Add utils + refacto
This commit is contained in:
@@ -4,6 +4,7 @@ using TMPro;
|
||||
using Unheimlich.Data.Dialogues;
|
||||
using Unheimlich.Gameplay.Player;
|
||||
using Unheimlich.Interactions.FloatingWords;
|
||||
using Unheimlich.Utility;
|
||||
|
||||
namespace Unheimlich.UI
|
||||
{
|
||||
@@ -43,6 +44,10 @@ namespace Unheimlich.UI
|
||||
|
||||
private DialogueDisplayMode _currentDisplayMode = DialogueDisplayMode.World;
|
||||
|
||||
private int _fadeCanvasTweenId = -1;
|
||||
private int _rotationTweenId = -1;
|
||||
private List<int> _floatingTweenIds = new List<int>();
|
||||
|
||||
private static readonly Vector3 ViewportCenter = new Vector3(0.5f, 0.5f, 0f);
|
||||
|
||||
private void Awake()
|
||||
@@ -91,7 +96,7 @@ namespace Unheimlich.UI
|
||||
|
||||
if (_dialogueCanvasGroup != null)
|
||||
{
|
||||
LeanTween.cancel(_dialoguePanel);
|
||||
TweenHelper.CancelTween(ref _fadeCanvasTweenId);
|
||||
_dialogueCanvasGroup.alpha = 1f;
|
||||
}
|
||||
}
|
||||
@@ -125,9 +130,12 @@ namespace Unheimlich.UI
|
||||
{
|
||||
if (_dialogueCanvasGroup != null && _dialoguePanel != null)
|
||||
{
|
||||
LeanTween.cancel(_dialoguePanel);
|
||||
LeanTween.alphaCanvas(_dialogueCanvasGroup, 0f, _fadeOutDuration)
|
||||
.setOnComplete(() =>
|
||||
TweenHelper.CancelTween(ref _fadeCanvasTweenId);
|
||||
_fadeCanvasTweenId = TweenHelper.FadeCanvasGroup(
|
||||
_dialogueCanvasGroup,
|
||||
0f,
|
||||
_fadeOutDuration,
|
||||
() =>
|
||||
{
|
||||
HideDialogueBox();
|
||||
onComplete?.Invoke();
|
||||
@@ -247,35 +255,18 @@ namespace Unheimlich.UI
|
||||
|
||||
float amplitude = _currentAnimationSettings.FloatingAmplitude;
|
||||
float duration = _currentAnimationSettings.FloatingDuration;
|
||||
float offset = index * 0.2f;
|
||||
float delay = index * 0.2f;
|
||||
|
||||
Vector3 startPos = choice.transform.localPosition;
|
||||
|
||||
LeanTween.value(choice, 0f, Mathf.PI * 2f, duration)
|
||||
.setDelay(offset)
|
||||
.setOnUpdate((float val) => {
|
||||
if (choice != null)
|
||||
{
|
||||
Vector3 newPos = startPos;
|
||||
newPos.y += Mathf.Sin(val) * amplitude;
|
||||
choice.transform.localPosition = newPos;
|
||||
}
|
||||
})
|
||||
.setLoopClamp()
|
||||
.setEase(LeanTweenType.linear);
|
||||
int tweenId = TweenHelper.FloatAnimation(choice, startPos, amplitude, duration, delay, Axis.Y);
|
||||
_floatingTweenIds.Add(tweenId);
|
||||
}
|
||||
|
||||
public void RotationAnimation(float degreesPerSecond = 60f)
|
||||
{
|
||||
if (degreesPerSecond <= 0f)
|
||||
return;
|
||||
|
||||
float duration = 360f / degreesPerSecond;
|
||||
|
||||
LeanTween.cancel(ChoiceContainer);
|
||||
LeanTween.rotateAroundLocal(ChoiceContainer, _currentRotationAxis, 360f, duration)
|
||||
.setLoopClamp()
|
||||
.setEase(LeanTweenType.linear);
|
||||
TweenHelper.CancelTween(ref _rotationTweenId);
|
||||
_rotationTweenId = TweenHelper.RotateAround(ChoiceContainer, _currentRotationAxis, degreesPerSecond);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -318,10 +309,17 @@ namespace Unheimlich.UI
|
||||
_currentAnchor = null;
|
||||
_currentAnimationSettings = null;
|
||||
_activeChoices.Clear();
|
||||
LeanTween.cancel(ChoiceContainer);
|
||||
|
||||
TweenHelper.CancelTween(ref _rotationTweenId);
|
||||
foreach (int tweenId in _floatingTweenIds)
|
||||
{
|
||||
int id = tweenId;
|
||||
TweenHelper.CancelTween(ref id);
|
||||
}
|
||||
_floatingTweenIds.Clear();
|
||||
|
||||
foreach (Transform child in ChoiceContainer.transform)
|
||||
{
|
||||
LeanTween.cancel(child.gameObject);
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user