using UnityEngine;
|
using System;
|
using UnityEngine.UI;
|
|
public class BattleTips : MonoBehaviour
|
{
|
public Vector2 beginPos = Vector2.zero;
|
public Vector2 endPos = new Vector2(0, 150);
|
|
public float scaleChangeTime = 0.2667f; // 7~8帧 (8/30=0.2667秒)
|
public float totalShowTime = 0.8f; // 总时间约24帧 (8+16=24帧)
|
public float timer = 0f;
|
|
public Vector3 beginScale = new Vector3(4f, 4f, 4f);
|
public Vector3 endScale = new Vector3(2f, 2f, 2f);
|
public Color beginColor = new Color(1f, 1f, 1f, 0.5f);
|
public Color endColor = new Color(1f, 1f, 1f, 1f);
|
|
public RectTransform rectTransform;
|
|
public Text tipText;
|
|
public Text artText;
|
|
public Action OnFinish;
|
|
private float speedRatio = 1f;
|
|
public void SetSpeedRatio(float ratio)
|
{
|
speedRatio = ratio;
|
}
|
|
public void SetText(string text, bool useArtText = false)
|
{
|
// 初始放大200% 透明度50% 7~8帧内缩回100% 透明度到100% 再往上飘14~16帧 然后消失 (30帧/秒)
|
|
// 8+16/30=0.8秒
|
|
|
rectTransform.anchoredPosition = beginPos;
|
rectTransform.localScale = beginScale;
|
|
timer = 0f;
|
gameObject.SetActive(true);
|
|
if (useArtText)
|
{
|
artText.text = text;
|
artText.color = beginColor;
|
tipText.gameObject.SetActive(false);
|
artText.gameObject.SetActive(true);
|
}
|
else
|
{
|
tipText.text = text;
|
tipText.color = beginColor;
|
artText.gameObject.SetActive(false);
|
tipText.gameObject.SetActive(true);
|
}
|
}
|
|
|
// 不要使用update
|
public void Run()
|
{
|
if (!gameObject.activeSelf)
|
return;
|
|
if (timer >= totalShowTime)
|
{
|
gameObject.SetActive(false);
|
OnFinish?.Invoke();
|
OnFinish = null;
|
return;
|
}
|
|
// 整个过程都往上飘
|
float moveProgress = timer / totalShowTime;
|
rectTransform.anchoredPosition = Vector2.Lerp(beginPos, endPos, moveProgress);
|
|
// 阶段1: 7~8帧内缩放从beginScale到endScale,透明度从50%到100%
|
if (timer < scaleChangeTime)
|
{
|
float scaleProgress = timer / scaleChangeTime;
|
rectTransform.localScale = Vector3.Lerp(beginScale, endScale, scaleProgress);
|
|
Color currentColor = Color.Lerp(beginColor, endColor, scaleProgress);
|
if (tipText.gameObject.activeSelf)
|
tipText.color = currentColor;
|
if (artText.gameObject.activeSelf)
|
artText.color = currentColor;
|
}
|
// 阶段2: 缩放完成后,保持endScale和100%透明度,继续往上飘
|
else
|
{
|
rectTransform.localScale = endScale;
|
|
if (tipText.gameObject.activeSelf)
|
tipText.color = endColor;
|
if (artText.gameObject.activeSelf)
|
artText.color = endColor;
|
}
|
|
timer += 1f / (float)BattleConst.skillMotionFps * speedRatio;
|
}
|
}
|