| | |
| | | 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; |
| | | public Vector2 beginPos = Vector2.zero; |
| | | public Vector2 endPos = new Vector2(0, 150); |
| | | |
| | | protected List<DamageLine> damageLineList = new List<DamageLine>(); |
| | | protected List<DamageLine> damageLineList = new List<DamageLine>(); |
| | | private BattleDmgInfo battleDmgInfo; |
| | | private BattleFloatingUIController controller; |
| | | |
| | | public PositionTween posTween; |
| | | // 飘血优化:初始放大200%,透明度50%,7~8帧内缩放回100%,透明度回到100%,再往上飘14~16帧【30帧/秒】,暴击初始放大300%,缩回150% |
| | | // 战斗帧BattleConst.skillMotionFps 1秒=30帧 |
| | | |
| | | public ScaleTween scaleTween; |
| | | void Awake() |
| | | { |
| | | line.SetActive(false); |
| | | } |
| | | |
| | | private BattleDmgInfo battleDmgInfo; |
| | | private void InitController() |
| | | { |
| | | if (controller != null) return; |
| | | |
| | | void Awake() |
| | | { |
| | | line.SetActive(false); |
| | | } |
| | | RectTransform rectTransform = GetComponent<RectTransform>(); |
| | | controller = new BattleFloatingUIController(rectTransform, gameObject, ApplyColor); |
| | | |
| | | // 使用当前设置的 beginPos 和 endPos |
| | | controller.beginPos = beginPos; |
| | | controller.endPos = endPos; |
| | | // controller.scaleChangeTime = scaleChangeTime; |
| | | // controller.totalShowTime = totalShowTime; |
| | | // controller.normalBeginScale = normalBeginScale; |
| | | // controller.normalEndScale = normalEndScale; |
| | | // controller.critBeginScale = critBeginScale; |
| | | // controller.critEndScale = critEndScale; |
| | | // controller.beginColor = beginColor; |
| | | // controller.endColor = endColor; |
| | | } |
| | | |
| | | public async void SetDamage(BattleDmgInfo _damageInfo, Action _onComplete) |
| | | { |
| | | battleDmgInfo = _damageInfo; |
| | | public void SetRatio(float speed, float scale) |
| | | { |
| | | InitController(); |
| | | controller.SetRatio(speed, scale); |
| | | } |
| | | |
| | | var damages = battleDmgInfo.battleDamageList; |
| | | public async void SetDamage(BattleDmgInfo _damageInfo, Action _onComplete) |
| | | { |
| | | battleDmgInfo = _damageInfo; |
| | | |
| | | for (int i = damages.Count; i < damageLineList.Count; i++) |
| | | { |
| | | damageLineList[i].SetActive(false); |
| | | } |
| | | var damages = battleDmgInfo.battleDamageList; |
| | | |
| | | posTween.Play(_onComplete); |
| | | for (int i = damages.Count; i < damageLineList.Count; i++) |
| | | { |
| | | damageLineList[i].SetActive(false); |
| | | } |
| | | |
| | | if (battleDmgInfo.IsCrit()) |
| | | { |
| | | scaleTween.Play(); |
| | | } |
| | | // 使用控制器的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); |
| | | } |
| | | } |
| | | 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 Stop() |
| | | { |
| | | posTween.Stop(); |
| | | if (battleDmgInfo.IsCrit()) |
| | | { |
| | | scaleTween.Stop(); |
| | | } |
| | | } |
| | | public void Play(bool isCrit, Action onComplete = null) |
| | | { |
| | | InitController(); |
| | | // 每次Play前更新controller的位置设置 |
| | | controller.beginPos = beginPos; |
| | | controller.endPos = endPos; |
| | | controller.Play(isCrit, onComplete); |
| | | } |
| | | |
| | | public void Resume() |
| | | { |
| | | posTween.Resume(); |
| | | if (battleDmgInfo.IsCrit()) |
| | | { |
| | | scaleTween.Resume(); |
| | | } |
| | | } |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | } |