53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
using DG.Tweening;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class PveLossButton : MButton
|
|
{
|
|
[Header("Анимация")]
|
|
[SerializeField] private float switchDuration;
|
|
[SerializeField] private float enabledScale = 1.1f, disabledScale = 0.9f;
|
|
[SerializeField] private Ease ease = Ease.Linear;
|
|
[SerializeField] private Image background;
|
|
[SerializeField] private List<TextMeshProUGUI> texts;
|
|
|
|
private Sequence animSequence;
|
|
protected bool interactable;
|
|
|
|
public override void Select() => SetSelected(true);
|
|
|
|
public override void Deselect() => SetSelected(false);
|
|
|
|
private void SetSelected(bool selected)
|
|
{
|
|
interactable = false;
|
|
if (animSequence != null)
|
|
animSequence.Kill();
|
|
|
|
Color bgColor = selected ? Color.white : Color.black;
|
|
Color textColor = selected ? Color.black : Color.white;
|
|
float scale = selected ? enabledScale : disabledScale;
|
|
|
|
animSequence = DOTween.Sequence();
|
|
animSequence.Join(background.DOColor(bgColor, switchDuration).SetEase(ease));
|
|
animSequence.Join(transform.DOScale(scale, switchDuration).SetEase(ease));
|
|
|
|
foreach (var text in texts)
|
|
animSequence.Join(text.DOColor(textColor, switchDuration).SetEase(ease));
|
|
|
|
animSequence.onComplete += () => interactable = selected;
|
|
animSequence.PlayForward();
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
}
|
|
|
|
//public override void Interact()
|
|
//{
|
|
|
|
//}
|
|
}
|