更改文件架构
This commit is contained in:
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:
|
Reference in New Issue
Block a user