2025-05-18 01:04:31 +08:00

119 lines
2.3 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-03-10
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "BBuffWidget" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.EventSystems;
namespace G.UI
{
/// <summary>
///
/// </summary>
public class BBuffWidget : KUIWidget,IPointerDownHandler,IPointerUpHandler
{
#region Field
TextMeshProUGUI _tmpNumber;
private int _number;
private int _index;
private Coroutine _cc;
private float _time;
private bool _isGo;
private int[] _date = new int[2];
#endregion
#region Method
public void SetNumber(int number)
{
_number = number;
_tmpNumber.text = $"+{_number}%";
}
public void AddNumber(int number)
{
_number += number;
_tmpNumber.text = $"+{_number}%";
}
public void SetType(string type)
{
_index = 0;
if (type == "yellow")
{
_index = 1;
}
else if (type == "blue")
{
_index = 2;
}
GetComponent<KUIImage>().ShowSprite(_index);
}
IEnumerator GoOpen()
{
while (true)
{
_time += Time.deltaTime;
if (_time > 0.5 && _isGo)
{
_date[0] = _index;
_date[1] = _number;
GlobalNotifier.PostNotification(GlobalDefine.EVENT_OPEN_BUFF,_date);
_isGo = false;
}
yield return null;
}
}
public void OpenBuff()
{
_date[0] = _index;
_date[1] = _number;
GlobalNotifier.PostNotification(GlobalDefine.EVENT_OPEN_BUFF, _date);
}
#endregion
#region Unity
/// <summary>
///
/// </summary>
private void Awake()
{
_tmpNumber = GetComponentInChildren<TextMeshProUGUI>();
}
public void OnPointerDown(PointerEventData eventData)
{
//_time = 0;
//_isGo = true;
//_cc = StartCoroutine(GoOpen());
Invoke("OpenBuff", 0.5f);
}
public void OnPointerUp(PointerEventData eventData)
{
//CancelInvoke();
//StopCoroutine(_cc);
//GlobalNotifier.PostNotification(GlobalDefine.EVENT_CLOSE_BUFF);
}
#endregion
}
}