113 lines
3.3 KiB
C#
113 lines
3.3 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using DG.Tweening;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class GamemodePanel : MenuPanel
|
|
{
|
|
[Header("Анимация рамки")]
|
|
[SerializeField] List<RectTransform> frames;
|
|
[SerializeField] Vector2 disabledFrameWH;
|
|
[SerializeField] Vector2 enabledFrameWH;
|
|
[SerializeField] float frameDuration = 0.15f;
|
|
|
|
[Header("Анимация персонажа")]
|
|
[SerializeField] Image characterImage;
|
|
[SerializeField] RectTransform characterRect;
|
|
[SerializeField] Vector2 disabledCharacterWH;
|
|
[SerializeField] Vector2 enabledCharacterWH;
|
|
[SerializeField] Color disabledCharacterColor;
|
|
[SerializeField] Color enabledCharacterColor;
|
|
[SerializeField] float characterDelay = 0.1f;
|
|
[SerializeField] float characterDuration = 0.1f;
|
|
|
|
[Header("Надпись режима")]
|
|
[SerializeField] RectTransform modeSign;
|
|
[SerializeField] Vector2 signOffset = new(-200, 0);
|
|
|
|
[Header("Взаимодействие")]
|
|
[SerializeField] private GameMode gameMode;
|
|
|
|
private Vector2 signStart;
|
|
private CancellationTokenSource cts;
|
|
|
|
private float totalTime => frameDuration + characterDelay + characterDuration;
|
|
|
|
public override void Initialize()
|
|
{
|
|
signStart = modeSign.anchoredPosition;
|
|
}
|
|
|
|
public override void Enable(int _, float delay)
|
|
{
|
|
StopAnimation();
|
|
cts = new();
|
|
|
|
foreach (var frame in frames)
|
|
{
|
|
frame
|
|
.DOSizeDelta(enabledFrameWH, frameDuration)
|
|
.SetEase(Ease.OutQuad)
|
|
.WithCancellation(cts.Token);
|
|
}
|
|
|
|
characterRect
|
|
.DOSizeDelta(enabledCharacterWH,characterDuration)
|
|
.SetDelay(characterDelay)
|
|
.SetEase(Ease.OutQuad)
|
|
.WithCancellation(cts.Token);
|
|
|
|
characterImage.DOColor(enabledCharacterColor, characterDuration)
|
|
.SetDelay(characterDelay)
|
|
.SetEase(Ease.OutQuad)
|
|
.WithCancellation(cts.Token);
|
|
|
|
Sequence sequence = DOTween.Sequence();
|
|
|
|
sequence.Append(
|
|
modeSign.DOAnchorPos(signStart - signOffset, totalTime * 0.15f)
|
|
.SetEase(Ease.Linear)
|
|
);
|
|
sequence.Append(
|
|
modeSign.DOAnchorPos(signStart, totalTime * 0.85f)
|
|
.SetEase(Ease.OutBounce)
|
|
);
|
|
sequence.WithCancellation(cts.Token);
|
|
sequence.Play();
|
|
|
|
|
|
}
|
|
|
|
public override void Disable(int _)
|
|
{
|
|
StopAnimation();
|
|
cts = new();
|
|
|
|
foreach (var frame in frames)
|
|
{
|
|
frame.DOSizeDelta(disabledFrameWH, frameDuration).SetEase(Ease.InCirc).WithCancellation(cts.Token);
|
|
}
|
|
|
|
characterRect
|
|
.DOSizeDelta(disabledCharacterWH, characterDuration)
|
|
//.SetDelay(characterDelay)
|
|
.SetEase(Ease.OutQuad)
|
|
.WithCancellation(cts.Token);
|
|
|
|
characterImage.DOColor(disabledCharacterColor, characterDuration)
|
|
.SetDelay(characterDelay)
|
|
.SetEase(Ease.OutQuad)
|
|
.WithCancellation(cts.Token);
|
|
}
|
|
|
|
public override void Interact() => GameManager.Instance.TryEnterGame(gameMode);
|
|
|
|
private void StopAnimation()
|
|
{
|
|
cts?.Cancel();
|
|
cts?.Dispose();
|
|
}
|
|
|
|
} |