Update HUD updates, moving scattered prefabs into a central HUD manager (#53)
Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Reviewed-on: #53
This commit is contained in:
@@ -1,89 +1,122 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using SkiaSharp.Unity;
|
||||
using Input;
|
||||
using AppleHills.Core;
|
||||
using UI.Core;
|
||||
using Pixelplacement;
|
||||
using Pixelplacement.TweenSystem;
|
||||
using UI;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class AppSwitcher : MonoBehaviour
|
||||
public class AppSwitcher : UIPage
|
||||
{
|
||||
|
||||
public TextAsset iconIdle;
|
||||
public TextAsset iconEstablish;
|
||||
public TextAsset rainbowEstablish;
|
||||
public TextAsset rainbowRemove;
|
||||
public GameObject rainbow;
|
||||
public GameObject icon;
|
||||
public GameObject rainbowIn;
|
||||
public GameObject rainbowOut;
|
||||
public GameObject gameLayoutContainer;
|
||||
public GameObject exitButton;
|
||||
public RectMask2D rectMask;
|
||||
|
||||
[Header("Slide Animation Settings")]
|
||||
public float slideDuration = 0.5f;
|
||||
|
||||
private SkottiePlayerV2 rainbowInPlayer;
|
||||
private SkottiePlayerV2 rainbowOutPlayer;
|
||||
private TweenBase slideInTween;
|
||||
private TweenBase slideOutTween;
|
||||
|
||||
private SkottiePlayerV2 iconPlayer;
|
||||
private SkottiePlayerV2 rainbowPlayer;
|
||||
private Animator animator;
|
||||
|
||||
|
||||
private void OnEnable()
|
||||
protected override void OnManagedAwake()
|
||||
{
|
||||
iconPlayer = icon.GetComponentInChildren<SkottiePlayerV2>();
|
||||
rainbowPlayer = rainbow.GetComponentInChildren<SkottiePlayerV2>();
|
||||
animator = GetComponent<Animator>();
|
||||
rainbow.SetActive(false);
|
||||
base.OnManagedAwake();
|
||||
|
||||
PageName = "AppSwitcher";
|
||||
rainbowInPlayer = rainbowIn.GetComponent<SkottiePlayerV2>();
|
||||
rainbowOutPlayer = rainbowOut.GetComponent<SkottiePlayerV2>();
|
||||
|
||||
if (rectMask == null)
|
||||
{
|
||||
rectMask = GetComponent<RectMask2D>();
|
||||
}
|
||||
|
||||
// Initially hide both
|
||||
rainbowIn.SetActive(true);
|
||||
exitButton.SetActive(false);
|
||||
}
|
||||
|
||||
public void OpenAppSwitcher()
|
||||
protected override void DoTransitionIn(Action onComplete)
|
||||
{
|
||||
PlayerHudManager.Instance.HideAllHudExcept(gameObject);
|
||||
|
||||
rainbow.SetActive(true);
|
||||
//Activate players
|
||||
rainbow.SetActive(true);
|
||||
gameLayoutContainer.SetActive(true);
|
||||
|
||||
// Play establishing animations
|
||||
rainbowPlayer.LoadAnimation(rainbowEstablish.text);
|
||||
rainbowPlayer.PlayAnimation(false);
|
||||
rainbowPlayer.loop = false;
|
||||
gameLayoutContainer.SetActive(true);
|
||||
animator.Play("GamesReveal");
|
||||
|
||||
// Show the exit button
|
||||
exitButton.SetActive(true);
|
||||
|
||||
// Set input mode to UI
|
||||
QuickAccess.Instance.PlayerController.InterruptMoveTo();
|
||||
InputManager.Instance.SetInputMode(InputMode.UI);
|
||||
|
||||
gameLayoutContainer.SetActive(true);
|
||||
|
||||
rainbowPlayer.OnAnimationFinished += AnimFinished;
|
||||
// Hide rainbow out, show rainbow in
|
||||
rainbowOut.SetActive(false);
|
||||
|
||||
// Play animation on rainbow in without resetting state
|
||||
rainbowInPlayer.PlayAnimation(true);
|
||||
|
||||
// Slide in animation - tween padding.left from 1700 to 0
|
||||
slideInTween = TweenPaddingLeft(1700f, 0f, Tween.EaseOut, () =>
|
||||
{
|
||||
onComplete?.Invoke();
|
||||
rainbowOut.SetActive(true);
|
||||
exitButton.SetActive(true);
|
||||
});
|
||||
}
|
||||
|
||||
public void CloseAppSwitcher()
|
||||
protected override void DoTransitionOut(Action onComplete)
|
||||
{
|
||||
rainbowPlayer.resetAfterFinished = true;
|
||||
rainbowPlayer.LoadAnimation(rainbowRemove.text);
|
||||
rainbowPlayer.PlayAnimation(false);
|
||||
rainbowPlayer.loop = false;
|
||||
animator.Play("GamesHide");
|
||||
|
||||
// Set input mode to game and ui
|
||||
InputManager.Instance.SetInputMode(InputMode.GameAndUI);
|
||||
rainbowIn.SetActive(false);
|
||||
|
||||
// Play animation on rainbow out with resetting state
|
||||
rainbowOutPlayer.PlayAnimation(true);
|
||||
|
||||
// Hide the exit button
|
||||
exitButton.SetActive(false);
|
||||
|
||||
PlayerHudManager.Instance.ShowAllHud();
|
||||
// Slide out animation - tween padding.left from 0 to 1700
|
||||
slideOutTween = TweenPaddingLeft(0f, 1700f, Tween.EaseIn, () => {
|
||||
gameLayoutContainer.SetActive(false);
|
||||
rainbowIn.SetActive(true);
|
||||
onComplete?.Invoke();
|
||||
InputManager.Instance.SetInputMode(InputMode.GameAndUI);
|
||||
});
|
||||
}
|
||||
|
||||
public void GamesHiddenAnimationEvent()
|
||||
{
|
||||
rainbow.SetActive(false);
|
||||
gameLayoutContainer.SetActive(false);
|
||||
|
||||
}
|
||||
|
||||
private void AnimFinished(string str)
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Tweens the left padding of the rectMask from startValue to endValue.
|
||||
/// </summary>
|
||||
private TweenBase TweenPaddingLeft(float startValue, float endValue, AnimationCurve easeCurve, Action onComplete)
|
||||
{
|
||||
// Set starting position
|
||||
Vector4 startPadding = rectMask.padding;
|
||||
startPadding.x = startValue;
|
||||
rectMask.padding = startPadding;
|
||||
|
||||
return Tween.Value(
|
||||
startValue,
|
||||
endValue,
|
||||
(value) => {
|
||||
Vector4 padding = rectMask.padding;
|
||||
padding.x = value;
|
||||
rectMask.padding = padding;
|
||||
},
|
||||
slideDuration,
|
||||
0f, // no delay
|
||||
easeCurve,
|
||||
Tween.LoopType.None,
|
||||
null, // onStart
|
||||
onComplete
|
||||
);
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
|
||||
// Clean up tweens
|
||||
slideInTween?.Stop();
|
||||
slideOutTween?.Stop();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user