1
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine.UIElements;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
@@ -51,48 +52,32 @@ namespace BITKit.UX
|
||||
}
|
||||
public class UXData : MonoBehaviour
|
||||
{
|
||||
[SerializeReference, SubclassSelector] public References key;
|
||||
[SerializeReference, SubclassSelector] public DataComponents dataParser;
|
||||
bool initialized;
|
||||
void OnEnable()
|
||||
[SerializeReference, SubclassSelector] private IReference key;
|
||||
[SerializeReference, SubclassSelector] private IDataComponent dataParser;
|
||||
private async void Start()
|
||||
{
|
||||
dataParser.SetKey(key);
|
||||
if (initialized)
|
||||
{
|
||||
dataParser.OnStart();
|
||||
}
|
||||
await UniTask.NextFrame();
|
||||
if (destroyCancellationToken.IsCancellationRequested) return;
|
||||
dataParser.SetKey(key.Value);
|
||||
dataParser.OnStart();
|
||||
destroyCancellationToken.Register(dataParser.OnStop);
|
||||
}
|
||||
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
|
||||
// #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
|
||||
}
|
||||
}
|
@@ -71,9 +71,10 @@ namespace BITKit.UX.Components
|
||||
[System.Serializable]
|
||||
public sealed class BoolEvent : DataComponents
|
||||
{
|
||||
public UnityEvent<bool> outputEvent;
|
||||
public UnityEvent ifTrueEvent;
|
||||
public UnityEvent ifFlaseEvent;
|
||||
[SerializeField]private UnityEvent<bool> outputEvent;
|
||||
[SerializeField]private UnityEvent ifTrueEvent;
|
||||
[SerializeField]private UnityEvent ifFlaseEvent;
|
||||
private readonly Optional<bool> _current = new();
|
||||
public override void OnStart()
|
||||
{
|
||||
Data.AddListener<bool>(key, OnSetBool, true);
|
||||
@@ -84,6 +85,11 @@ namespace BITKit.UX.Components
|
||||
}
|
||||
async void OnSetBool(bool boolean)
|
||||
{
|
||||
if (_current.Allow)
|
||||
{
|
||||
if (_current.Value == boolean) return;
|
||||
}
|
||||
_current.SetValueThenAllow(boolean);
|
||||
try
|
||||
{
|
||||
await UniTask.SwitchToMainThread(BITApp.CancellationToken);
|
||||
|
Reference in New Issue
Block a user