97 lines
3.4 KiB
C#
97 lines
3.4 KiB
C#
using System.Linq;
|
|
using ChocDino.UIFX;
|
|
using Cielonos.MainGame.Inventory;
|
|
using DG.Tweening;
|
|
using SLSUtilities.UI;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Cielonos.MainGame.UI
|
|
{
|
|
public class SupportEquipmentIcon : UIElementBase
|
|
{
|
|
public SupportEquipmentBase supportEquipment;
|
|
public RuntimeFunctionUnit functionUnit;
|
|
public Image frame;
|
|
public Image iconImage;
|
|
public Image timer;
|
|
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)
|
|
{
|
|
|
|
}
|
|
else if (functionCount == 1)
|
|
{
|
|
functionUnit = supportEquipment.functionSm.functionUnits.Values.ToList()[0];
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void UpdateUI()
|
|
{
|
|
if (functionUnit == null) return;
|
|
|
|
float fillAmount;
|
|
|
|
if (functionUnit.maxCooldown <= 0f)
|
|
{
|
|
fillAmount = 0f;
|
|
}
|
|
else
|
|
{
|
|
fillAmount = functionUnit.currentCooldown / functionUnit.maxCooldown;
|
|
}
|
|
|
|
timer.fillAmount = fillAmount;
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
} |