BITKit/Src/Unity/Scripts/UX/Core/UXPanel.cs

82 lines
2.2 KiB
C#
Raw Normal View History

2023-08-23 01:59:26 +08:00
using System;
2023-06-05 19:57:17 +08:00
using System.Collections;
using System.Collections.Generic;
2023-06-29 14:57:11 +08:00
using System.Linq;
2023-06-05 19:57:17 +08:00
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.Events;
2023-06-29 14:57:11 +08:00
2023-06-05 19:57:17 +08:00
using Cursor = UnityEngine.Cursor;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace BITKit.UX
{
2023-09-01 14:35:05 +08:00
[Obsolete]
2023-06-05 19:57:17 +08:00
public interface IPanelComponent : IActivable
{
}
2023-08-23 01:59:26 +08:00
[Obsolete("See UXService")]
2023-06-05 19:57:17 +08:00
public class UXPanel : UXElement
{
[Header(Constant.Header.Components)]
public UIDocument document;
[Header(Constant.Header.Settings)]
public bool cursor;
public bool allowInput;
public bool isAdditive;
[Header(Constant.Header.InternalVariables)]
2023-06-29 14:57:11 +08:00
private IPanelComponent[] components;
2023-06-05 19:57:17 +08:00
public override void OnStart()
{
components = GetComponentsInChildren<IPanelComponent>(true);
document.enabled = true;
base.OnStart();
2023-06-29 14:57:11 +08:00
foreach (var x in document.rootVisualElement.Children().ToArray())
{
if(x.ClassListContains("removeOnStart"))
x.RemoveFromHierarchy();
}
2023-06-05 19:57:17 +08:00
}
public override void Set(bool active)
{
document.rootVisualElement.style.display = (active) ? DisplayStyle.Flex : DisplayStyle.None;
if (active)
RegisterCallback();
else
UnRegisterCallback();
foreach (var x in components)
{
x.SetActive(active);
}
}
public virtual void OnDestroyComponent() { }
protected virtual float GetOpacity()
{
return document.rootVisualElement.style.opacity.value;
}
protected virtual void SetOpacity(float value)
{
document.rootVisualElement.style.opacity = new(value);
}
protected virtual void RegisterCallback() { }
protected virtual void UnRegisterCallback() { }
[BIT]
public void Entry()
{
BITAppForUnity.ThrowIfNotPlaying();
UXFramework.Enter(gameObject.name);
}
}
#if UNITY_EDITOR
[CustomEditor(typeof(UXPanel), true)]
public class UXPanelInspector : BITInspector<UXPanel>
{
}
#endif
}