Files
AppleHillsProduction/Assets/Scripts/UI/AppSwitcher.cs

118 lines
3.3 KiB
C#
Raw Normal View History

2025-11-09 21:01:41 +01:00
using System;
using UnityEngine;
2025-11-09 21:01:41 +01:00
using UnityEngine.UI;
2025-11-06 15:36:02 +01:00
using SkiaSharp.Unity;
2025-11-06 17:49:44 +01:00
using Input;
using AppleHills.Core;
2025-11-09 21:01:41 +01:00
using UI.Core;
using Pixelplacement;
using Pixelplacement.TweenSystem;
2025-11-09 13:23:03 +01:00
using UI;
2025-11-09 21:01:41 +01:00
public class AppSwitcher : UIPage
{
2025-11-06 15:36:02 +01:00
public TextAsset rainbowEstablish;
public TextAsset rainbowRemove;
2025-11-06 17:49:44 +01:00
public GameObject rainbow;
public GameObject gameLayoutContainer;
public GameObject exitButton;
2025-11-09 21:01:41 +01:00
public RectMask2D rectMask;
[Header("Slide Animation Settings")]
public float slideDuration = 0.5f;
2025-11-06 17:49:44 +01:00
private SkottiePlayerV2 rainbowPlayer;
2025-11-09 21:01:41 +01:00
private TweenBase slideInTween;
private TweenBase slideOutTween;
2025-11-06 15:36:02 +01:00
2025-11-09 21:01:41 +01:00
protected override void OnManagedAwake()
2025-11-06 15:36:02 +01:00
{
2025-11-09 21:01:41 +01:00
base.OnManagedAwake();
PageName = "AppSwitcher";
2025-11-06 17:49:44 +01:00
rainbowPlayer = rainbow.GetComponentInChildren<SkottiePlayerV2>();
2025-11-09 21:01:41 +01:00
if (rectMask == null)
{
rectMask = GetComponent<RectMask2D>();
}
2025-11-06 15:36:02 +01:00
}
2025-11-09 21:01:41 +01:00
protected override void DoTransitionIn(Action onComplete)
{
2025-11-06 17:49:44 +01:00
gameLayoutContainer.SetActive(true);
// Play establishing animations
rainbowPlayer.LoadAnimation(rainbowEstablish.text);
rainbowPlayer.PlayAnimation(false);
rainbowPlayer.loop = false;
2025-11-09 21:01:41 +01:00
2025-11-06 17:49:44 +01:00
// Show the exit button
exitButton.SetActive(true);
// Set input mode to UI
QuickAccess.Instance.PlayerController.InterruptMoveTo();
InputManager.Instance.SetInputMode(InputMode.UI);
2025-11-09 21:01:41 +01:00
// Slide in animation - tween padding.left from 1700 to 0
slideInTween = TweenPaddingLeft(1700f, 0f, Tween.EaseOutBack, () => onComplete?.Invoke());
2025-11-06 17:49:44 +01:00
}
2025-11-09 21:01:41 +01:00
protected override void DoTransitionOut(Action onComplete)
2025-11-06 17:49:44 +01:00
{
rainbowPlayer.LoadAnimation(rainbowRemove.text);
2025-11-09 21:01:41 +01:00
rainbowPlayer.PlayAnimation(true);
2025-11-06 17:49:44 +01:00
rainbowPlayer.loop = false;
2025-11-09 21:01:41 +01:00
2025-11-06 17:49:44 +01:00
// Set input mode to game and ui
InputManager.Instance.SetInputMode(InputMode.GameAndUI);
// Hide the exit button
exitButton.SetActive(false);
2025-11-09 13:23:03 +01:00
2025-11-09 21:01:41 +01:00
// Slide out animation - tween padding.left from 0 to 1700
slideOutTween = TweenPaddingLeft(0f, 1700f, Tween.EaseInBack, () => {
gameLayoutContainer.SetActive(false);
PlayerHudManager.Instance.ShowAllHud();
onComplete?.Invoke();
});
2025-11-06 17:49:44 +01:00
}
2025-11-09 21:01:41 +01:00
/// <summary>
/// Tweens the left padding of the rectMask from startValue to endValue.
/// </summary>
private TweenBase TweenPaddingLeft(float startValue, float endValue, AnimationCurve easeCurve, Action onComplete)
2025-11-06 17:49:44 +01:00
{
2025-11-09 21:01:41 +01:00
// 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
);
}
2025-11-06 17:49:44 +01:00
2025-11-09 21:01:41 +01:00
protected override void OnDestroy()
{
base.OnDestroy();
// Clean up tweens
slideInTween?.Stop();
slideOutTween?.Stop();
2025-11-06 17:49:44 +01:00
}
}