2023-06-05 19:57:17 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using System.Threading;
|
2024-03-31 23:31:00 +08:00
|
|
|
using Cysharp.Threading.Tasks;
|
2023-06-05 19:57:17 +08:00
|
|
|
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
|
|
|
|
{
|
2024-03-31 23:31:00 +08:00
|
|
|
[SerializeReference, SubclassSelector] private IReference key;
|
|
|
|
[SerializeReference, SubclassSelector] private IDataComponent dataParser;
|
|
|
|
private async void Start()
|
2023-06-05 19:57:17 +08:00
|
|
|
{
|
2024-03-31 23:31:00 +08:00
|
|
|
await UniTask.NextFrame();
|
|
|
|
if (destroyCancellationToken.IsCancellationRequested) return;
|
|
|
|
dataParser.SetKey(key.Value);
|
|
|
|
dataParser.OnStart();
|
|
|
|
destroyCancellationToken.Register(dataParser.OnStop);
|
2023-06-05 19:57:17 +08:00
|
|
|
}
|
2024-03-31 23:31:00 +08:00
|
|
|
// #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
|
2023-06-05 19:57:17 +08:00
|
|
|
}
|
|
|
|
}
|