using UnityEngine; using UnityEngine.UI; namespace Watermelon { public class UIExamplePage : UIPage { [SerializeField] Image backgroundImage; private RectTransform pageRectTransform; private Color defaultBackgroundColor; private UIGame gamePage; public override void Init() { // Cache variables pageRectTransform = (RectTransform)transform; defaultBackgroundColor = backgroundImage.color; // Or get them from other components gamePage = UIController.GetPage(); } protected override void OnShow() { // Reset components backgroundImage.color = defaultBackgroundColor.SetAlpha(0.0f); // Play animation backgroundImage.DOColor(defaultBackgroundColor, 0.3f).OnComplete(delegate { // IMPORTANT // For the correct work of UIController events you should call NotifyOpened method right after page animations are completed NotifyOpened(); }); } protected override void OnHide() { // Play animation backgroundImage.DOFade(0.0f, 0.3f).OnComplete(delegate { // IMPORTANT // For the correct work of UIController events you should call NotifyClosed method right after page animations are completed NotifyClosed(); }); } #region Buttons public void OnCloseButtonClicked() { // or instead you can use UIController static method and add OnPageHidded callback UIController.HidePage(() => { // Is called when UIExamplePage page is hidden }); } #endregion } }