From 09bc892c7283df8757a07b646d5af21ddaa263d1 Mon Sep 17 00:00:00 2001
From: lcy <1459594991@qq.com>
Date: 星期四, 06 十一月 2025 18:22:34 +0800
Subject: [PATCH] 164 天子的考验-客户端
---
Main/System/Battle/UIComp/DamageContent.cs | 142 +++++++++++++++++++++++++++++++++++-----------
1 files changed, 107 insertions(+), 35 deletions(-)
diff --git a/Main/System/Battle/UIComp/DamageContent.cs b/Main/System/Battle/UIComp/DamageContent.cs
index 9963eb0..80be128 100644
--- a/Main/System/Battle/UIComp/DamageContent.cs
+++ b/Main/System/Battle/UIComp/DamageContent.cs
@@ -2,50 +2,122 @@
using System.Collections.Generic;
using UnityEngine;
using System;
+using Cysharp.Threading.Tasks;
-public class DamageContent : MonoBehaviour
+public class DamageContent : MonoBehaviour, IBattleFloatingUI
{
- public GameObject line;
+ public GameObject line;
+ public RectTransform parent;
- public RectTransform parent;
+ [Header("Floating Config")]
+ [Tooltip("璇峰湪Inspector涓嫋鎷紽loatingConfig璧勬簮")]
+ public FloatingConfig floatingConfig;
- protected List<DamageLine> damageLineList = new List<DamageLine>();
+ protected List<DamageLine> damageLineList = new List<DamageLine>();
+ private BattleDmgInfo battleDmgInfo;
+ private BattleFloatingUIController controller;
- public PositionTween posTween;
+ void Awake()
+ {
+ line.SetActive(false);
+ }
- void Awake()
- {
- line.SetActive(false);
- }
+ private void InitController()
+ {
+ if (controller != null) return;
- public void SetDamage(List<long> damages, Action _onComplete)
- {
- for (int i = 0; i < damages.Count; i++)
- {
- if (i >= damageLineList.Count)
- {
- GameObject newLine = GameObject.Instantiate(line, parent);
- damageLineList.Add(newLine.GetComponent<DamageLine>());
- }
- damageLineList[i].SetActive(true);
- damageLineList[i].SetDamage(damages[i]);
- }
+ if (floatingConfig == null)
+ {
+ Debug.LogError($"[DamageContent] FloatingConfig 鏈厤缃紝璇峰湪Inspector涓嫋鎷借祴鍊�! GameObject: {gameObject.name}");
+ return;
+ }
- for (int i = damages.Count; i < damageLineList.Count; i++)
- {
- damageLineList[i].SetActive(false);
- }
+ RectTransform rectTransform = GetComponent<RectTransform>();
+ controller = new BattleFloatingUIController(rectTransform, gameObject, ApplyColor, floatingConfig);
+ }
- posTween.Play(_onComplete);
- }
+ public void SetRatio(float speed, float scale)
+ {
+ InitController();
+ controller?.SetRatio(speed, scale);
+ }
- public void Stop()
- {
- posTween.Stop();
- }
+ /// <summary>
+ /// 璁剧疆椋樺瓧鐨勮捣鐐瑰拰缁堢偣浣嶇疆锛堣繍琛屾椂鍔ㄦ�佽缃級
+ /// </summary>
+ public void SetPosition(Vector2 beginPos, Vector2 endPos)
+ {
+ InitController();
+ controller?.SetRuntimePosition(beginPos, endPos);
+ }
- public void Resume()
- {
- posTween.Resume();
- }
+ public async void SetDamage(BattleDmgInfo _battleDmgInfo, List<BattleDmg> damages, Action _onComplete)
+ {
+ battleDmgInfo = _battleDmgInfo;
+ for (int i = damages.Count; i < damageLineList.Count; i++)
+ {
+ damageLineList[i].SetActive(false);
+ }
+
+ // 浣跨敤鎺у埗鍣ㄧ殑Play鏂规硶
+ bool isCrit = battleDmgInfo.IsCrit();
+ Play(isCrit, _onComplete);
+
+ for (int i = 0; i < damages.Count; i++)
+ {
+ if (i >= damageLineList.Count)
+ {
+ GameObject newLine = GameObject.Instantiate(line, parent);
+ damageLineList.Add(newLine.GetComponent<DamageLine>());
+ }
+ damageLineList[i].SetActive(true);
+ damageLineList[i].SetDamage(damages[i]);
+ await UniTask.Delay(100);
+ }
+ }
+
+ public void Play(bool isCrit, Action onComplete = null)
+ {
+ InitController();
+ controller?.Play(isCrit, onComplete);
+ }
+
+ public void Run()
+ {
+ if (controller == null) return;
+ 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)
+ {
+ for (int i = 0; i < damageLineList.Count; i++)
+ {
+ if (damageLineList[i].gameObject.activeSelf)
+ {
+ damageLineList[i].SetColor(color);
+ }
+ }
+ }
+
+ // 杩愯鏃舵洿鏂伴厤缃�
+ public void SetFloatingConfig(FloatingConfig config)
+ {
+ floatingConfig = config;
+ if (controller != null)
+ {
+ controller.SetConfig(config);
+ }
+ }
}
--
Gitblit v1.8.0