UI调整
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
using ChocDino.UIFX;
|
||||
using Cielonos.MainGame.Inventory;
|
||||
using DG.Tweening;
|
||||
using SLSUtilities.UI;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine.UI;
|
||||
@@ -8,31 +11,87 @@ namespace Cielonos.MainGame.UI
|
||||
{
|
||||
public class MainWeaponFunctionIcon : UIElementBase
|
||||
{
|
||||
public RuntimeFunctionUnit functionUnit;
|
||||
[FormerlySerializedAs("timerFillImage")] public Image frame;
|
||||
public Image frame;
|
||||
public Image iconImage;
|
||||
public Image timer;
|
||||
|
||||
public Image timerImage;
|
||||
public TMP_Text timerText;
|
||||
public TMP_Text costText;
|
||||
|
||||
private Sequence _frameOutlineSequence;
|
||||
private RuntimeFunctionUnit _functionUnit;
|
||||
public void Initialize(RuntimeFunctionUnit functionUnit)
|
||||
{
|
||||
this.functionUnit = functionUnit;
|
||||
this._functionUnit = functionUnit;
|
||||
iconImage.sprite = functionUnit.data.icon != null ? functionUnit.data.icon : null;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateUI()
|
||||
{
|
||||
float fillAmount;
|
||||
|
||||
if (functionUnit.maxCooldown <= 0f)
|
||||
if (_functionUnit.maxCooldown <= 0f)
|
||||
{
|
||||
fillAmount = 1f;
|
||||
//无冷却
|
||||
}
|
||||
else
|
||||
{
|
||||
fillAmount = 1f - functionUnit.currentCooldown / functionUnit.maxCooldown;
|
||||
float fillAmount = 1f - _functionUnit.currentCooldown / _functionUnit.maxCooldown;
|
||||
timerImage.fillAmount = fillAmount;
|
||||
|
||||
if (_functionUnit.currentCooldown > 0f)
|
||||
{
|
||||
timerText.text = _functionUnit.currentCooldown.ToString("F1");
|
||||
}
|
||||
else
|
||||
{
|
||||
timerText.text = "";
|
||||
}
|
||||
}
|
||||
|
||||
frame.fillAmount = fillAmount;
|
||||
|
||||
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 SetFrameOutline(float totalDuration, Color color = default, float intensity = 0.5f)
|
||||
{
|
||||
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.5f;
|
||||
_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.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user