1
This commit is contained in:
99
Unity/Scripts/UX/Components/UXData.cs
Normal file
99
Unity/Scripts/UX/Components/UXData.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Sirenix.OdinInspector;
|
||||
using System.Threading;
|
||||
using UnityEngine.UIElements;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
#endif
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public interface IDataComponent : IStart, IStop
|
||||
{
|
||||
void SetKey(string value);
|
||||
}
|
||||
[System.Serializable]
|
||||
public sealed class MonoDataComponent : MonoBehaviour, IDataComponent
|
||||
{
|
||||
public MonoBehaviour mono;
|
||||
IDataComponent component => mono as IDataComponent;
|
||||
public void OnStart()
|
||||
{
|
||||
component.OnStart();
|
||||
}
|
||||
|
||||
public void OnStop()
|
||||
{
|
||||
component.OnStop();
|
||||
}
|
||||
|
||||
public void SetKey(string value)
|
||||
{
|
||||
component.SetKey(value);
|
||||
}
|
||||
}
|
||||
public abstract class DataComponents : IDataComponent
|
||||
{
|
||||
protected string key;
|
||||
public virtual void OnStart()
|
||||
{
|
||||
|
||||
}
|
||||
public virtual void SetKey(string key)
|
||||
{
|
||||
this.key = key;
|
||||
}
|
||||
public virtual void OnStop()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
public class UXData : MonoBehaviour
|
||||
{
|
||||
[SerializeReference, SubclassSelector] public References key;
|
||||
[SerializeReference, SubclassSelector] public DataComponents dataParser;
|
||||
bool initialized;
|
||||
void OnEnable()
|
||||
{
|
||||
dataParser.SetKey(key);
|
||||
if (initialized)
|
||||
{
|
||||
dataParser.OnStart();
|
||||
}
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
if (initialized is false)
|
||||
{
|
||||
dataParser.OnStart();
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
void OnDisable()
|
||||
{
|
||||
if (initialized)
|
||||
{
|
||||
dataParser.OnStop();
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.CustomEditor(typeof(UXData))]
|
||||
public class UXDataInspector : BITInspector<UXData>
|
||||
{
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
CreateSubTitle(Constant.Header.Settings);
|
||||
var key = root.Create<PropertyField>();
|
||||
CreateSubTitle(Constant.Header.Reference);
|
||||
var dataParser = root.Create<PropertyField>();
|
||||
|
||||
key.bindingPath = nameof(UXData.key);
|
||||
dataParser.bindingPath = nameof(UXData.dataParser);
|
||||
return root;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user