更改文件架构
This commit is contained in:
8
Packages/Common~/Scripts/UX/Alert.meta
Normal file
8
Packages/Common~/Scripts/UX/Alert.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8843d28029d2ba48852f15202d54fe8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
26
Packages/Common~/Scripts/UX/Alert/Alerter.cs
Normal file
26
Packages/Common~/Scripts/UX/Alert/Alerter.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
namespace BITKit.UX.Internal
|
||||
{
|
||||
[System.Serializable]
|
||||
public record Alert : AlertMessage, IAction
|
||||
{
|
||||
public void Excute()
|
||||
{
|
||||
BITKit.UX.Alert.Print(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class Alerter : MonoBehaviour
|
||||
{
|
||||
public AlertMessage message;
|
||||
public void Excute()
|
||||
{
|
||||
Alert.Print(message);
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Alert/Alerter.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Alert/Alerter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 818def42ae392e34abc38ea6068cb181
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
52
Packages/Common~/Scripts/UX/Alert/UXAlert.cs
Normal file
52
Packages/Common~/Scripts/UX/Alert/UXAlert.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
[System.Serializable]
|
||||
public record AlertMessage
|
||||
{
|
||||
public string title = "Alert";
|
||||
public string message = "message";
|
||||
}
|
||||
|
||||
public static class Alert
|
||||
{
|
||||
public static void Print(AlertMessage message)
|
||||
{
|
||||
UXAlert.Singleton.PrintAlertMessage(message);
|
||||
}
|
||||
}
|
||||
public class UXAlert : MonoBehaviour
|
||||
{
|
||||
internal static UXAlert Singleton;
|
||||
[SerializeField] private UIDocument document;
|
||||
Label titleLabel;
|
||||
Label contextLabel;
|
||||
Button comfirmButton;
|
||||
private void Awake()
|
||||
{
|
||||
Singleton = this;
|
||||
var container = document.rootVisualElement;
|
||||
titleLabel = container.Q<Label>(UXConstant.TitleLabel);
|
||||
contextLabel = container.Q<Label>(UXConstant.ContextLabel);
|
||||
comfirmButton = container.Q<Button>(UXConstant.MainButton);
|
||||
comfirmButton.clicked += Close;
|
||||
Close();
|
||||
}
|
||||
internal void PrintAlertMessage(AlertMessage message)
|
||||
{
|
||||
document.rootVisualElement.SetActive(true);
|
||||
titleLabel.text = message.title;
|
||||
contextLabel.text = message.message;
|
||||
}
|
||||
void Close()
|
||||
{
|
||||
document.rootVisualElement.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Alert/UXAlert.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Alert/UXAlert.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4a5649cb486a3c44ba26996d036e853
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
29
Packages/Common~/Scripts/UX/BITKit.UX.asmdef
Normal file
29
Packages/Common~/Scripts/UX/BITKit.UX.asmdef
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "BITKit.UX",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:2bafac87e7f4b9b418d9448d219b01ab",
|
||||
"GUID:a209c53514018594f9f482516f2a6781",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:8b544bd1de979ea49a79084643257201",
|
||||
"GUID:be17a8778dbfe454890ed8279279e153",
|
||||
"GUID:9e24947de15b9834991c9d8411ea37cf",
|
||||
"GUID:593a5b492d29ac6448b1ebf7f035ef33",
|
||||
"GUID:84651a3751eca9349aac36a66bba901b",
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:9400d40641bab5b4a9702f65bf5c6eb5"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"ODIN_INSPECTOR"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
7
Packages/Common~/Scripts/UX/BITKit.UX.asmdef.meta
Normal file
7
Packages/Common~/Scripts/UX/BITKit.UX.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ef4ed8ff60a7aa4bb60a8030e6f4008
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/UX/BlackScreen.meta
Normal file
8
Packages/Common~/Scripts/UX/BlackScreen.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47ef6611ff66d144aba7e30f8cbecb09
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
50
Packages/Common~/Scripts/UX/BlackScreen/BlackScreen.cs
Normal file
50
Packages/Common~/Scripts/UX/BlackScreen/BlackScreen.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.Events;
|
||||
using Cysharp.Threading.Tasks;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class BlackScreen : MonoBehaviour
|
||||
{
|
||||
[Header(Constant.Header.Components)]
|
||||
public UIDocument document;
|
||||
VisualElement root;
|
||||
void Start()
|
||||
{
|
||||
root = document.rootVisualElement;
|
||||
Data.AddListener<UnityAction>("BlackScreen", x =>
|
||||
{
|
||||
CrossFade(x, 0.32f);
|
||||
});
|
||||
root.SetOpacity(1);
|
||||
root.SetActive(false);
|
||||
}
|
||||
void CrossFade(UnityAction action, float duration = 1f)
|
||||
{
|
||||
Sequence sequence = DOTween.Sequence();
|
||||
var enterTween = DOTween.To(root.GetOpacity, root.SetOpacity, 1, duration);
|
||||
var exitTween = DOTween.To(root.GetOpacity, root.SetOpacity, 0, duration);
|
||||
|
||||
sequence.Append(enterTween);
|
||||
sequence.AppendInterval(0.1f);
|
||||
sequence.Append(exitTween);
|
||||
|
||||
enterTween.onComplete += () =>
|
||||
{
|
||||
action.Invoke();
|
||||
};
|
||||
sequence.onComplete += () =>
|
||||
{
|
||||
root.SetActive(false);
|
||||
};
|
||||
|
||||
root.SetActive(true);
|
||||
root.SetOpacity(0);
|
||||
|
||||
sequence.Play();
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/BlackScreen/BlackScreen.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/BlackScreen/BlackScreen.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e93f74931ac425c45953585809454f41
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/UX/Components.meta
Normal file
8
Packages/Common~/Scripts/UX/Components.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7ba09e922d82abe4a817808a8f39e91b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
99
Packages/Common~/Scripts/UX/Components/UXData.cs
Normal file
99
Packages/Common~/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
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Components/UXData.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Components/UXData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae1f33a93b73bad40817685f6d13e097
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6667f2ea88571b54881d9d1118fc3e6f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "BITKit.UX.Components",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:a209c53514018594f9f482516f2a6781",
|
||||
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:be17a8778dbfe454890ed8279279e153",
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:9400d40641bab5b4a9702f65bf5c6eb5"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d2db42e8a830b54fa78ebb94e912288
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using BITKit.UX;
|
||||
using UnityEngine.Networking;
|
||||
namespace BITKit.UX.Components
|
||||
{
|
||||
[System.Serializable]
|
||||
public class QRBuilder : StringComponent
|
||||
{
|
||||
public TranslateSO so;
|
||||
public UXImage image;
|
||||
public InitializationState state;
|
||||
protected override async void OnSet(string value)
|
||||
{
|
||||
state = InitializationState.Initializing;
|
||||
var url = so.Get(value);
|
||||
using (var request = UnityWebRequestTexture.GetTexture(url))
|
||||
{
|
||||
Debug.Log(url);
|
||||
await request.SendWebRequest();
|
||||
BITApp.CancellationTokenSource.Token.ThrowIfCancellationRequested();
|
||||
if (request.result is UnityWebRequest.Result.Success)
|
||||
{
|
||||
var texture = DownloadHandlerTexture.GetContent(request);
|
||||
image.Set(texture);
|
||||
state = InitializationState.Initialized;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = InitializationState.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da98aa1707942e742850cd8995ba7d90
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,108 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine.Events;
|
||||
using BITKit.UX;
|
||||
namespace BITKit.UX.Components
|
||||
{
|
||||
public abstract class StringComponent : DataComponents
|
||||
{
|
||||
public override void OnStart()
|
||||
{
|
||||
Data.AddListener<string>(key, OnSet);
|
||||
}
|
||||
public override void OnStop()
|
||||
{
|
||||
Data.RemoveListender<string>(key, OnSet);
|
||||
}
|
||||
protected abstract void OnSet(string value);
|
||||
}
|
||||
[System.Serializable]
|
||||
public sealed class Text : StringComponent
|
||||
{
|
||||
public Provider output;
|
||||
protected override async void OnSet(string value)
|
||||
{
|
||||
await UniTask.SwitchToMainThread();
|
||||
output.Set(value);
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
public sealed class TranslateText : StringComponent
|
||||
{
|
||||
ITranslator translator;
|
||||
public Provider output;
|
||||
public TranslateSO so;
|
||||
public string source;
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
source = output.Get<string>();
|
||||
translator = DI.Get<ITranslator>();
|
||||
translator.OnChangeLanguage += OnTranslate;
|
||||
}
|
||||
protected override async void OnSet(string value)
|
||||
{
|
||||
source = value;
|
||||
value = so?.GetAt(value);
|
||||
await UniTask.SwitchToMainThread();
|
||||
output.Set(value);
|
||||
}
|
||||
public override void OnStop()
|
||||
{
|
||||
translator.OnChangeLanguage -= OnTranslate;
|
||||
}
|
||||
void OnTranslate(string langs)
|
||||
{
|
||||
OnSet(source);
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
public sealed class Event : StringComponent
|
||||
{
|
||||
public UnityEvent<string> output;
|
||||
protected override async void OnSet(string value)
|
||||
{
|
||||
await UniTask.SwitchToMainThread();
|
||||
output.Invoke(value);
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
public sealed class BoolEvent : DataComponents
|
||||
{
|
||||
public UnityEvent<bool> outputEvent;
|
||||
public UnityEvent ifTrueEvent;
|
||||
public UnityEvent ifFlaseEvent;
|
||||
public override void OnStart()
|
||||
{
|
||||
Data.AddListener<bool>(key, OnSetBool, true);
|
||||
}
|
||||
public override void OnStop()
|
||||
{
|
||||
Data.RemoveListender<bool>(key, OnSetBool);
|
||||
}
|
||||
async void OnSetBool(bool boolean)
|
||||
{
|
||||
try
|
||||
{
|
||||
await UniTask.SwitchToMainThread(BITApp.CancellationTokenSource.Token);
|
||||
outputEvent.Invoke(boolean);
|
||||
|
||||
if (boolean is true)
|
||||
ifTrueEvent.Invoke();
|
||||
else
|
||||
ifFlaseEvent.Invoke();
|
||||
}
|
||||
catch (System.OperationCanceledException)
|
||||
{
|
||||
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02604813db464e84496818ce0a5fdc93
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/UX/ContextMenu.meta
Normal file
8
Packages/Common~/Scripts/UX/ContextMenu.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96d295cd364701943a874f702f833ef0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
150
Packages/Common~/Scripts/UX/ContextMenu/UXContextMenu.cs
Normal file
150
Packages/Common~/Scripts/UX/ContextMenu/UXContextMenu.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Remoting.Contexts;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.InputSystem;
|
||||
using BITKit;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using Cysharp.Threading.Tasks;
|
||||
namespace BITKit.UX.Internal
|
||||
{
|
||||
public class ContextMenu : IContextMenu
|
||||
{
|
||||
public virtual VisualElement GetVisualElement()
|
||||
{
|
||||
return new VisualElement();
|
||||
}
|
||||
}
|
||||
public class Label : ContextMenu
|
||||
{
|
||||
public Label(string text)
|
||||
{
|
||||
this.text = text;
|
||||
}
|
||||
string text;
|
||||
public override VisualElement GetVisualElement()
|
||||
{
|
||||
UnityEngine.UIElements.Label label = new(text);
|
||||
return label;
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
public class TestContextMenu : IAction
|
||||
{
|
||||
public void Excute()
|
||||
{
|
||||
ContextMenuBuilder
|
||||
.Create()
|
||||
.BuildText("Tools")
|
||||
.BuildAction("Log", () => Debug.Log(nameof(ContextMenu)))
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
public class Button : ContextMenu
|
||||
{
|
||||
public Button(string text, params Action[] actions)
|
||||
{
|
||||
this.text = text;
|
||||
foreach (var x in actions)
|
||||
{
|
||||
action += x;
|
||||
}
|
||||
}
|
||||
string text;
|
||||
Action action;
|
||||
public override VisualElement GetVisualElement()
|
||||
{
|
||||
UnityEngine.UIElements.Button button = new();
|
||||
button.clicked += action;
|
||||
button.text = text;
|
||||
return button;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public interface IContextMenu
|
||||
{
|
||||
VisualElement GetVisualElement();
|
||||
}
|
||||
public static class ContextMenuBuilderExtensions
|
||||
{
|
||||
public static ContextMenuBuilder BuildText(this ContextMenuBuilder self, string text)
|
||||
{
|
||||
self.Add(new Internal.Label(text));
|
||||
return self;
|
||||
}
|
||||
public static ContextMenuBuilder BuildAction(this ContextMenuBuilder self, string text, Action action)
|
||||
{
|
||||
self.Add(new Internal.Button(text, action, self.Excute));
|
||||
return self;
|
||||
}
|
||||
}
|
||||
public class ContextMenuBuilder
|
||||
{
|
||||
readonly List<IContextMenu> contexts = new();
|
||||
public event Action OnExcuted;
|
||||
private ContextMenuBuilder()
|
||||
{
|
||||
|
||||
}
|
||||
public static ContextMenuBuilder Create()
|
||||
{
|
||||
return new();
|
||||
}
|
||||
public void Build()
|
||||
{
|
||||
UXContextMenu.Singleton.Create(this);
|
||||
}
|
||||
internal void Excute()
|
||||
{
|
||||
OnExcuted?.Invoke();
|
||||
}
|
||||
public void Add(IContextMenu x) => contexts.Add(x);
|
||||
public IEnumerable<IContextMenu> GetContextMenus() => contexts.ToArray();
|
||||
}
|
||||
public class UXContextMenu : MonoBehaviour
|
||||
{
|
||||
internal static UXContextMenu Singleton;
|
||||
[SerializeField] private UIDocument document;
|
||||
private VisualElement root;
|
||||
private VisualElement container;
|
||||
private void Awake()
|
||||
{
|
||||
Singleton = this;
|
||||
root = document.rootVisualElement;
|
||||
container = document.rootVisualElement[0];
|
||||
root.RegisterCallback<MouseDownEvent>(x =>
|
||||
{
|
||||
Close();
|
||||
});
|
||||
Close();
|
||||
}
|
||||
public void Create(ContextMenuBuilder builder)
|
||||
{
|
||||
var pos = Mouse.current.position.ReadValue();
|
||||
pos.y = Screen.height - pos.y;
|
||||
pos = RuntimePanelUtils.ScreenToPanel(root.panel, pos);
|
||||
|
||||
container.style.position = Position.Absolute;
|
||||
container.style.left = pos.x;
|
||||
container.style.top = pos.y;
|
||||
container.Clear();
|
||||
|
||||
root.SetActive(true);
|
||||
|
||||
foreach (var context in builder.GetContextMenus())
|
||||
{
|
||||
container.Add(context.GetVisualElement());
|
||||
}
|
||||
builder.OnExcuted += Close;
|
||||
}
|
||||
void Close()
|
||||
{
|
||||
container.Clear();
|
||||
root.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1325be4d8754c324e9a4942fba79db26
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/UX/Core.meta
Normal file
8
Packages/Common~/Scripts/UX/Core.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5dc34c310e0729b44a166514d03601b7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/UX/Core/Events.meta
Normal file
8
Packages/Common~/Scripts/UX/Core/Events.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0131c34f2a3d2547be0827e751e0e2a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
13
Packages/Common~/Scripts/UX/Core/Events/OnTranslateEvent.cs
Normal file
13
Packages/Common~/Scripts/UX/Core/Events/OnTranslateEvent.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using BITKit;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class OnTranslateEvent : EventBase<OnTranslateEvent>
|
||||
{
|
||||
public string source;
|
||||
public string text;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f42d4f8bbc73bc84587d0bbd9fc920a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
74
Packages/Common~/Scripts/UX/Core/UXBar.cs
Normal file
74
Packages/Common~/Scripts/UX/Core/UXBar.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXBar : UXElement<VisualElement>, IProvider<float>
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
public string fillElementName;
|
||||
public string labelName;
|
||||
[Header(Constant.Header.Output)]
|
||||
public Provider onValueChanged;
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
VisualElement fillElement;
|
||||
Label labelElement;
|
||||
public override void OnStart()
|
||||
{
|
||||
fillElement = visualElement.Q<VisualElement>(fillElementName);
|
||||
labelElement = visualElement.Q<Label>(labelName);
|
||||
if (visualElement is INotifyValueChanged<float> iNotify)
|
||||
{
|
||||
iNotify.RegisterValueChangedCallback(OnValueChanged);
|
||||
}
|
||||
}
|
||||
public void Set(int value)
|
||||
{
|
||||
float w = Mathf.Clamp((float)value / 100 * 100, 0f, 100f);
|
||||
Set(w);
|
||||
}
|
||||
public async void Set(float value)
|
||||
{
|
||||
try
|
||||
{
|
||||
await UniTask.SwitchToMainThread(gameObject.GetCancellationTokenOnDestroy());
|
||||
switch (visualElement)
|
||||
{
|
||||
case INotifyValueChanged<float> iNotify:
|
||||
iNotify.SetValueWithoutNotify(value);
|
||||
break;
|
||||
default:
|
||||
value *= 100;
|
||||
fillElement.style.width = new StyleLength(Length.Percent(value));
|
||||
break;
|
||||
}
|
||||
if (labelElement is not null)
|
||||
labelElement.text = value.ToString();
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
if (e is not OperationCanceledException)
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public async void SetDirect(float progess,string label)
|
||||
{
|
||||
await UniTask.SwitchToMainThread(gameObject.GetCancellationTokenOnDestroy());
|
||||
Set(progess);
|
||||
labelElement.text = label;
|
||||
}
|
||||
float IProvider<float>.Get()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
void OnValueChanged(ChangeEvent<float> changeEvent)
|
||||
{
|
||||
if(onValueChanged is not null)
|
||||
onValueChanged.Set(changeEvent.newValue);
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXBar.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXBar.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de67752b421e2a842b0407b2c6c524a9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
57
Packages/Common~/Scripts/UX/Core/UXButton.cs
Normal file
57
Packages/Common~/Scripts/UX/Core/UXButton.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Events;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXButton : UXElement<Button>
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
public bool allowRightClick;
|
||||
[Header(Constant.Header.Events)]
|
||||
public UnityEvent onClick = new();
|
||||
public UnityEvent onRightClick = new();
|
||||
public override void OnStart()
|
||||
{
|
||||
try
|
||||
{
|
||||
visualElement.clicked += Click;
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
if (allowRightClick)
|
||||
{
|
||||
foreach (var x in visualElement.Children())
|
||||
{
|
||||
x.pickingMode = PickingMode.Ignore;
|
||||
}
|
||||
visualElement.RegisterCallback<MouseDownEvent>(OnMouseDown);
|
||||
visualElement.RegisterCallback<MouseUpEvent>(OnMouseUp);
|
||||
}
|
||||
//visualElement.AddManipulator(new ContextualMenuManipulator(RightClick));
|
||||
}
|
||||
public override void Set(bool active)
|
||||
{
|
||||
base.Set(active);
|
||||
visualElement.SetEnabled(active);
|
||||
}
|
||||
void Click()
|
||||
{
|
||||
onClick.Invoke();
|
||||
}
|
||||
void OnMouseDown(MouseDownEvent mouseEvent)
|
||||
{
|
||||
if (mouseEvent.button is 1)
|
||||
{
|
||||
onRightClick.Invoke();
|
||||
}
|
||||
}
|
||||
void OnMouseUp(MouseUpEvent mouseEvent)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXButton.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXButton.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44e9dc9ae2389a74abe198bbd3f86c69
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
23
Packages/Common~/Scripts/UX/Core/UXConstant.cs
Normal file
23
Packages/Common~/Scripts/UX/Core/UXConstant.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.AddressableAssets;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXConstant
|
||||
{
|
||||
public const string TitleLabel = "title-label";
|
||||
public const string ContextLabel = "context-label";
|
||||
public const string NumberLabel = "number-label";
|
||||
public const string DescriptionLabel = "description-label";
|
||||
public const string ContextContainer = "context-container";
|
||||
public const string MainButton = "main-button";
|
||||
public const string SecButton = "sec-button";
|
||||
public const string MainImage = "main-image";
|
||||
public const string ContextImage = "context-image";
|
||||
public const string Icon = "icon-image";
|
||||
public const string ContextListView = "context-listview";
|
||||
public const string Inspector = "inspector-container";
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXConstant.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXConstant.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2632a26b74a00eb47924d9df4e5e4a93
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
30
Packages/Common~/Scripts/UX/Core/UXContainer.cs
Normal file
30
Packages/Common~/Scripts/UX/Core/UXContainer.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXContainer
|
||||
{
|
||||
public static implicit operator VisualElement(UXContainer self) => self.visualElement;
|
||||
public Label contextlabel;
|
||||
public Label titleLabel;
|
||||
public Label descriptionLabel;
|
||||
public Label numberLabel;
|
||||
public Button button;
|
||||
public Button secButton;
|
||||
public VisualElement visualElement;
|
||||
public VisualElement icon;
|
||||
public UXContainer(VisualElement visualElement)
|
||||
{
|
||||
this.visualElement = visualElement;
|
||||
contextlabel = visualElement.Q<Label>(UXConstant.ContextLabel);
|
||||
titleLabel = visualElement.Q<Label>(UXConstant.TitleLabel);
|
||||
numberLabel = visualElement.Q<Label>(UXConstant.TitleLabel);
|
||||
descriptionLabel = visualElement.Q<Label>(UXConstant.DescriptionLabel);
|
||||
button = visualElement.Q<Button>(UXConstant.MainButton);
|
||||
secButton = visualElement.Q<Button>(UXConstant.SecButton);
|
||||
icon = visualElement.Q(UXConstant.Icon);
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXContainer.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXContainer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93fe1a2d311a583478feae7af24a8a59
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
63
Packages/Common~/Scripts/UX/Core/UXDrag.cs
Normal file
63
Packages/Common~/Scripts/UX/Core/UXDrag.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXDrag : UXElement<VisualElement>
|
||||
{
|
||||
Vector3 m_IconStartPosition;
|
||||
Vector3 m_PointerStartPosition;
|
||||
bool isDraging;
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
// listen for LMB down
|
||||
visualElement.RegisterCallback<PointerDownEvent>(PointerDownEventHandler);
|
||||
|
||||
// listen for mouse movement and LMB up
|
||||
visualElement.RegisterCallback<PointerMoveEvent>(PointerMoveEventHandler);
|
||||
visualElement.RegisterCallback<PointerUpEvent>(PointerUpEventHandler);
|
||||
}
|
||||
protected virtual void PointerMoveEventHandler(PointerMoveEvent evt)
|
||||
{
|
||||
if (isDraging && visualElement.HasPointerCapture(evt.pointerId))
|
||||
{
|
||||
float newX = m_IconStartPosition.x + (evt.position.x - m_PointerStartPosition.x);
|
||||
float newY = m_IconStartPosition.y + (evt.position.y - m_PointerStartPosition.y);
|
||||
|
||||
var delta = new Vector2(newX, newY);
|
||||
delta = GetProcessDelta(delta);
|
||||
visualElement.transform.position = delta;
|
||||
OnDelta(delta);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void PointerDownEventHandler(PointerDownEvent evt)
|
||||
{
|
||||
// set the icon and pointer starting positions
|
||||
m_IconStartPosition = visualElement.transform.position;
|
||||
m_PointerStartPosition = evt.position;
|
||||
|
||||
visualElement.CapturePointer(evt.pointerId);
|
||||
|
||||
isDraging = true;
|
||||
}
|
||||
|
||||
protected virtual void PointerUpEventHandler(PointerUpEvent evt)
|
||||
{
|
||||
isDraging = false;
|
||||
|
||||
visualElement.ReleasePointer(evt.pointerId);
|
||||
}
|
||||
|
||||
protected virtual Vector2 GetProcessDelta(Vector2 delta)
|
||||
{
|
||||
return delta;
|
||||
}
|
||||
protected virtual void OnDelta(Vector2 delta)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXDrag.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXDrag.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67edb976a23915f448217677f217dc49
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
21
Packages/Common~/Scripts/UX/Core/UXDropdown.cs
Normal file
21
Packages/Common~/Scripts/UX/Core/UXDropdown.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Events;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXDropdown : UXElement<DropdownField>
|
||||
{
|
||||
public UnityEvent<string> onSet = new();
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
visualElement.RegisterValueChangedCallback(x =>
|
||||
{
|
||||
onSet.Invoke(x.newValue);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXDropdown.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXDropdown.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7865b020e8dddd5428fa39b34bed9eed
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
169
Packages/Common~/Scripts/UX/Core/UXElement.cs
Normal file
169
Packages/Common~/Scripts/UX/Core/UXElement.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Events;
|
||||
using Sirenix.OdinInspector;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Threading;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public abstract class UXElement : Provider, IProvider<bool>, IActivable, IEnabled
|
||||
{
|
||||
protected bool isActive = true;
|
||||
public virtual bool Get() => isActive;
|
||||
public virtual void Set(bool active) { }
|
||||
public virtual void OnStart() { }
|
||||
public override void Set<T>(T obj)
|
||||
{
|
||||
(this as IProvider<T>).Set(obj);
|
||||
}
|
||||
public virtual void SetActive(bool active)
|
||||
{
|
||||
GetVisualElement().SetActive(active);
|
||||
}
|
||||
|
||||
public virtual void SetPosition(Vector3 worldPosition)
|
||||
{
|
||||
if (Camera.main != null)
|
||||
{
|
||||
var cameraTrans = Camera.main.transform;
|
||||
var visualElement = GetVisualElement();
|
||||
var pos = RuntimePanelUtils
|
||||
.CameraTransformWorldToPanel(visualElement.panel, worldPosition, Camera.main);
|
||||
pos.x = (pos.x - visualElement.layout.width / 2);
|
||||
|
||||
Rect elementRect = new()
|
||||
{
|
||||
position = pos,
|
||||
size = visualElement.layout.size,
|
||||
};
|
||||
|
||||
visualElement.style.left = 0;
|
||||
visualElement.style.top = 0;
|
||||
visualElement.style.position = Position.Absolute;
|
||||
visualElement.transform.position = pos;
|
||||
visualElement.SetOpacity(Vector3.Dot(cameraTrans.forward, worldPosition - cameraTrans.position) > 0 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
public virtual VisualElement GetVisualElement() => null;
|
||||
|
||||
public virtual bool IsEnabled()
|
||||
{
|
||||
return GetVisualElement().enabledSelf;
|
||||
}
|
||||
public virtual void SetEnabled(bool enabled)
|
||||
{
|
||||
GetVisualElement().SetEnabled(enabled);
|
||||
}
|
||||
}
|
||||
public abstract class UXElement<UX> : UXElement, IProvider<UX> where UX : VisualElement
|
||||
{
|
||||
public static implicit operator UX(UXElement<UX> self)
|
||||
{
|
||||
return self.visualElement;
|
||||
}
|
||||
[Header(Constant.Header.Components)]
|
||||
public UIDocument document;
|
||||
[Header(Constant.Header.Settings)]
|
||||
public string bindName;
|
||||
[SerializeField, SerializeReference, SubclassSelector]
|
||||
IReference bindNameProvider = new GetNameFromGameobject();
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
private UX m_visualElement;
|
||||
protected IStyle style => visualElement.style;
|
||||
public UX visualElement
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_visualElement is null)
|
||||
{
|
||||
var bindName = this.bindName;
|
||||
if (string.IsNullOrEmpty(bindName))
|
||||
{
|
||||
bindName = bindNameProvider.Get();
|
||||
}
|
||||
var split = bindName.Split(@".");
|
||||
var visualElement = document.rootVisualElement;
|
||||
foreach (var name in split)
|
||||
{
|
||||
try
|
||||
{
|
||||
visualElement = visualElement.Q(name);
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
Debug.LogWarning(name);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
m_visualElement = visualElement as UX;
|
||||
|
||||
if (m_visualElement is null)
|
||||
{
|
||||
Debug.LogWarning(bindName);
|
||||
}
|
||||
}
|
||||
return m_visualElement;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Get() => isActive;
|
||||
public override VisualElement GetVisualElement() => visualElement;
|
||||
protected CancellationToken cancellationToken;
|
||||
public override async void Set(bool active)
|
||||
{
|
||||
await UniTask.SwitchToMainThread(cancellationToken);
|
||||
visualElement.SetEnabled(active);
|
||||
if (active != isActive)
|
||||
{
|
||||
isActive = active;
|
||||
visualElement.SetEnabled(active);
|
||||
}
|
||||
}
|
||||
void Awake()
|
||||
{
|
||||
cancellationToken = gameObject.GetCancellationTokenOnDestroy();
|
||||
OnStart();
|
||||
}
|
||||
void OnValidate()
|
||||
{
|
||||
if (bindNameProvider is GetNameFromGameobject x)
|
||||
{
|
||||
x.gameobject = gameObject;
|
||||
}
|
||||
if (document is null)
|
||||
{
|
||||
document = GetComponentInParent<UIDocument>();
|
||||
}
|
||||
}
|
||||
UX IProvider<UX>.Get() => visualElement;
|
||||
public override T Get<T>()
|
||||
{
|
||||
if (visualElement is T t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
return base.Get<T>();
|
||||
}
|
||||
public void Set(UX t)
|
||||
{
|
||||
var root = visualElement.parent;
|
||||
root.Remove(visualElement);
|
||||
root.Add(t);
|
||||
m_visualElement = t;
|
||||
}
|
||||
protected virtual void OnVistualElementDisabled()
|
||||
{
|
||||
|
||||
}
|
||||
public void AddToClassList(string className)
|
||||
{
|
||||
visualElement.AddToClassList(className);
|
||||
}
|
||||
public void RemoveFromClassList(string className)
|
||||
{
|
||||
visualElement.RemoveFromClassList(className);
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXElement.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXElement.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2bff39fa929acdc469b6c427f7a94687
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
39
Packages/Common~/Scripts/UX/Core/UXFactory.cs
Normal file
39
Packages/Common~/Scripts/UX/Core/UXFactory.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXFactory : MonoBehaviour
|
||||
{
|
||||
[Header(Constant.Header.Components)]
|
||||
public UIDocument document;
|
||||
[Header(Constant.Header.Settings)]
|
||||
public string containerName;
|
||||
[Header(Constant.Header.Prefabs)]
|
||||
public VisualTreeAsset template;
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
VisualElement container;
|
||||
void Awake()
|
||||
{
|
||||
container = document.rootVisualElement.Q(containerName);
|
||||
}
|
||||
public UXContainer Create()
|
||||
{
|
||||
return new UXContainer(Create<VisualElement>());
|
||||
}
|
||||
public T Create<T>() where T : VisualElement
|
||||
{
|
||||
var x = template.CloneTree().Q<T>();
|
||||
container.Add(x);
|
||||
return x;
|
||||
}
|
||||
public void Remove(VisualElement element)
|
||||
{
|
||||
container.Remove(element);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXFactory.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXFactory.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3bfe3d409a675d4c94d1b1ad9897877
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
118
Packages/Common~/Scripts/UX/Core/UXFramework.cs
Normal file
118
Packages/Common~/Scripts/UX/Core/UXFramework.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Events;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXFramework : MonoBehaviour
|
||||
{
|
||||
public static Dictionary<string, UXPanel> panels = new();
|
||||
public static Stack<UXPanel> stacks = new();
|
||||
static UXFramework singleton;
|
||||
static UXPanel current;
|
||||
public static void Enter(string name)
|
||||
{
|
||||
if (panels.TryGetValue(name, out var panel))
|
||||
{
|
||||
Enter(panel);
|
||||
}
|
||||
}
|
||||
public static void Enter<T>()
|
||||
{
|
||||
Enter(typeof(T).Name);
|
||||
}
|
||||
public static void Enter(UXPanel panel)
|
||||
{
|
||||
if (current == panel) return;
|
||||
if (panel.isAdditive is false)
|
||||
{
|
||||
current?.Set(false);
|
||||
stacks.Push(panel);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
panel.Set(true);
|
||||
|
||||
current = panel;
|
||||
|
||||
singleton.history.Add(panel.name);
|
||||
|
||||
BITAppForUnity.AllowCursor.SetElements(singleton, panel.cursor);
|
||||
BITInputSystem.AllowInput.SetElements(singleton, panel.allowInput);
|
||||
}
|
||||
public static void Return()
|
||||
{
|
||||
if (stacks.TryPop(out var panel))
|
||||
{
|
||||
if (panel == current)
|
||||
{
|
||||
stacks.TryPop(out panel);
|
||||
}
|
||||
Enter(panel);
|
||||
}
|
||||
}
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
static void Reload()
|
||||
{
|
||||
panels.Clear();
|
||||
stacks.Clear();
|
||||
current = null;
|
||||
}
|
||||
[Header(Constant.Header.Settings)]
|
||||
public bool dontDestroyOnLoad;
|
||||
public UXPanel startPanel;
|
||||
public List<string> history = new();
|
||||
void Awake()
|
||||
{
|
||||
if (singleton is null)
|
||||
{
|
||||
singleton = this;
|
||||
if (dontDestroyOnLoad)
|
||||
{
|
||||
GameObject.DontDestroyOnLoad(gameObject);
|
||||
gameObject.transform.parent = BITAppForUnity.GameObject.transform;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
if (singleton == this)
|
||||
{
|
||||
singleton = null;
|
||||
foreach (var x in panels)
|
||||
{
|
||||
x.Value.OnDestroyComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
GetComponentsInChildren<UXPanel>(true).ForEach(x =>
|
||||
{
|
||||
var uxPanelType = typeof(UXPanel);
|
||||
var name = uxPanelType == x.GetType() ? x.gameObject.name : x.GetType().Name;
|
||||
panels.TryAdd(name, x);
|
||||
});
|
||||
foreach (var x in panels)
|
||||
{
|
||||
x.Value.OnStart();
|
||||
x.Value.Set(false);
|
||||
}
|
||||
//await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(startDelay),gameObject.GetCancellationTokenOnDestroy());
|
||||
if (startPanel)
|
||||
{
|
||||
Enter(startPanel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXFramework.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXFramework.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6dce5b2d366433a479765a57ffb2fb17
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
33
Packages/Common~/Scripts/UX/Core/UXImage.cs
Normal file
33
Packages/Common~/Scripts/UX/Core/UXImage.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Events;
|
||||
using Sirenix.OdinInspector;
|
||||
using Cysharp.Threading.Tasks;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXImage : UXElement<VisualElement>
|
||||
{
|
||||
private VisualElement icon;
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
icon = GetVisualElement().Q(UXConstant.Icon);
|
||||
}
|
||||
public async void Set(Sprite sprite)
|
||||
{
|
||||
await UniTask.SwitchToMainThread();
|
||||
var _icon = this.icon ?? visualElement;
|
||||
_icon.style.backgroundImage =sprite? new StyleBackground(sprite):null;
|
||||
}
|
||||
public async void Set(Texture2D texture)
|
||||
{
|
||||
await UniTask.SwitchToMainThread();
|
||||
var _icon = this.icon ?? visualElement;
|
||||
_icon.style.backgroundImage =texture? new StyleBackground(texture):null;
|
||||
}
|
||||
public void SetSprite(Sprite sprite) => Set(sprite);
|
||||
public void SetTexture(Texture2D texture2D) => Set(texture2D);
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXImage.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXImage.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0864e489ffa52240821dff61c1e5f5c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
50
Packages/Common~/Scripts/UX/Core/UXLabel.cs
Normal file
50
Packages/Common~/Scripts/UX/Core/UXLabel.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Events;
|
||||
using Sirenix.OdinInspector;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXLabel : UXElement<Label>, IProvider<string>
|
||||
{
|
||||
const string keyword = "{x}";
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeReference, SubclassSelector] public References format;
|
||||
public override T Get<T>()
|
||||
{
|
||||
if (typeof(T) == typeof(string))
|
||||
{
|
||||
if (visualElement.text is T t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return base.Get<T>();
|
||||
}
|
||||
public async void Set(string t)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (format is not null)
|
||||
{
|
||||
t = format.Get().Replace(keyword, t);
|
||||
}
|
||||
await UniTask.SwitchToMainThread(cancellationToken);
|
||||
visualElement.text = t;
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
if (e is not OperationCanceledException)
|
||||
throw;
|
||||
}
|
||||
}
|
||||
string IProvider<string>.Get()
|
||||
{
|
||||
UniTask.SwitchToMainThread();
|
||||
return visualElement.text;
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXLabel.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXLabel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b0261cd9eafc784c9d4cc6a24ea6886
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
58
Packages/Common~/Scripts/UX/Core/UXMeshRenderer.cs
Normal file
58
Packages/Common~/Scripts/UX/Core/UXMeshRenderer.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using BITKit.SubSystems;
|
||||
using UnityEngine.UIElements;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
#endif
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXMeshRenderer : UXElement<VisualElement>
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
public Transform model;
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
|
||||
CreateTexture();
|
||||
}
|
||||
public async void CreateTexture()
|
||||
{
|
||||
//visualElement.style.backgroundImage = new(Background.FromTexture2D(texture));
|
||||
visualElement.style.backgroundImage = new(await MeshRendering.Create(model));
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
//[CustomEditor(typeof(UXMeshRenderer))]
|
||||
public class UXMeshRendererInspector : BITInspector<UXMeshRenderer>
|
||||
{
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
CreateSubTitle(Constant.Header.Gameobjects);
|
||||
var document = root.Create<PropertyField>();
|
||||
CreateSubTitle(Constant.Header.Settings);
|
||||
var model = root.Create<PropertyField>();
|
||||
var button = root.Create<Button>();
|
||||
|
||||
model.BindProperty(serializedObject.FindProperty(nameof(UXMeshRenderer.model)));
|
||||
|
||||
button.text = "Create";
|
||||
button.clicked += () =>
|
||||
{
|
||||
if (EditorApplication.isPlaying)
|
||||
{
|
||||
agent.CreateTexture();
|
||||
}
|
||||
};
|
||||
return root;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXMeshRenderer.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXMeshRenderer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 063753040cae4134ea252f4e958fb896
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
73
Packages/Common~/Scripts/UX/Core/UXPanel.cs
Normal file
73
Packages/Common~/Scripts/UX/Core/UXPanel.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Events;
|
||||
using Sirenix.OdinInspector;
|
||||
using Cursor = UnityEngine.Cursor;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public interface IPanelComponent : IActivable
|
||||
{
|
||||
}
|
||||
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)]
|
||||
IPanelComponent[] components;
|
||||
public override void OnStart()
|
||||
{
|
||||
components = GetComponentsInChildren<IPanelComponent>(true);
|
||||
document.enabled = true;
|
||||
base.OnStart();
|
||||
}
|
||||
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
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXPanel.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXPanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d682bd06112d7b34bbdda9f77df8d91e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
32
Packages/Common~/Scripts/UX/Core/UXRadioButtonGroup.cs
Normal file
32
Packages/Common~/Scripts/UX/Core/UXRadioButtonGroup.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Events;
|
||||
using System.Linq;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXRadioButtonGroup : UXElement<RadioButtonGroup>
|
||||
{
|
||||
[Header(Constant.Header.Events)]
|
||||
public UnityEvent<int> onSelectedIndex = new();
|
||||
public UnityEvent<string> onSelectedValue = new();
|
||||
public void Set(List<string> list)
|
||||
{
|
||||
visualElement.choices = list;
|
||||
visualElement.SetValueWithoutNotify(0);
|
||||
}
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
visualElement.RegisterValueChangedCallback(OnSelected);
|
||||
}
|
||||
void OnSelected(ChangeEvent<int> indexEvent)
|
||||
{
|
||||
var list = visualElement.choices;
|
||||
var value = list.ElementAt(indexEvent.newValue);
|
||||
onSelectedIndex.Invoke(indexEvent.newValue);
|
||||
onSelectedValue.Invoke(value);
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXRadioButtonGroup.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXRadioButtonGroup.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c7a179eaf6526e4caa6ba6b25e1ac69
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
15
Packages/Common~/Scripts/UX/Core/UXScrollView.cs
Normal file
15
Packages/Common~/Scripts/UX/Core/UXScrollView.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Events;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXScrollView : UXElement<ScrollView>
|
||||
{
|
||||
public void ScrollToTop()
|
||||
{
|
||||
visualElement.verticalScroller.value = 0;
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXScrollView.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXScrollView.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41945c65d2dba67408496e46d3380ec5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
39
Packages/Common~/Scripts/UX/Core/UXSlider.cs
Normal file
39
Packages/Common~/Scripts/UX/Core/UXSlider.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UIElements;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXSlider : UXElement<Slider>, IProvider<float>
|
||||
{
|
||||
public UnityEvent<float> onSetValue = new();
|
||||
public Provider outputValue;
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
visualElement.RegisterValueChangedCallback(x =>
|
||||
{
|
||||
onSetValue.Invoke(x.newValue);
|
||||
outputValue?.Set(x.newValue);
|
||||
});
|
||||
}
|
||||
float IProvider<float>.Get()
|
||||
{
|
||||
return visualElement.value;
|
||||
}
|
||||
void IProvider<float>.Set(float t)
|
||||
{
|
||||
SetValue(t);
|
||||
}
|
||||
public void SetValue(float t)
|
||||
{
|
||||
visualElement.SetValueWithoutNotify(t);
|
||||
}
|
||||
public void SetNormalizeValue(float t)
|
||||
{
|
||||
var value = Mathf.Lerp(visualElement.lowValue, visualElement.highValue, t);
|
||||
visualElement.SetValueWithoutNotify(value);
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXSlider.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXSlider.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 46e997f0c93001e47882c2d37f073e8a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/UX/Core/UXSubPanel.cs
Normal file
8
Packages/Common~/Scripts/UX/Core/UXSubPanel.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXSubPanel.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXSubPanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5990e59ee6edcc8409ba1612514f17f9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
101
Packages/Common~/Scripts/UX/Core/UXTable.cs
Normal file
101
Packages/Common~/Scripts/UX/Core/UXTable.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXTable : UXElement<VisualElement>, IProvider<DataTable>
|
||||
{
|
||||
public int createTableTimes = 0;
|
||||
Label[,] labelTable = new Label[0, 0];
|
||||
public new DataTable Get()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public async void Set(DataTable t)
|
||||
{
|
||||
try
|
||||
{
|
||||
await UniTask.SwitchToMainThread(cancellationToken);
|
||||
if (labelTable.GetLength(0) != t.Rows.Count)
|
||||
{
|
||||
CreateDataTable();
|
||||
}
|
||||
t.Rows.Count.ForEach(row =>
|
||||
{
|
||||
t.Columns.Count.ForEach(col =>
|
||||
{
|
||||
var value = t.Rows[row][col] as string;
|
||||
var label = labelTable[row, col];
|
||||
label.text = value;
|
||||
});
|
||||
});
|
||||
t.Dispose();
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
if (e is OperationCanceledException)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
void CreateDataTable()
|
||||
{
|
||||
var width = visualElement.layout.width / t.Columns.Count;
|
||||
int rowCount = 0;
|
||||
int colCount = 0;
|
||||
|
||||
visualElement.Clear();
|
||||
visualElement.style.flexDirection = new(FlexDirection.Column);
|
||||
|
||||
labelTable = new Label[t.Rows.Count, t.Columns.Count];
|
||||
|
||||
foreach (DataRow row in t.Rows)
|
||||
{
|
||||
VisualElement element = new();
|
||||
var style = element.style;
|
||||
style.flexDirection = FlexDirection.Row;
|
||||
SetUpStyle(element.style);
|
||||
|
||||
colCount = 0;
|
||||
|
||||
foreach (DataColumn col in t.Columns)
|
||||
{
|
||||
var value = row[col];
|
||||
var label = new Label(value?.ToString());
|
||||
//label.style.width = width;
|
||||
SetUpStyle(label.style);
|
||||
element.Add(label);
|
||||
|
||||
labelTable[rowCount, colCount] = label;
|
||||
|
||||
colCount++;
|
||||
}
|
||||
rowCount++;
|
||||
|
||||
visualElement.Add(element);
|
||||
}
|
||||
createTableTimes++;
|
||||
}
|
||||
}
|
||||
void SetUpStyle(IStyle style)
|
||||
{
|
||||
style.marginTop = 0;
|
||||
style.marginLeft = 0;
|
||||
style.marginRight = 0;
|
||||
style.marginBottom = 0;
|
||||
style.paddingTop = 0;
|
||||
style.paddingLeft = 0;
|
||||
style.paddingRight = 0;
|
||||
style.paddingBottom = 0;
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXTable.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXTable.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f56df63313ab5eb46a795d059ed753aa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
40
Packages/Common~/Scripts/UX/Core/UXTextField.cs
Normal file
40
Packages/Common~/Scripts/UX/Core/UXTextField.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Events;
|
||||
using Cysharp.Threading.Tasks;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXTextField : UXElement<TextField>, IProvider<string>
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
public TranslateSO translateSO;
|
||||
[Header(Constant.Header.Events)]
|
||||
public UnityEvent<string> onValueChanged = new();
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
visualElement.RegisterValueChangedCallback(OnValueChanged);
|
||||
}
|
||||
public async void Set(string t)
|
||||
{
|
||||
if (translateSO)
|
||||
{
|
||||
t = translateSO.GetAt(t);
|
||||
}
|
||||
await UniTask.SwitchToMainThread(cancellationToken);
|
||||
visualElement.value = t;
|
||||
}
|
||||
string IProvider<string>.Get()
|
||||
{
|
||||
return visualElement.value;
|
||||
}
|
||||
|
||||
void OnValueChanged(ChangeEvent<string> changeEvent)
|
||||
{
|
||||
onValueChanged.Invoke(changeEvent.newValue);
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXTextField.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXTextField.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 506b820ddfecc7f42b1e74466744e00a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
40
Packages/Common~/Scripts/UX/Core/UXToggle.cs
Normal file
40
Packages/Common~/Scripts/UX/Core/UXToggle.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Events;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXToggle : UXElement<Toggle>
|
||||
{
|
||||
[Header(Constant.Header.Events)]
|
||||
public UnityEvent<bool> onToggle = new();
|
||||
public UnityEvent onChecked = new();
|
||||
public UnityEvent onDecheck = new();
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
visualElement.RegisterValueChangedCallback(x =>
|
||||
{
|
||||
onToggle.Invoke(x.newValue);
|
||||
if (x.newValue)
|
||||
{
|
||||
onChecked.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
onDecheck.Invoke();
|
||||
}
|
||||
});
|
||||
}
|
||||
public override bool Get()
|
||||
{
|
||||
return visualElement.value;
|
||||
}
|
||||
public override void Set(bool active)
|
||||
{
|
||||
onToggle.Invoke(active);
|
||||
visualElement.SetValueWithoutNotify(active);
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXToggle.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXToggle.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85a128d5fb005d148ba05870043218a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/UX/Core/UXUtils.cs
Normal file
8
Packages/Common~/Scripts/UX/Core/UXUtils.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXUtils.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXUtils.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f54503955f24a24d8dddbda57126147
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
39
Packages/Common~/Scripts/UX/Core/UXWindow.cs
Normal file
39
Packages/Common~/Scripts/UX/Core/UXWindow.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Events;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public interface IWindowComponent : IActivable { }
|
||||
public class UXWindow : UXElement<VisualElement>
|
||||
{
|
||||
IWindowComponent[] components;
|
||||
public override void Set(bool active)
|
||||
{
|
||||
try
|
||||
{
|
||||
visualElement.style.display = (active) ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
BIT4Log.Warnning(gameObject);
|
||||
throw;
|
||||
}
|
||||
foreach (var x in components)
|
||||
{
|
||||
x.SetActive(active);
|
||||
}
|
||||
}
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
components = GetComponentsInChildren<IWindowComponent>(true);
|
||||
|
||||
if(visualElement is null)
|
||||
{
|
||||
Debug.Log($"{transform.name} bind failure");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXWindow.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXWindow.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ffaa722a0db415c4c8f60706afb4ad0b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
219
Packages/Common~/Scripts/UX/Core/UXWindowManager.cs
Normal file
219
Packages/Common~/Scripts/UX/Core/UXWindowManager.cs
Normal file
@@ -0,0 +1,219 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Events;
|
||||
using Sirenix.OdinInspector;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public interface IWindowElement
|
||||
{
|
||||
string GetName();
|
||||
UXElement Navigation { get; }
|
||||
UXElement Window { get; }
|
||||
UXWindowManager SubWindowManager { get; }
|
||||
Task Open(CancellationToken cancellationToken = default);
|
||||
Task Close(CancellationToken cancellationToken = default);
|
||||
}
|
||||
[System.Serializable]
|
||||
public class UXWindowElement : IWindowElement
|
||||
{
|
||||
[SerializeField]
|
||||
protected string name;
|
||||
[SerializeField]
|
||||
protected UXElement navigation;
|
||||
[SerializeField]
|
||||
protected UXElement window;
|
||||
[SerializeField]
|
||||
protected UXWindowManager subWindowManager;
|
||||
[SerializeField]
|
||||
protected bool enabled;
|
||||
public UXElement Navigation => navigation;
|
||||
public UXElement Window => window;
|
||||
public UXWindowManager SubWindowManager => subWindowManager;
|
||||
public async Task Close(CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await UniTask.SwitchToMainThread(cancellationToken);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
await UniTask.Yield();
|
||||
try
|
||||
{
|
||||
navigation.GetVisualElement().SetEnabled(true);
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
Debug.LogWarning($"Navgation:{name} 已丢失");
|
||||
throw;
|
||||
}
|
||||
try
|
||||
{
|
||||
window.Set(false);
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
Debug.LogWarning($"Window:{name} 已丢失");
|
||||
throw;
|
||||
}
|
||||
enabled = false;
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
Debug.LogWarning(name);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Open(CancellationToken cancellationToken = default)
|
||||
{
|
||||
await UniTask.SwitchToMainThread(cancellationToken);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
navigation.GetVisualElement().SetEnabled(false);
|
||||
window.Set(true);
|
||||
enabled = true;
|
||||
}
|
||||
public string GetName() => name;
|
||||
|
||||
|
||||
}
|
||||
public class UXWindowManager : MonoBehaviour, INextble
|
||||
{
|
||||
public enum WindowState
|
||||
{
|
||||
None,
|
||||
Flex,
|
||||
Hidden
|
||||
}
|
||||
[Header(Constant.Header.Components)]
|
||||
[SerializeReference, SubclassSelector] public List<IWindowElement> windows = new();
|
||||
public UXWindowManager subWindowManager;
|
||||
[Header(Constant.Header.Settings)]
|
||||
public UXElement startElement;
|
||||
[SerializeField] bool hidden;
|
||||
[Header(Constant.Header.Events)]
|
||||
public UnityEvent<string> OnEntry = new();
|
||||
public UnityEvent<string> OnExit = new();
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
List<IWindowElement> activeWindows = new();
|
||||
IWindowElement activeWindow;
|
||||
public int index { get; private set; }
|
||||
CancellationTokenSource cts;
|
||||
public async void Select(UXElement element)
|
||||
{
|
||||
cts.Cancel();
|
||||
cts = new();
|
||||
foreach (var activeWindow in activeWindows)
|
||||
{
|
||||
await activeWindow.Close(cts.Token);
|
||||
OnExit.Invoke(activeWindow.GetName());
|
||||
|
||||
}
|
||||
|
||||
activeWindows.Clear();
|
||||
var window = windows
|
||||
.Find(x => x.GetName() == element.name || x.Navigation == element || x.Window == element);
|
||||
index = windows.IndexOf(window);
|
||||
activeWindows.Add(window);
|
||||
activeWindow = window;
|
||||
// currentWindow = window;
|
||||
try
|
||||
{
|
||||
await window.Open();
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
Debug.LogWarning(name);
|
||||
if (window is null)
|
||||
{
|
||||
Debug.Log("Window is Null");
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
||||
OnEntry.Invoke(window.GetName());
|
||||
}
|
||||
public bool Next()
|
||||
{
|
||||
if (activeWindow is not null && activeWindow.SubWindowManager)
|
||||
{
|
||||
if (activeWindow.SubWindowManager.Next())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (windows.Count > index + 1)
|
||||
{
|
||||
var element = windows[index + 1].Navigation;
|
||||
Select(element);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Previous()
|
||||
{
|
||||
if (activeWindow is not null && activeWindow.SubWindowManager)
|
||||
{
|
||||
if (activeWindow.SubWindowManager.Previous())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (index - 1 >= 0)
|
||||
{
|
||||
var element = windows[index - 1].Navigation;
|
||||
Select(element);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool Hidden
|
||||
{
|
||||
get => hidden;
|
||||
set
|
||||
{
|
||||
if (hidden)
|
||||
{
|
||||
Exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
Recovery();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Exit()
|
||||
{
|
||||
hidden = true;
|
||||
activeWindow?.Close();
|
||||
}
|
||||
public void Recovery()
|
||||
{
|
||||
hidden = false;
|
||||
activeWindow?.Open();
|
||||
}
|
||||
void Awake()
|
||||
{
|
||||
cts = new();
|
||||
var ct = gameObject.GetCancellationTokenOnDestroy();
|
||||
ct.Register(cts.Cancel);
|
||||
}
|
||||
async void Start()
|
||||
{
|
||||
await UniTask.Yield();
|
||||
foreach (var window in windows)
|
||||
{
|
||||
await window.Close(cts.Token);
|
||||
}
|
||||
Select(startElement);
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Core/UXWindowManager.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Core/UXWindowManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b49fab83196ab64b837f4916eb66fd0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/UX/Debug.meta
Normal file
8
Packages/Common~/Scripts/UX/Debug.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9dc4856af36fd6440a4ace72cd372ef2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
16
Packages/Common~/Scripts/UX/Debug/DebugUXElement.cs
Normal file
16
Packages/Common~/Scripts/UX/Debug/DebugUXElement.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Sirenix.OdinInspector;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class DebugUXElement : SerializedMonoBehaviour
|
||||
{
|
||||
public UXElement element;
|
||||
[Button]
|
||||
public void SetActive(bool active)
|
||||
{
|
||||
element.Set(active);
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Debug/DebugUXElement.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Debug/DebugUXElement.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c2ce5e9f3121c843a9964fcd7129540
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/UX/Debuger.meta
Normal file
8
Packages/Common~/Scripts/UX/Debuger.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3905025ed51a3a64b97f041df86f78ac
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
60
Packages/Common~/Scripts/UX/Debuger/UXDebuger.cs
Normal file
60
Packages/Common~/Scripts/UX/Debuger/UXDebuger.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using UnityEngine.UIElements;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Linq;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public sealed class UXDebuger : UXElement<ListView>, IDebuger
|
||||
{
|
||||
List<string> texts = new();
|
||||
Dictionary<string, string> textDict = new();
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
visualElement.itemsSource = texts;
|
||||
visualElement.makeItem = MakeItem;
|
||||
visualElement.bindItem = BindItem;
|
||||
}
|
||||
public void Log(string context)
|
||||
{
|
||||
texts.Add(context);
|
||||
}
|
||||
public async void Log(string title, string context)
|
||||
{
|
||||
//await UniTask.SwitchToThreadPool();
|
||||
textDict.Insert(title, context);
|
||||
texts.Clear();
|
||||
texts.AddRange(textDict.Select(x => $"{x.Key}:{x.Value}"));
|
||||
try
|
||||
{
|
||||
await UniTask.SwitchToMainThread(BITApp.CancellationTokenSource.Token);
|
||||
}
|
||||
catch (System.OperationCanceledException)
|
||||
{
|
||||
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
VisualElement MakeItem()
|
||||
{
|
||||
return new Label();
|
||||
}
|
||||
void BindItem(VisualElement element, int index)
|
||||
{
|
||||
var label = element as Label;
|
||||
label.text = texts[index];
|
||||
}
|
||||
void Awake()
|
||||
{
|
||||
DI.Register<IDebuger>(this);
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Debuger/UXDebuger.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Debuger/UXDebuger.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5a22846b573d5c4685160aed721d514
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/UX/Input.meta
Normal file
8
Packages/Common~/Scripts/UX/Input.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2438aa030d480c43b8394e57aa93fc4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
22
Packages/Common~/Scripts/UX/Input/BITKit.UX.OnScreen.asmdef
Normal file
22
Packages/Common~/Scripts/UX/Input/BITKit.UX.OnScreen.asmdef
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "BITKit.UX.OnScreen",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:a209c53514018594f9f482516f2a6781",
|
||||
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008",
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:2bafac87e7f4b9b418d9448d219b01ab",
|
||||
"GUID:be17a8778dbfe454890ed8279279e153",
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:9400d40641bab5b4a9702f65bf5c6eb5"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 917f4379101d8ba4f8226ed9bbeeeb84
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
47
Packages/Common~/Scripts/UX/Input/UXScreenJoyStick.cs
Normal file
47
Packages/Common~/Scripts/UX/Input/UXScreenJoyStick.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Events;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXScreenJoyStick : UXDrag
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
public float range;
|
||||
public bool resetOnUp;
|
||||
public bool updateDelta;
|
||||
[Header(Constant.Header.Events)]
|
||||
public UnityEvent<Vector2> onDelta;
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
public Vector2 delta;
|
||||
protected override Vector2 GetProcessDelta(Vector2 delta)
|
||||
{
|
||||
delta = Vector2.ClampMagnitude(delta, range);
|
||||
return delta;
|
||||
}
|
||||
protected override void PointerUpEventHandler(PointerUpEvent evt)
|
||||
{
|
||||
base.PointerUpEventHandler(evt);
|
||||
if (resetOnUp)
|
||||
{
|
||||
visualElement.transform.position = default;
|
||||
onDelta.Invoke(this.delta = default);
|
||||
}
|
||||
}
|
||||
protected override void OnDelta(Vector2 delta)
|
||||
{
|
||||
delta.y = -delta.y;
|
||||
if (updateDelta is false)
|
||||
onDelta.Invoke(delta);
|
||||
this.delta = delta;
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
if (updateDelta && delta.sqrMagnitude is not 0)
|
||||
{
|
||||
onDelta.Invoke(delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Input/UXScreenJoyStick.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Input/UXScreenJoyStick.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38765acb716bd8b409e8b336ce84f19c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/UX/Navigation.meta
Normal file
8
Packages/Common~/Scripts/UX/Navigation.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0757adba9accdb4caf57436d2f5ba31
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
38
Packages/Common~/Scripts/UX/Navigation/UXNextable.cs
Normal file
38
Packages/Common~/Scripts/UX/Navigation/UXNextable.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using UnityEngine.Events;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXNextable : MonoBehaviour, INextble
|
||||
{
|
||||
public MonoBehaviour entry;
|
||||
public UnityEvent onStart;
|
||||
public UnityEvent onEnd;
|
||||
public void EntryNext()
|
||||
{
|
||||
Next();
|
||||
}
|
||||
public bool Next()
|
||||
{
|
||||
if (entry is INextble x)
|
||||
{
|
||||
return x.Next();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void EntryPrevious()
|
||||
{
|
||||
Previous();
|
||||
}
|
||||
public bool Previous()
|
||||
{
|
||||
if (entry is INextble x)
|
||||
{
|
||||
return x.Previous();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Navigation/UXNextable.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Navigation/UXNextable.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 598807ef83bdb7c4695eedcc4831d763
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/UX/Quest.meta
Normal file
8
Packages/Common~/Scripts/UX/Quest.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43c9066041ede064c9620a23f1920392
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
20
Packages/Common~/Scripts/UX/Quest/BITKit.UX.Quest.asmdef
Normal file
20
Packages/Common~/Scripts/UX/Quest/BITKit.UX.Quest.asmdef
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "BITKit.UX.Quest",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008",
|
||||
"GUID:2bafac87e7f4b9b418d9448d219b01ab",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:9400d40641bab5b4a9702f65bf5c6eb5"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5274363baca5454aaf4284ab7fbef6f
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
91
Packages/Common~/Scripts/UX/Quest/UXQuest.cs
Normal file
91
Packages/Common~/Scripts/UX/Quest/UXQuest.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using BITKit.SubSystems.Quest;
|
||||
using UnityEngine.UIElements;
|
||||
using System.Threading.Tasks;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXQuest : UXElement<VisualElement>
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
public bool clearAfterCompleted;
|
||||
[Header(Constant.Header.Reference)]
|
||||
[SerializeReference, SubclassSelector] public References completeClassName;
|
||||
[Header(Constant.Header.Prefabs)]
|
||||
public VisualTreeAsset visualTreeAsset;
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
public Dictionary<string, UXContainer> dictionary = new();
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
QuestSystem.OnQuestCreated += OnQuestCreated;
|
||||
QuestSystem.OnQuestCompleted += OnQuestCompleted;
|
||||
QuestSystem.OnQuestCanceled += OnQuestCancened;
|
||||
|
||||
visualElement.Clear();
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
QuestSystem.OnQuestCreated -= OnQuestCreated;
|
||||
QuestSystem.OnQuestCompleted -= OnQuestCompleted;
|
||||
QuestSystem.OnQuestCanceled -= OnQuestCancened;
|
||||
}
|
||||
void OnQuestCreated(QuestSystem.Info quest)
|
||||
{
|
||||
BIT4Log.Log<UXQuest>($"已创建任务:{quest.name}");
|
||||
|
||||
|
||||
if (dictionary.TryGetValue(quest.name, out var container))
|
||||
{
|
||||
container.visualElement.RemoveFromClassList(completeClassName);
|
||||
}
|
||||
else
|
||||
{
|
||||
container = new(visualTreeAsset.CloneTree());
|
||||
dictionary.Add(quest.name, container);
|
||||
}
|
||||
|
||||
|
||||
container.titleLabel.text = quest.name;
|
||||
container.descriptionLabel.text = quest.description;
|
||||
|
||||
visualElement.Add(container);
|
||||
}
|
||||
void OnQuestCancened(QuestSystem.Info quest)
|
||||
{
|
||||
BIT4Log.Log<UXQuest>($"已取消任务:{quest.name}");
|
||||
if (dictionary.TryGetValue(quest.name, out var container))
|
||||
{
|
||||
visualElement.Remove(container);
|
||||
dictionary.Remove(quest.name);
|
||||
}
|
||||
}
|
||||
async void OnQuestCompleted(QuestSystem.Info quest)
|
||||
{
|
||||
BIT4Log.Log<UXQuest>($"已完成任务:{quest.name}");
|
||||
|
||||
if (dictionary.TryGetValue(quest.name, out var container))
|
||||
{
|
||||
container.visualElement.AddToClassList(completeClassName);
|
||||
container.titleLabel.text = $"已完成:{quest.name}";
|
||||
container.visualElement.tabIndex = 256;
|
||||
if (clearAfterCompleted)
|
||||
{
|
||||
dictionary.Remove(quest.name);
|
||||
try
|
||||
{
|
||||
await Task.Delay(8096, cancellationToken);
|
||||
}
|
||||
catch (System.OperationCanceledException) { }
|
||||
catch (System.Exception)
|
||||
{
|
||||
visualElement.Remove(container);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Quest/UXQuest.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Quest/UXQuest.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef16bfdf3d30c624cb49798302a9565c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/UX/SubMenu.meta
Normal file
8
Packages/Common~/Scripts/UX/SubMenu.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a4110ffce8eaaa4fbb4c6cc86d62f1e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
73
Packages/Common~/Scripts/UX/SubMenu/SubMenu.cs
Normal file
73
Packages/Common~/Scripts/UX/SubMenu/SubMenu.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Events;
|
||||
namespace BITKit
|
||||
{
|
||||
public struct NewSubMenu
|
||||
{
|
||||
public string name;
|
||||
public Vector2 position;
|
||||
public IEnumerable<SubAction> actions;
|
||||
}
|
||||
public struct SubAction
|
||||
{
|
||||
public string name;
|
||||
public UnityAction action;
|
||||
}
|
||||
public class SubMenu : BITBehavior
|
||||
{
|
||||
[Header(Constant.Header.Components)]
|
||||
public UIDocument document;
|
||||
Label label;
|
||||
VisualElement context;
|
||||
VisualElement root;
|
||||
void Start()
|
||||
{
|
||||
Data.AddListener<IEnumerable<SubAction>>(OnAction);
|
||||
Data.AddListener<NewSubMenu>(OnContextMenu);
|
||||
root = document.rootVisualElement;
|
||||
label = root.Q<Label>("Label");
|
||||
context = root.Q("Context");
|
||||
SetActive(false);
|
||||
root.RegisterCallback<PointerLeaveEvent>(x =>
|
||||
{
|
||||
SetActive(false);
|
||||
});
|
||||
}
|
||||
void OnContextMenu(NewSubMenu contextMenu)
|
||||
{
|
||||
label.text = contextMenu.name;
|
||||
OnAction(contextMenu.actions);
|
||||
root.style.left = contextMenu.position.x - 4f;
|
||||
root.style.top = contextMenu.position.y - 4f;
|
||||
}
|
||||
void OnAction(IEnumerable<SubAction> actions)
|
||||
{
|
||||
SetActive(true);
|
||||
actions.ForEach(x =>
|
||||
{
|
||||
var button = new Button();
|
||||
button.text = x.name;
|
||||
button.clicked += () =>
|
||||
{
|
||||
x.action.Invoke();
|
||||
SetActive(false);
|
||||
};
|
||||
context.Add(button);
|
||||
});
|
||||
}
|
||||
public override void SetActive(bool active)
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Clear();
|
||||
}
|
||||
document.rootVisualElement.SetActive(active);
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/SubMenu/SubMenu.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/SubMenu/SubMenu.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9e12554cacfd7944957a480f6d62e93
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/UX/Touch.meta
Normal file
8
Packages/Common~/Scripts/UX/Touch.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41c33b2fc80b9eb43a52eabf1b7e1945
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
17
Packages/Common~/Scripts/UX/Touch/BITKit.UX.Touch.asmdef
Normal file
17
Packages/Common~/Scripts/UX/Touch/BITKit.UX.Touch.asmdef
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "BITKit.UX.Touch",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:a209c53514018594f9f482516f2a6781",
|
||||
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 105d77f86fa433c48a95f37e37057b03
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
18
Packages/Common~/Scripts/UX/Touch/UXTouchToolBar.cs
Normal file
18
Packages/Common~/Scripts/UX/Touch/UXTouchToolBar.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class UXTouchToolBar : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/UX/Touch/UXTouchToolBar.cs.meta
Normal file
11
Packages/Common~/Scripts/UX/Touch/UXTouchToolBar.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9f44f29d2c072d409a14c0c8375f45a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user