144 lines
3.3 KiB
C#
144 lines
3.3 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Unity
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2020-06-06
|
|||
|
// Description :
|
|||
|
// Last Modified By : Kimch
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "DamageBoard" company="Kunpo"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
namespace G
|
|||
|
{
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using DG.Tweening;
|
|||
|
using TMPro;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
/// </summary>
|
|||
|
public enum DamageBoardType
|
|||
|
{
|
|||
|
TYPE_INVALID = -1,
|
|||
|
PLAYER_HP_ADD = 0, //我方HP增加
|
|||
|
PLAYER_HP_SUB, //我方HP减少
|
|||
|
PLAYER_ATTACK_CRITICAL,//我方攻击时 出暴击伤害
|
|||
|
ENEMY_HP_SUB,
|
|||
|
TYPE_COPY_PORP,//获取到道具(副本玩法使用)
|
|||
|
}
|
|||
|
|
|||
|
public class DamageBoard : KUIWidget
|
|||
|
{
|
|||
|
#if UNITY_EDITOR
|
|||
|
[Tooltip("移动位移")]
|
|||
|
#endif
|
|||
|
public Vector2 moveOffset = new Vector2(10f, 200f);
|
|||
|
#if UNITY_EDITOR
|
|||
|
[Tooltip("移动时间")]
|
|||
|
#endif
|
|||
|
public float moveDuration = 1f;
|
|||
|
|
|||
|
private TextMeshProUGUI _valueText;
|
|||
|
private TextMeshProUGUI _signText;
|
|||
|
private TextMeshProUGUI _kindText;
|
|||
|
|
|||
|
private RectTransform _selfRect;
|
|||
|
private CanvasGroup _selfGroup;
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
_valueText = this.Find<TextMeshProUGUI>("Value");
|
|||
|
_signText = this.Find<TextMeshProUGUI>("Sign");
|
|||
|
_kindText = this.Find<TextMeshProUGUI>("Kind");
|
|||
|
|
|||
|
_selfRect = this.GetComponent<RectTransform>();
|
|||
|
}
|
|||
|
|
|||
|
public void Reset()
|
|||
|
{
|
|||
|
if (_selfRect == null)
|
|||
|
{
|
|||
|
_valueText = this.Find<TextMeshProUGUI>("Value");
|
|||
|
_signText = this.Find<TextMeshProUGUI>("Sign");
|
|||
|
_kindText = this.Find<TextMeshProUGUI>("Kind");
|
|||
|
|
|||
|
_selfRect = this.GetComponent<RectTransform>();
|
|||
|
}
|
|||
|
|
|||
|
_valueText.text = string.Empty;
|
|||
|
_kindText.text = string.Empty;
|
|||
|
_signText.text = string.Empty;
|
|||
|
|
|||
|
this.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
public void SetValue(int value, DamageBoardType type = DamageBoardType.TYPE_INVALID)
|
|||
|
{
|
|||
|
switch (type)
|
|||
|
{
|
|||
|
case DamageBoardType.TYPE_COPY_PORP:
|
|||
|
SetPropValueText($"+{value}");
|
|||
|
break;
|
|||
|
default:
|
|||
|
SetValueText(value.ToString());
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private Color GetColor(byte r, byte g, byte b, byte a)
|
|||
|
{
|
|||
|
return new Color32(r, g, b, a);
|
|||
|
}
|
|||
|
|
|||
|
private void SetValueText(string value)
|
|||
|
{
|
|||
|
if (_valueText)
|
|||
|
{
|
|||
|
_valueText.text = value;
|
|||
|
}
|
|||
|
}
|
|||
|
private void SetPropValueText(string value)
|
|||
|
{
|
|||
|
if (_valueText)
|
|||
|
{
|
|||
|
_valueText.text = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void SetTextContent(string kind, string sign, string value, VertexGradient gradient)
|
|||
|
{
|
|||
|
if (_kindText)
|
|||
|
{
|
|||
|
_kindText.text = kind;
|
|||
|
_kindText.colorGradient = gradient;
|
|||
|
}
|
|||
|
if (_signText)
|
|||
|
{
|
|||
|
_signText.text = sign;
|
|||
|
_signText.colorGradient = gradient;
|
|||
|
}
|
|||
|
if (_valueText)
|
|||
|
{
|
|||
|
_valueText.text = value;
|
|||
|
_valueText.colorGradient = gradient;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void SetPosition(Vector3 position)
|
|||
|
{
|
|||
|
var screenPosition = RectTransformUtility.WorldToScreenPoint(Camera.main, position);
|
|||
|
var pos = BoardManager.ScreenPointToLocalPointInRectangle(screenPosition);
|
|||
|
_selfRect.anchoredPosition = pos;
|
|||
|
|
|||
|
this.gameObject.SetActive(true);
|
|||
|
|
|||
|
_selfRect.DOLocalMove(pos + moveOffset, moveDuration)
|
|||
|
.OnComplete(() =>
|
|||
|
{
|
|||
|
BoardManager.Instance.ReturnBoard(this);
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
}
|