Compare commits
	
		
			4 Commits
		
	
	
		
			new-window
			...
			main
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| d14e2ca055 | |||
| d0d7134b68 | |||
| 987c7b1be2 | |||
| f7a7427610 | 
| @ -1,5 +1,4 @@ | |||||||
| using UnityEngine; | using UnityEngine; | ||||||
| using UnityEngine.SceneManagement; |  | ||||||
| 
 | 
 | ||||||
| namespace NEG.Utils | namespace NEG.Utils | ||||||
| { | { | ||||||
|  | |||||||
| @ -185,8 +185,10 @@ public static class BuildingUtils | |||||||
|         string command = |         string command = | ||||||
|             $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && push_build.bat"; |             $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && push_build.bat"; | ||||||
|         if (demo) |         if (demo) | ||||||
|  |         { | ||||||
|             command = |             command = | ||||||
|                 $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && push_demo.bat"; |                 $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && push_demo.bat"; | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         var processInfo = new ProcessStartInfo("cmd.exe", $"/c {command}") |         var processInfo = new ProcessStartInfo("cmd.exe", $"/c {command}") | ||||||
|         { |         { | ||||||
|  | |||||||
| @ -102,8 +102,10 @@ namespace NegUtils.Editor | |||||||
|                             return; |                             return; | ||||||
| 
 | 
 | ||||||
|                         if (EditorPrefs.GetBool("GoToCurrentSceneAfterPlay")) |                         if (EditorPrefs.GetBool("GoToCurrentSceneAfterPlay")) | ||||||
|  |                         { | ||||||
|                             EditorSceneManager.LoadSceneInPlayMode(EditorPrefs.GetString("LastOpenedScenePath"), |                             EditorSceneManager.LoadSceneInPlayMode(EditorPrefs.GetString("LastOpenedScenePath"), | ||||||
|                                 new LoadSceneParameters(LoadSceneMode.Single)); |                                 new LoadSceneParameters(LoadSceneMode.Single)); | ||||||
|  |                         } | ||||||
|                         else if (EditorPrefs.GetBool("GoToFirstSceneAfterPlay")) |                         else if (EditorPrefs.GetBool("GoToFirstSceneAfterPlay")) | ||||||
|                             SceneManager.LoadScene(1); |                             SceneManager.LoadScene(1); | ||||||
|                     } |                     } | ||||||
|  | |||||||
| @ -31,10 +31,12 @@ namespace NEG.Utils | |||||||
|                 var methodFields = |                 var methodFields = | ||||||
|                     type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); |                     type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); | ||||||
|                 for (int i = 0; i < methodFields.Length; i++) |                 for (int i = 0; i < methodFields.Length; i++) | ||||||
|  |                 { | ||||||
|                     if (Attribute.GetCustomAttribute(methodFields[i], typeof(FactoryRegistration)) != null) |                     if (Attribute.GetCustomAttribute(methodFields[i], typeof(FactoryRegistration)) != null) | ||||||
|                         methodFields[i].Invoke(null, Array.Empty<object>()); |                         methodFields[i].Invoke(null, Array.Empty<object>()); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         public void Register(T1 key, Type type) => data.Add(key, type); |         public void Register(T1 key, Type type) => data.Add(key, type); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,3 +0,0 @@ | |||||||
| using System.Runtime.CompilerServices; |  | ||||||
| 
 |  | ||||||
| [assembly: InternalsVisibleTo("NEG.UI.UnityUi")] |  | ||||||
| @ -1,3 +0,0 @@ | |||||||
| fileFormatVersion: 2 |  | ||||||
| guid: 1bf54cf2dc934c9b85c514bb01057e64 |  | ||||||
| timeCreated: 1716843793 |  | ||||||
| @ -248,8 +248,10 @@ namespace System.Collections.Generic | |||||||
|         public PriorityQueue(int initialCapacity, IComparer<TPriority>? comparer) |         public PriorityQueue(int initialCapacity, IComparer<TPriority>? comparer) | ||||||
|         { |         { | ||||||
|             if (initialCapacity < 0) |             if (initialCapacity < 0) | ||||||
|  |             { | ||||||
|                 throw new ArgumentOutOfRangeException( |                 throw new ArgumentOutOfRangeException( | ||||||
|                     nameof(initialCapacity), initialCapacity, SR.ArgumentOutOfRange_NeedNonNegNum); |                     nameof(initialCapacity), initialCapacity, SR.ArgumentOutOfRange_NeedNonNegNum); | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|             _nodes = new (TElement, TPriority)[initialCapacity]; |             _nodes = new (TElement, TPriority)[initialCapacity]; | ||||||
|             _comparer = InitializeComparer(comparer); |             _comparer = InitializeComparer(comparer); | ||||||
| @ -508,9 +510,8 @@ namespace System.Collections.Generic | |||||||
|                 if (_size > 1) Heapify(); |                 if (_size > 1) Heapify(); | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |                 foreach (var (element, priority) in items) | ||||||
|                 foreach (var (element, priority) in items) Enqueue(element, priority); |                     Enqueue(element, priority); | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @ -554,9 +555,8 @@ namespace System.Collections.Generic | |||||||
|                 if (i > 1) Heapify(); |                 if (i > 1) Heapify(); | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |                 foreach (var element in elements) | ||||||
|                 foreach (var element in elements) Enqueue(element, priority); |                     Enqueue(element, priority); | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @ -684,12 +684,16 @@ namespace System.Collections.Generic | |||||||
|             int lastParentWithChildren = GetParentIndex(_size - 1); |             int lastParentWithChildren = GetParentIndex(_size - 1); | ||||||
| 
 | 
 | ||||||
|             if (_comparer == null) |             if (_comparer == null) | ||||||
|  |             { | ||||||
|                 for (int index = lastParentWithChildren; index >= 0; --index) |                 for (int index = lastParentWithChildren; index >= 0; --index) | ||||||
|                     MoveDownDefaultComparer(nodes[index], index); |                     MoveDownDefaultComparer(nodes[index], index); | ||||||
|  |             } | ||||||
|             else |             else | ||||||
|  |             { | ||||||
|                 for (int index = lastParentWithChildren; index >= 0; --index) |                 for (int index = lastParentWithChildren; index >= 0; --index) | ||||||
|                     MoveDownCustomComparer(nodes[index], index); |                     MoveDownCustomComparer(nodes[index], index); | ||||||
|             } |             } | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///     Moves a node up in the tree to restore heap order. |         ///     Moves a node up in the tree to restore heap order. | ||||||
| @ -715,10 +719,8 @@ namespace System.Collections.Generic | |||||||
|                     nodeIndex = parentIndex; |                     nodeIndex = parentIndex; | ||||||
|                 } |                 } | ||||||
|                 else |                 else | ||||||
|                 { |  | ||||||
|                     break; |                     break; | ||||||
|             } |             } | ||||||
|             } |  | ||||||
| 
 | 
 | ||||||
