152 lines
5.8 KiB
C#
152 lines
5.8 KiB
C#
using System.Linq;
|
|
using ChocDino.UIFX;
|
|
using Cielonos.MainGame.Inventory;
|
|
using DG.Tweening;
|
|
using SLSUtilities.UI;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Cielonos.MainGame.UI
|
|
{
|
|
public class SupportEquipmentIcon : UIElementBase
|
|
{
|
|
public SupportEquipmentBase supportEquipment;
|
|
public Image frame;
|
|
public Image iconImage;
|
|
public Image timerImage;
|
|
public TMP_Text timerText;
|
|
public TMP_Text costText;
|
|
|
|
private RuntimeFunctionUnit _functionUnit;
|
|
private Sequence _frameOutlineSequence;
|
|
|
|
public void Initialize(SupportEquipmentBase supportEquipment)
|
|
{
|
|
if (supportEquipment == null)
|
|
{
|
|
iconImage.sprite = null;
|
|
_functionUnit = null;
|
|
}
|
|
else
|
|
{
|
|
this.supportEquipment = supportEquipment;
|
|
iconImage.sprite = supportEquipment.contentData.squareIcon;
|
|
|
|
if (supportEquipment.functionSm != null)
|
|
{
|
|
int functionCount = supportEquipment.functionSm.functionUnits.Count;
|
|
|
|
if (functionCount == 0)
|
|
{
|
|
DisableAllParts();
|
|
}
|
|
else if (functionCount == 1)
|
|
{
|
|
_functionUnit = supportEquipment.functionSm.mainFunction;
|
|
}
|
|
else
|
|
{
|
|
//如果有多个功能单元,优先显示主功能单元
|
|
_functionUnit = supportEquipment.functionSm.mainFunction;
|
|
}
|
|
|
|
timerImage.gameObject.SetActive(true);
|
|
timerText.gameObject.SetActive(true);
|
|
costText.gameObject.SetActive(true);
|
|
iconImage.color = Color.white;
|
|
|
|
if (_functionUnit.maxCooldown <= 0)
|
|
{
|
|
timerImage.gameObject.SetActive(false);
|
|
timerText.gameObject.SetActive(false);
|
|
}
|
|
|
|
if(_functionUnit.data.energyCost <= 0)
|
|
{
|
|
costText.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
costText.text = Mathf.CeilToInt(_functionUnit.data.energyCost).ToString("D");
|
|
}
|
|
|
|
if (_functionUnit.data.tags.Contains("Disruption"))
|
|
{
|
|
Color newColor = Color.yellow;
|
|
iconImage.color = newColor;
|
|
newColor.a = 0.5f;
|
|
frame.color = newColor;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
DisableAllParts();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void DisableAllParts()
|
|
{
|
|
iconImage.sprite = null;
|
|
iconImage.color = Color.clear;
|
|
timerImage.gameObject.SetActive(false);
|
|
timerText.gameObject.SetActive(false);
|
|
costText.gameObject.SetActive(false);
|
|
}
|
|
|
|
public override void UpdateUI()
|
|
{
|
|
if (_functionUnit == null) return;
|
|
|
|
if (_functionUnit.maxCooldown <= 0f)
|
|
{
|
|
//无冷却
|
|
}
|
|
else
|
|
{
|
|
float fillAmount = 1f - _functionUnit.currentCooldown / _functionUnit.maxCooldown;
|
|
timerImage.fillAmount = fillAmount;
|
|
|
|
if (_functionUnit.currentCooldown > 0f)
|
|
{
|
|
timerText.text = _functionUnit.currentCooldown.ToString("F1");
|
|
}
|
|
else
|
|
{
|
|
timerText.text = "";
|
|
}
|
|
}
|
|
|
|
if (_functionUnit.data.energyCost > 0)
|
|
{
|
|
float playerCurrentEnergy = MainGameManager.Player.attributeSm[CharacterAttribute.Energy];
|
|
costText.color = playerCurrentEnergy >= _functionUnit.data.energyCost ? Color.cyan : Color.orangeRed;
|
|
costText.text = Mathf.CeilToInt(_functionUnit.data.energyCost).ToString("D");
|
|
}
|
|
}
|
|
|
|
public void UseOutlineAnimation() => SetFrameOutline(0.4f, Color.white);
|
|
public void CanNotUseOutlineAnimation() => SetFrameOutline(0.4f, Color.red);
|
|
public void NoTargetOutlineAnimation() => SetFrameOutline(0.4f, Color.orange);
|
|
|
|
public void SetFrameOutline(float totalDuration, Color color = default, float intensity = 2f)
|
|
{
|
|
GetComponent<Canvas>().sortingOrder = 10;
|
|
color = color == default ? Color.white : color;
|
|
Color hdrColor = color * Mathf.Pow(2f, intensity);
|
|
GlowFilter glowFilter = frame.GetComponent<GlowFilter>();
|
|
glowFilter.Color = hdrColor;
|
|
float fadeDuration = Mathf.Clamp(totalDuration / 2f, 0.2f, totalDuration);
|
|
float stayDuration = totalDuration - fadeDuration;
|
|
float strengthPeak = 0.25f;
|
|
_frameOutlineSequence?.Kill(true);
|
|
_frameOutlineSequence = DOTween.Sequence();
|
|
_frameOutlineSequence.Append(DOTween.To(() => glowFilter.Strength, x => glowFilter.Strength = x, strengthPeak, fadeDuration).SetEase(Ease.OutQuad));
|
|
_frameOutlineSequence.AppendInterval(stayDuration);
|
|
_frameOutlineSequence.Append(DOTween.To(() => glowFilter.Strength, x => glowFilter.Strength = x, 0f, fadeDuration).SetEase(Ease.InQuad));
|
|
_frameOutlineSequence.OnComplete(() => GetComponent<Canvas>().sortingOrder = 0);
|
|
_frameOutlineSequence.Play();
|
|
}
|
|
}
|
|
} |