EscapeShooter/My project/Assets/Project Files/Game/Scripts/UI/Pages/UIExamplePage.cs

63 lines
1.8 KiB
C#

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<UIGame>();
}
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<UIExamplePage>(() =>
{
// Is called when UIExamplePage page is hidden
});
}
#endregion
}
}