using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using System;
|
using Cysharp.Threading.Tasks;
|
|
public class DamageContent : MonoBehaviour, IBattleFloatingUI
|
{
|
public GameObject line;
|
public RectTransform parent;
|
|
public Vector2 beginPos = Vector2.zero;
|
public Vector2 endPos = new Vector2(0, 150);
|
|
protected List<DamageLine> damageLineList = new List<DamageLine>();
|
private BattleDmgInfo battleDmgInfo;
|
private BattleFloatingUIController controller;
|
|
// 飘血优化:初始放大200%,透明度50%,7~8帧内缩放回100%,透明度回到100%,再往上飘14~16帧【30帧/秒】,暴击初始放大300%,缩回150%
|
// 战斗帧BattleConst.skillMotionFps 1秒=30帧
|
|
void Awake()
|
{
|
line.SetActive(false);
|
}
|
|
private void InitController()
|
{
|
if (controller != null) return;
|
|
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 void SetRatio(float speed, float scale)
|
{
|
InitController();
|
controller.SetRatio(speed, scale);
|
}
|
|
public async void SetDamage(BattleDmgInfo _damageInfo, Action _onComplete)
|
{
|
battleDmgInfo = _damageInfo;
|
|
var damages = battleDmgInfo.battleDamageList;
|
|
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();
|
// 每次Play前更新controller的位置设置
|
controller.beginPos = beginPos;
|
controller.endPos = endPos;
|
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);
|
}
|
}
|
}
|
}
|