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; public class AppSwitcher : UIPage { public TextAsset rainbowEstablish; public TextAsset rainbowRemove; public GameObject rainbow; public GameObject gameLayoutContainer; public GameObject exitButton; public RectMask2D rectMask; [Header("Slide Animation Settings")] public float slideDuration = 0.5f; private SkottiePlayerV2 rainbowPlayer; private TweenBase slideInTween; private TweenBase slideOutTween; protected override void OnManagedAwake() { base.OnManagedAwake(); PageName = "AppSwitcher"; rainbowPlayer = rainbow.GetComponentInChildren(); if (rectMask == null) { rectMask = GetComponent(); } } protected override void DoTransitionIn(Action onComplete) { gameLayoutContainer.SetActive(true); // Play establishing animations rainbowPlayer.LoadAnimation(rainbowEstablish.text); rainbowPlayer.PlayAnimation(false); rainbowPlayer.loop = false; // Show the exit button exitButton.SetActive(true); // Set input mode to UI QuickAccess.Instance.PlayerController.InterruptMoveTo(); InputManager.Instance.SetInputMode(InputMode.UI); // Slide in animation - tween padding.left from 1700 to 0 slideInTween = TweenPaddingLeft(1700f, 0f, Tween.EaseOutBack, () => onComplete?.Invoke()); } protected override void DoTransitionOut(Action onComplete) { rainbowPlayer.LoadAnimation(rainbowRemove.text); rainbowPlayer.PlayAnimation(true); rainbowPlayer.loop = false; // Set input mode to game and ui InputManager.Instance.SetInputMode(InputMode.GameAndUI); // Hide the exit button exitButton.SetActive(false); // Slide out animation - tween padding.left from 0 to 1700 slideOutTween = TweenPaddingLeft(0f, 1700f, Tween.EaseInBack, () => { gameLayoutContainer.SetActive(false); PlayerHudManager.Instance.ShowAllHud(); onComplete?.Invoke(); }); } /// /// Tweens the left padding of the rectMask from startValue to endValue. /// 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(); } }