|             nodes[nodeIndex] = node; |             nodes[nodeIndex] = node; | ||||||
|         } |         } | ||||||
| @ -748,10 +750,8 @@ namespace System.Collections.Generic | |||||||
|                     nodeIndex = parentIndex; |                     nodeIndex = parentIndex; | ||||||
|                 } |                 } | ||||||
|                 else |                 else | ||||||
|                 { |  | ||||||
|                     break; |                     break; | ||||||
|             } |             } | ||||||
|             } |  | ||||||
| 
 | 
 | ||||||
|             nodes[nodeIndex] = node; |             nodes[nodeIndex] = node; | ||||||
|         } |         } | ||||||
| @ -894,8 +894,10 @@ namespace System.Collections.Generic | |||||||
|                 if (array.GetLowerBound(0) != 0) throw new ArgumentException(SR.Arg_NonZeroLowerBound, nameof(array)); |                 if (array.GetLowerBound(0) != 0) throw new ArgumentException(SR.Arg_NonZeroLowerBound, nameof(array)); | ||||||
| 
 | 
 | ||||||
|                 if (index < 0 || index > array.Length) |                 if (index < 0 || index > array.Length) | ||||||
|  |                 { | ||||||
|                     throw new ArgumentOutOfRangeException(nameof(index), index, |                     throw new ArgumentOutOfRangeException(nameof(index), index, | ||||||
|                         SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); |                         SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); | ||||||
|  |                 } | ||||||
| 
 | 
 | ||||||
