73 lines
1.9 KiB
C#
73 lines
1.9 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Threading;
|
||
|
using Cysharp.Threading.Tasks;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UIElements;
|
||
|
// ReSharper disable MemberCanBeProtected.Global
|
||
|
|
||
|
namespace BITKit.UX
|
||
|
{
|
||
|
public class UIToolKitPanel : MonoBehaviour,IUXPanel
|
||
|
{
|
||
|
public UIToolKitPanel()
|
||
|
{
|
||
|
Index = GetType().FullName;
|
||
|
}
|
||
|
[Header(Constant.Header.Components)]
|
||
|
[SerializeField] protected UIDocument document;
|
||
|
[Header(Constant.Header.Settings)]
|
||
|
[SerializeField] private bool isAnimate;
|
||
|
[SerializeField] private bool allowCursor;
|
||
|
[SerializeField] private bool allowInput;
|
||
|
[SerializeField] private bool autoEntry;
|
||
|
public bool IsAnimate => isAnimate;
|
||
|
public bool IsValid => cancellationToken.IsCancellationRequested is false;
|
||
|
public string Index { get; private set; }
|
||
|
public bool AllowCursor => allowCursor;
|
||
|
public bool AllowInput => allowInput;
|
||
|
protected CancellationToken cancellationToken { get; private set; }
|
||
|
protected virtual void Awake()
|
||
|
{
|
||
|
cancellationToken = gameObject.GetCancellationTokenOnDestroy();
|
||
|
Index= typeof(UIToolKitPanel) == GetType() ? gameObject.name : GetType().Name;
|
||
|
}
|
||
|
protected virtual void Start()
|
||
|
{
|
||
|
if(IsValid && autoEntry)
|
||
|
UXService.Entry(this);
|
||
|
}
|
||
|
public void Entry()
|
||
|
{
|
||
|
UXService.Entry(this);
|
||
|
}
|
||
|
protected virtual void OnEnable()=>UXService.Register(this);
|
||
|
protected virtual void OnDisable()=>UXService.UnRegister(this);
|
||
|
void IUXPanel.Entry()
|
||
|
{
|
||
|
OnEntryOrExit(true);
|
||
|
document.rootVisualElement.SetActive(true);
|
||
|
}
|
||
|
void IUXPanel.Exit()
|
||
|
{
|
||
|
if (IsValid is false) return;
|
||
|
OnEntryOrExit(false);
|
||
|
try
|
||
|
{
|
||
|
document.rootVisualElement.SetActive(false);
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
BIT4Log.Warning<UIToolKitPanel>(name);
|
||
|
BIT4Log.LogException(e);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
protected virtual void OnEntryOrExit(bool isEntry)
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|