using UnityEngine;
|
using System;
|
using UnityEngine.UI;
|
|
public class BattleTips : MonoBehaviour, IBattleFloatingUI
|
{
|
public Vector2 beginPos = Vector2.zero;
|
public Vector2 endPos = new Vector2(0, 150);
|
|
public RectTransform rectTransform;
|
public Text tipText;
|
public Text artText;
|
|
public Image background;
|
|
public Vector3 normalBeginScale = new Vector3(2f, 2f, 2f);
|
public Vector3 normalEndScale = new Vector3(1f, 1f, 1f);
|
|
public Action OnFinish; // 保留 OnFinish
|
|
[SerializeField]
|
private BattleFloatingUIController controller;
|
|
void Awake()
|
{
|
InitController();
|
}
|
|
private void InitController()
|
{
|
if (controller != null) return;
|
|
controller = new BattleFloatingUIController(rectTransform, gameObject, ApplyColor);
|
controller.beginPos = beginPos;
|
controller.endPos = endPos;
|
controller.normalBeginScale = normalBeginScale;
|
controller.normalEndScale = normalEndScale;
|
}
|
|
public void SetRatio(float speed, float scale)
|
{
|
InitController(); // 确保 controller 已初始化
|
controller.SetRatio(speed, scale);
|
}
|
|
public void SetText(string text, bool useArtText = false, bool isCrit = false, Color textColor = default)
|
{
|
if (textColor == default)
|
{
|
textColor = Color.white;
|
}
|
|
InitController();
|
if (useArtText)
|
{
|
artText.text = text;
|
tipText.gameObject.SetActive(false);
|
artText.gameObject.SetActive(true);
|
}
|
else
|
{
|
tipText.text = text;
|
artText.gameObject.SetActive(false);
|
tipText.gameObject.SetActive(true);
|
}
|
|
controller.beginColor = new Color(textColor.r, textColor.g, textColor.b, controller.beginColor.a);
|
controller.endColor = new Color(textColor.r, textColor.g, textColor.b, controller.endColor.a);
|
ApplyColor(controller.beginColor);
|
Play(isCrit);
|
}
|
|
public void Play(bool isCrit, Action onComplete = null)
|
{
|
InitController(); // 确保 controller 已初始化
|
|
// 合并 OnFinish 和 onComplete
|
Action combinedCallback = () =>
|
{
|
OnFinish?.Invoke();
|
OnFinish = null;
|
onComplete?.Invoke();
|
};
|
|
controller.Play(isCrit, combinedCallback);
|
}
|
|
public void Run()
|
{
|
if (controller == null) return; // 防止在 Awake 前调用
|
controller.Run();
|
}
|
|
public void Stop()
|
{
|
if (controller == null) return;
|
controller.Stop();
|
}
|
|
public void Resume()
|
{
|
if (controller == null) return;
|
controller.Resume();
|
}
|
|
private void ApplyColor(Color color)
|
{
|
if (tipText.gameObject.activeSelf)
|
tipText.color = color;
|
if (artText.gameObject.activeSelf)
|
artText.color = color;
|
}
|
|
public void ShowBackground(bool showBackground)
|
{
|
// Implement the logic to show or hide the background
|
background.enabled = showBackground;
|
}
|
|
public void UpdatePositions(Vector2 begin, Vector2 end)
|
{
|
InitController();
|
beginPos = begin;
|
endPos = end;
|
controller.beginPos = begin;
|
controller.endPos = end;
|
}
|
|
public void UpdateScales(Vector3 beginScale, Vector3 endScale)
|
{
|
InitController();
|
normalBeginScale = beginScale;
|
normalEndScale = endScale;
|
controller.normalBeginScale = beginScale;
|
controller.normalEndScale = endScale;
|
}
|
}
|