From 4e41975b0c62fa10ab571b0c9ad0690754762b6a Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期四, 30 十月 2025 16:45:07 +0800
Subject: [PATCH] 125 战斗 飘字更新
---
Main/System/Battle/UIComp/BattleTips.cs | 152 ++++++++++++++++++++++++++++++--------------------
1 files changed, 91 insertions(+), 61 deletions(-)
diff --git a/Main/System/Battle/UIComp/BattleTips.cs b/Main/System/Battle/UIComp/BattleTips.cs
index dfaff7c..bda5b8b 100644
--- a/Main/System/Battle/UIComp/BattleTips.cs
+++ b/Main/System/Battle/UIComp/BattleTips.cs
@@ -2,106 +2,136 @@
using System;
using UnityEngine.UI;
-public class BattleTips : MonoBehaviour
+public class BattleTips : MonoBehaviour, IBattleFloatingUI
{
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;
+ public Image background;
- private float speedRatio = 1f;
+ public Vector3 normalBeginScale = new Vector3(2f, 2f, 2f);
+ public Vector3 normalEndScale = new Vector3(1f, 1f, 1f);
- public void SetSpeedRatio(float ratio)
+ public Action OnFinish; // 淇濈暀 OnFinish
+
+ [SerializeField]
+ private BattleFloatingUIController controller;
+
+ void Awake()
{
- speedRatio = ratio;
+ InitController();
}
- public void SetText(string text, bool useArtText = false)
+ private void InitController()
{
- // 鍒濆鏀惧ぇ200% 閫忔槑搴�50% 7~8甯у唴缂╁洖100% 閫忔槑搴﹀埌100% 鍐嶅線涓婇14~16甯� 鐒跺悗娑堝け 锛�30甯�/绉�)
+ if (controller != null) return;
- // 8+16/30=0.8绉�
-
+ controller = new BattleFloatingUIController(rectTransform, gameObject, ApplyColor);
+ controller.beginPos = beginPos;
+ controller.endPos = endPos;
+ controller.normalBeginScale = normalBeginScale;
+ controller.normalEndScale = normalEndScale;
+ }
- rectTransform.anchoredPosition = beginPos;
- rectTransform.localScale = beginScale;
+ public void SetRatio(float speed, float scale)
+ {
+ InitController(); // 纭繚 controller 宸插垵濮嬪寲
+ controller.SetRatio(speed, scale);
+ }
- timer = 0f;
- gameObject.SetActive(true);
+ 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;
- 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);
}
+
+ 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);
}
-
- // 涓嶈浣跨敤update
- public void Run()
+ public void Play(bool isCrit, Action onComplete = null)
{
- if (!gameObject.activeSelf)
- return;
-
- if (timer >= totalShowTime)
+ InitController(); // 纭繚 controller 宸插垵濮嬪寲
+
+ // 鍚堝苟 OnFinish 鍜� onComplete
+ Action combinedCallback = () =>
{
- gameObject.SetActive(false);
OnFinish?.Invoke();
OnFinish = null;
- return;
- }
+ onComplete?.Invoke();
+ };
+
+ controller.Play(isCrit, combinedCallback);
+ }
- // 鏁翠釜杩囩▼閮藉線涓婇
- float moveProgress = timer / totalShowTime;
- rectTransform.anchoredPosition = Vector2.Lerp(beginPos, endPos, moveProgress);
+ public void Run()
+ {
+ if (controller == null) return; // 闃叉鍦� Awake 鍓嶈皟鐢�
+ controller.Run();
+ }
- // 闃舵1: 7~8甯у唴缂╂斁浠巄eginScale鍒癳ndScale锛岄�忔槑搴︿粠50%鍒�100%
- if (timer < scaleChangeTime)
- {
- float scaleProgress = timer / scaleChangeTime;
- rectTransform.localScale = Vector3.Lerp(beginScale, endScale, scaleProgress);
+ public void Stop()
+ {
+ if (controller == null) return;
+ controller.Stop();
+ }
- 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;
- }
+ public void Resume()
+ {
+ if (controller == null) return;
+ controller.Resume();
+ }
- timer += 1f / (float)BattleConst.skillMotionFps * speedRatio;
+ 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;
}
}
\ No newline at end of file
--
Gitblit v1.8.0