|                 if (array.Length - index < _queue._size) throw new ArgumentException(SR.Argument_InvalidOffLen); |                 if (array.Length - index < _queue._size) throw new ArgumentException(SR.Argument_InvalidOffLen); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -13,6 +13,31 @@ namespace NEG.UI | |||||||
|     [PublicAPI] |     [PublicAPI] | ||||||
|     public abstract class UiManager : IDisposable |     public abstract class UiManager : IDisposable | ||||||
|     { |     { | ||||||
|  |         private IArea currentArea; | ||||||
|  |         protected IDefaultPopup currentDefaultPopup; | ||||||
|  |         private (PopupData data, int priority) currentShownPopup; | ||||||
|  | 
 | ||||||
|  |         //TODO: localize | ||||||
|  |         private string localizedYes = "Yes", localizedNo = "No", localizedOk = "Ok"; | ||||||
|  | 
 | ||||||
|  |         private List<IWindow> mainWindows; | ||||||
|  | 
 | ||||||
|  |         private PriorityQueue<PopupData, int> popupsToShow = new(); | ||||||
|  | 
 | ||||||
|  |         protected UiManager(IArea startArea) | ||||||
|  |         { | ||||||
|  |             if (Instance != null) | ||||||
|  |             { | ||||||
|  |                 Debug.LogError("Only one instance od UiManager is allowed"); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             Instance = this; | ||||||
|  | 
 | ||||||
|  |             CurrentArea = startArea; | ||||||
|  |             mainWindows = new List<IWindow>(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         public static UiManager Instance { get; protected set; } |         public static UiManager Instance { get; protected set; } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @ -38,31 +63,6 @@ namespace NEG.UI | |||||||
| 
 | 
 | ||||||
|         public PopupData CurrentPopup => currentShownPopup.data; |         public PopupData CurrentPopup => currentShownPopup.data; | ||||||
| 
 | 
 | ||||||
|         private IArea currentArea; |  | ||||||
|         protected IDefaultPopup currentDefaultPopup; |  | ||||||
|         private (PopupData data, int priority) currentShownPopup; |  | ||||||
| 
 |  | ||||||
|         //TODO: localize |  | ||||||
|         private string localizedYes = "Yes", localizedNo = "No", localizedOk = "Ok"; |  | ||||||
| 
 |  | ||||||
|         private List<IWindow> mainWindows; |  | ||||||
| 
 |  | ||||||
|         private PriorityQueue<PopupData, int> popupsToShow = new(); |  | ||||||
|         private Dictionary<string, IWindow> registeredWindows = new(); |  | ||||||
| 
 |  | ||||||
|         protected UiManager(IArea startArea = default) |  | ||||||
|         { |  | ||||||
|             if (Instance != null) |  | ||||||
|             { |  | ||||||
|                 Debug.LogError("Only one instance od UiManager is allowed"); |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             Instance = this; |  | ||||||
|             CurrentArea = startArea; |  | ||||||
|             mainWindows = new List<IWindow>(); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         public virtual void Dispose() => Instance = null; |         public virtual void Dispose() => Instance = null; | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @ -164,9 +164,6 @@ namespace NEG.UI | |||||||
| 
 | 
 | ||||||
|         public void OnWindowClosed(IWindow window) => MainWindowClosed(window); |         public void OnWindowClosed(IWindow window) => MainWindowClosed(window); | ||||||
| 
 | 
 | ||||||
|         internal void RegisterWindow(IWindow window) => registeredWindows.Add(window.WindowId, window); |  | ||||||
|         internal void UnRegisterWindow(IWindow window) => registeredWindows.Remove(window.WindowId); |  | ||||||
| 
 |  | ||||||
|         //TODO: select new main window |         //TODO: select new main window | ||||||
|         protected void PopupClosed(PopupData data) |         protected void PopupClosed(PopupData data) | ||||||
|         { |         { | ||||||
|  | |||||||
| @ -29,7 +29,7 @@ namespace NEG.UI.Area | |||||||
| 
 | 
 | ||||||
|         private void OnDestroy() |         private void OnDestroy() | ||||||
|         { |         { | ||||||
|             if(UiManager.Instance == null) |             if (UiManager.Instance == null) | ||||||
|                 return; |                 return; | ||||||
|             if (ReferenceEquals(UiManager.Instance.CurrentArea, this)) |             if (ReferenceEquals(UiManager.Instance.CurrentArea, this)) | ||||||
|                 UiManager.Instance.CurrentArea = null; |                 UiManager.Instance.CurrentArea = null; | ||||||
|  | |||||||
| @ -43,10 +43,7 @@ namespace NEG.UI.UnityUi.Buttons | |||||||
| 
 | 
 | ||||||
|         private void Start() => OnDeselect(null); |         private void Start() => OnDeselect(null); | ||||||
| 
 | 
 | ||||||
|         private void OnValidate() |         private void OnValidate() => this.ValidateRefs(); | ||||||
|         { |  | ||||||
|             this.ValidateRefs(); |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         public void OnDeselect(BaseEventData eventData) => OnDeselected?.Invoke(eventData is SilentEventData); |         public void OnDeselect(BaseEventData eventData) => OnDeselected?.Invoke(eventData is SilentEventData); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,3 +1,4 @@ | |||||||
|  | using UnityEditor; | ||||||
| using UnityEngine; | using UnityEngine; | ||||||
| 
 | 
 | ||||||
| namespace NEG.UI.UnityUi.Buttons.Reactions | namespace NEG.UI.UnityUi.Buttons.Reactions | ||||||
| @ -7,7 +8,7 @@ namespace NEG.UI.UnityUi.Buttons.Reactions | |||||||
|         protected override void OnClicked() |         protected override void OnClicked() | ||||||
|         { |         { | ||||||
| #if UNITY_EDITOR | #if UNITY_EDITOR | ||||||
|             UnityEditor.EditorApplication.isPlaying = false; |             EditorApplication.isPlaying = false; | ||||||
| #endif | #endif | ||||||
|             Application.Quit(); |             Application.Quit(); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -74,10 +74,12 @@ namespace NEG.UI.UnityUi | |||||||
|             var data = new PointerEventData(EventSystem.current); |             var data = new PointerEventData(EventSystem.current); | ||||||
|             var currentSelected = EventSystem.current.currentSelectedGameObject; |             var currentSelected = EventSystem.current.currentSelectedGameObject; | ||||||
|             if (currentSelected != null) |             if (currentSelected != null) | ||||||
|  |             { | ||||||
|                 for (var current = EventSystem.current.currentSelectedGameObject.transform; |                 for (var current = EventSystem.current.currentSelectedGameObject.transform; | ||||||
|                      current != null; |                      current != null; | ||||||
|                      current = current.parent) |                      current = current.parent) | ||||||
|                     ExecuteEvents.Execute(current.gameObject, data, ExecuteEvents.pointerExitHandler); |                     ExecuteEvents.Execute(current.gameObject, data, ExecuteEvents.pointerExitHandler); | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|             EventSystem.current.SetSelectedGameObject(currentSelected); |             EventSystem.current.SetSelectedGameObject(currentSelected); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -12,44 +12,25 @@ namespace NEG.UI.UnityUi.Window | |||||||
|     [DefaultExecutionOrder(10)] |     [DefaultExecutionOrder(10)] | ||||||
|     public class MonoWindow : MonoBehaviour, IWindow |     public class MonoWindow : MonoBehaviour, IWindow | ||||||
|     { |     { | ||||||
|         public event Action<object> OnOpened; |  | ||||||
|         public event Action OnClosed; |  | ||||||
|         public event Action<IControllable.BackUsed> OnBackUsed; |  | ||||||
|          |  | ||||||
|         [field: SerializeField] public string WindowId { get; private set; } |  | ||||||
| 
 |  | ||||||
|         public IEnumerable<IWindowSlot> AvailableSlots => windowSlots; |  | ||||||
|         public IWindowSlot Parent { get; private set; } |  | ||||||
|          |  | ||||||
|         public bool IsOpened { get; protected set; } |  | ||||||
|          |  | ||||||
|         public bool IsMainWindow { get; } |  | ||||||
| 
 |  | ||||||
|         public GameObject DefaultSelectedItem => defaultSelectedItem; |  | ||||||
|          |  | ||||||
|         [SerializeField] private List<MonoWindowSlot> windowSlots; |         [SerializeField] private List<MonoWindowSlot> windowSlots; | ||||||
| 
 | 
 | ||||||
|         [SerializeField] private string windowName; |  | ||||||
| 
 |  | ||||||
|         [SerializeField] private GameObject defaultSelectedItem; |         [SerializeField] private GameObject defaultSelectedItem; | ||||||
| 
 | 
 | ||||||
|  |         public bool IsMainWindow { get; } | ||||||
|  | 
 | ||||||
|  |         public bool IsOpened { get; protected set; } | ||||||
|  | 
 | ||||||
|         private IWindowSlot DefaultWindowSlot => windowSlots[0]; |         private IWindowSlot DefaultWindowSlot => windowSlots[0]; | ||||||
|  |         public GameObject DefaultSelectedItem => defaultSelectedItem; | ||||||
| 
 | 
 | ||||||
| 
 |         private void Awake() => ((IWindow)this).SetHiddenState(); | ||||||
|         private void Awake() |  | ||||||
|         { |  | ||||||
|             UiManager.Instance.RegisterWindow(this); |  | ||||||
|             ((IWindow)this).SetHiddenState(); |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         private void OnDestroy() |         private void OnDestroy() | ||||||
|         { |         { | ||||||
|             if(UiManager.Instance == null) |             if (UiManager.Instance == null) | ||||||
|                 return; |                 return; | ||||||
|             if (IsOpened) |             if (IsOpened) | ||||||
|                 UiManager.Instance.OnWindowClosed(this); |                 UiManager.Instance.OnWindowClosed(this); | ||||||
|             UiManager.Instance.UnRegisterWindow(this); |  | ||||||
| 
 |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void OnValidate() |         private void OnValidate() | ||||||
| @ -60,6 +41,13 @@ namespace NEG.UI.UnityUi.Window | |||||||
| #endif | #endif | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         public event Action<object> OnOpened; | ||||||
|  |         public event Action OnClosed; | ||||||
|  |         public event Action<IControllable.BackUsed> OnBackUsed; | ||||||
|  | 
 | ||||||
|  |         public IEnumerable<IWindowSlot> AvailableSlots => windowSlots; | ||||||
|  |         public IWindowSlot Parent { get; private set; } | ||||||
|  | 
 | ||||||
|         public void SetOpenedState(IWindowSlot parentSlot, object data) |         public void SetOpenedState(IWindowSlot parentSlot, object data) | ||||||
|         { |         { | ||||||
|             gameObject.SetActive(true); |             gameObject.SetActive(true); | ||||||
|  | |||||||
| @ -12,8 +12,6 @@ namespace NEG.UI.Window | |||||||
|         /// </summary> |         /// </summary> | ||||||
|         IWindowSlot Parent { get; } |         IWindowSlot Parent { get; } | ||||||
| 
 | 
 | ||||||
|         string WindowId { get; } |  | ||||||
| 
 |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///     Called internally by slot to open window. |         ///     Called internally by slot to open window. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|  | |||||||
| @ -5,5 +5,4 @@ namespace NEG.Utils | |||||||
|     public class ReadOnlyAttribute : PropertyAttribute |     public class ReadOnlyAttribute : PropertyAttribute | ||||||
|     { |     { | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
| } | } | ||||||
							
								
								
									
										85
									
								
								NEG/Utils/SerializableGuid.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								NEG/Utils/SerializableGuid.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,85 @@ | |||||||
|  | using System; | ||||||
|  | using UnityEngine; | ||||||
|  | 
 | ||||||
|  | namespace NEG.Utils | ||||||
|  | { | ||||||
|  |     [Serializable] | ||||||
|  |     public struct SerializableGuid : IComparable, IComparable<SerializableGuid>, IEquatable<SerializableGuid> | ||||||
|  |     { | ||||||
|  |         [SerializeField] private uint value0; | ||||||
|  |         [SerializeField] private uint value1; | ||||||
|  |         [SerializeField] private uint value2; | ||||||
|  |         [SerializeField] private uint value3; | ||||||
|  | 
 | ||||||
|  |         // public SerializableGuid(string hexRepresentation) | ||||||
|  |         // { | ||||||
|  |         //     value0 = 0U; | ||||||
|  |         //     value1 = 0U; | ||||||
|  |         //     value2 = 0U; | ||||||
|  |         //     value3 = 0U; | ||||||
|  |         //     TryParse(hexRepresentation, out this); | ||||||
|  |         // } | ||||||
|  | 
 | ||||||
|  |         public static bool operator ==(SerializableGuid x, SerializableGuid y) | ||||||
|  |         { | ||||||
|  |             return (int)x.value0 == (int)y.value0 && (int)x.value1 == (int)y.value1 && | ||||||
|  |                    (int)x.value2 == (int)y.value2 && (int)x.value3 == (int)y.value3; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public static bool operator !=(SerializableGuid x, SerializableGuid y) => !(x == y); | ||||||
|  | 
 | ||||||
|  |         public static bool operator <(SerializableGuid x, SerializableGuid y) | ||||||
|  |         { | ||||||
|  |             if ((int)x.value0 != (int)y.value0) | ||||||
|  |                 return x.value0 < y.value0; | ||||||
|  |             if ((int)x.value1 != (int)y.value1) | ||||||
|  |                 return x.value1 < y.value1; | ||||||
|  |             return (int)x.value2 != (int)y.value2 ? x.value2 < y.value2 : x.value3 < y.value3; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public static bool operator > (SerializableGuid x, SerializableGuid y) => !(x < y) && !(x == y); | ||||||
|  | 
 | ||||||
|  |         public override bool Equals(object obj) => obj is SerializableGuid guid && Equals(guid); | ||||||
|  | 
 | ||||||
|  |         public bool Equals(SerializableGuid obj) => this == obj; | ||||||
|  | 
 | ||||||
|  |         public override int GetHashCode() | ||||||
|  |         { | ||||||
|  |             return ((((((int)value0 * 397) ^ (int)value1) * 397) ^ (int)value2) * 397) ^ | ||||||
|  |                    (int)value3; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public int CompareTo(object obj) => obj == null ? 1 : CompareTo((SerializableGuid)obj); | ||||||
|  | 
 | ||||||
|  |         public int CompareTo(SerializableGuid rhs) | ||||||
|  |         { | ||||||
|  |             if (this < rhs) | ||||||
|  |                 return -1; | ||||||
|  |             return this > rhs ? 1 : 0; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public bool Empty() => value0 == 0U && value1 == 0U && value2 == 0U && value3 == 0U; | ||||||
|  | 
 | ||||||
|  |         // public static bool TryParse(string hex, out SerializableGuid result) | ||||||
|  |         // { | ||||||
|  |         //     result = HexToSerializableGuidInternal(hex); | ||||||
|  |         //     return !result.Empty(); | ||||||
|  |         // } | ||||||
|  | 
 | ||||||
|  |         public static SerializableGuid Generate() | ||||||
|  |         { | ||||||
|  |             byte[] array = Guid.NewGuid().ToByteArray(); | ||||||
|  | 
 | ||||||
|  |             var guid = new SerializableGuid | ||||||
|  |             { | ||||||
|  |                 value0 = BitConverter.ToUInt32(new ReadOnlySpan<byte>(array, 0, 4)),  | ||||||
|  |                 value1 = BitConverter.ToUInt32(new ReadOnlySpan<byte>(array, 4, 4)), | ||||||
|  |                 value2 = BitConverter.ToUInt32(new ReadOnlySpan<byte>(array, 8, 4)), | ||||||
|  |                 value3 = BitConverter.ToUInt32(new ReadOnlySpan<byte>(array, 12, 4)) | ||||||
|  |             }; | ||||||
|  |             return guid; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         //public override string ToString() => SerializableGuidToHexInternal(ref this); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										3
									
								
								NEG/Utils/SerializableGuid.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								NEG/Utils/SerializableGuid.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | |||||||
|  | fileFormatVersion: 2 | ||||||
|  | guid: a81e7c502db5413194d0ebfc7bad054e | ||||||
|  | timeCreated: 1741038901 | ||||||
| @ -10,9 +10,8 @@ namespace NEG.Utils.UiToolkits | |||||||
| { | { | ||||||
|     public class MultiSelectChips : VisualElement |     public class MultiSelectChips : VisualElement | ||||||
|     { |     { | ||||||
|         private readonly List<MultiSelectChipItem> spawnedItems = new(); |  | ||||||
| 
 |  | ||||||
|         private readonly VisualTreeAsset itemPrefab; |         private readonly VisualTreeAsset itemPrefab; | ||||||
|  |         private readonly List<MultiSelectChipItem> spawnedItems = new(); | ||||||
| 
 | 
 | ||||||
|         private ICollection<IMultiSelectChipItem> itemsSource; |         private ICollection<IMultiSelectChipItem> itemsSource; | ||||||
| 
 | 
 | ||||||
| @ -86,8 +85,10 @@ namespace NEG.Utils.UiToolkits | |||||||
|             List<IMultiSelectChipItem> itemsToAdd = new(itemsSource); |             List<IMultiSelectChipItem> itemsToAdd = new(itemsSource); | ||||||
| 
 | 
 | ||||||
|             foreach (var item in spawnedItems) |             foreach (var item in spawnedItems) | ||||||
|  |             { | ||||||
|                 if (itemsToAdd.Contains(item.ChipItem)) |                 if (itemsToAdd.Contains(item.ChipItem)) | ||||||
|                     itemsToAdd.Remove(item.ChipItem); |                     itemsToAdd.Remove(item.ChipItem); | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|             foreach (var item in itemsToAdd) |             foreach (var item in itemsToAdd) | ||||||
|             { |             { | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" | <ui:UXML xmlns:ui="UnityEngine.UIElements" | ||||||
|          xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" |          xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" | ||||||
|          noNamespaceSchemaLocation="../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False"> |          noNamespaceSchemaLocation="../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False"> | ||||||
|     <ui:VisualElement name="VisualElement" class="unity-button" |     <ui:VisualElement name="VisualElement" class="unity-button" | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" | <ui:UXML xmlns:ui="UnityEngine.UIElements" | ||||||
|          xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" |          xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" | ||||||
|          noNamespaceSchemaLocation="../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False"> |          noNamespaceSchemaLocation="../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False"> | ||||||
|     <ui:VisualElement style="flex-direction: row; flex-wrap: wrap;"> |     <ui:VisualElement style="flex-direction: row; flex-wrap: wrap;"> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user