NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/UI_TransitionController.cs

132 lines
2.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using Button = UnityEngine.UI.Button;
using Image = UnityEngine.UI.Image;
using Toggle = UnityEngine.UI.Toggle;
using ScrollView = PhxhSDK.PhxhScrollView;
using Framework;
using DG.Tweening;
public class UI_TransitionController : UIWindow
{
//UI GameObj
///Auto Gen Start///
public Image Image_Content;
public TMP_Text Text_Title;
public TMP_Text Text_Yes;
public Image Image_Mask;
///Auto Gen End///
public enum ShowType
{
TitleOnly, //仅显示中间标题
BlackOnly //仅黑屏
}
private ShowType _type;
private GameObject _goBlack;
private GameObject _goTitle;
//界面打开外部调用
public static async UniTask<UIWindow> Open(int input)
{
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_Transition, input);
}
public static async UniTask<UIWindow> Open(ShowType showType)
{
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_Transition, showType);
}
// deal with input data
public override void PreLoad(object data = null)
{
if (data is ShowType showType)
{
_type = showType;
}
else if (data is int showInt)
{
_type = (ShowType)showInt;
}
}
// Use this for initialization
public override void OnInit()
{
//bind UI GameObj
UI_TransitionBinder.GetComponents(this);
_goBlack = FindObj("Mask");
_goTitle = FindObj("Content");
}
//invoke when open window
protected override void OnShowWindow(object data = null)
{
_ShowPanel();
}
//invoke when reload window
protected override void OnReloadWindow(object data = null)
{
}
//invoke when close window
protected override void OnHideWindow()
{
}
//invoke when destroy
public override void OnRelease()
{
base.OnRelease();
}
#region #API
public async UniTask EnterBlack(float time = 0.5f)
{
Image_Mask.DOFade(1, time);
await UniTask.Delay((int)(time * 1000));
}
public async UniTask ExitBlack(float time = 0.5f)
{
Image_Mask.DOFade(0, time);
await UniTask.Delay((int)(time * 1000));
}
#endregion
#region #Show
private void _ShowPanel()
{
switch (_type)
{
case ShowType.BlackOnly:
{
_ShowBlack();
break;
}
}
}
private void _ShowBlack()
{
_goBlack.SetActive(true);
_goTitle.SetActive(false);
}
#endregion
}