| 1234567891011121314151617181920212223242526272829303132333435 |
- using GameAudio = DevilLink2.Presentation.AudioManager;
- using DevilLink2.Presentation;
- using UnityEngine;
- namespace DevilLink2.UI
- {
- /// <summary>Synchronous visibility/input gate. Popup motion and completion callbacks are retired.</summary>
- [DisallowMultipleComponent]
- public sealed class UITransition : MonoBehaviour
- {
- // Compatibility for existing editor tools. These APIs can no longer enable motion.
- public const float EnterSeconds=0,ExitSeconds=0;
- public static bool EnablePopupAnimations { get=>false; set{} }
- public bool? PopupAnimationOverride => null;
- public void SetPopupAnimationOverride(bool? ignored){}
- private CanvasGroup group;private Transform content;private bool initialized,inputEnabled=true;
- public bool IsShown {get;private set;}
- public bool IsTransitioning => false;
- public static bool IsVisible(GameObject target){var gate=target?target.GetComponent<UITransition>():null;return gate?gate.IsShown:target&&target.activeSelf;}
- public static void Show(GameObject target,bool visible){if(!target)return;var gate=target.GetComponent<UITransition>();if(!gate)gate=target.AddComponent<UITransition>();gate.SetVisible(visible);}
- public static void SetInput(GameObject target,bool enabled){if(!target)return;var gate=target.GetComponent<UITransition>();if(gate){gate.inputEnabled=enabled;gate.ApplyInput();}else{var g=target.GetComponent<CanvasGroup>();if(g)g.interactable=enabled;}}
- private void Prepare(){if(initialized)return;group=GetComponent<CanvasGroup>();if(!group)group=gameObject.AddComponent<CanvasGroup>();
- content=transform.Find("Card");if(!content)content=transform.Find("Border");if(!content)content=transform.Find("RewardCard");
- var old=GetComponent<PopupAnimationController>();if(old){old.ResetVisual();old.enabled=false;}
- initialized=true;
- }
- public void SetVisible(bool visible){bool first=!initialized;Prepare();bool changed=IsShown!=visible;IsShown=visible;
- Normalize();ApplyInput();gameObject.SetActive(visible);
- if(!first&&changed&&GetComponent<UnityEngine.UI.Image>())GameAudio.Sound(visible?AudioCue.UI_Open:AudioCue.UI_Close);
- }
- private void Normalize(){if(group)group.alpha=1;if(content){content.localScale=Vector3.one;var g=content.GetComponent<CanvasGroup>();if(g)g.alpha=1;}}
- private void ApplyInput(){if(!group)return;group.interactable=IsShown&&inputEnabled;group.blocksRaycasts=IsShown;}
- private void OnEnable(){if(initialized){Normalize();ApplyInput();}}
- private void OnDisable(){if(group){group.alpha=1;group.interactable=false;group.blocksRaycasts=false;}if(content)content.localScale=Vector3.one;}
- }
- }
|