From 5afe410bce0ceea9c484eb5c0896859c44681827 Mon Sep 17 00:00:00 2001 From: Vladimir Sigalkin Date: Thu, 17 Aug 2023 21:59:47 +0300 Subject: [PATCH] feat(values): added variants --- .../Examples/extDebug.Menu/Example.cs | 14 +++-- Assets/extDebug/Scripts/Menu/DM.cs | 47 +++++++++-------- Assets/extDebug/Scripts/Menu/DMBool.cs | 2 +- Assets/extDebug/Scripts/Menu/DMBranch.cs | 51 ++++++++++--------- Assets/extDebug/Scripts/Menu/DMContainer.cs | 47 +++++++++-------- Assets/extDebug/Scripts/Menu/DMEnum.cs | 4 +- Assets/extDebug/Scripts/Menu/DMFloat.cs | 2 +- Assets/extDebug/Scripts/Menu/DMInt16.cs | 2 +- Assets/extDebug/Scripts/Menu/DMInt32.cs | 5 +- Assets/extDebug/Scripts/Menu/DMInt64.cs | 2 +- Assets/extDebug/Scripts/Menu/DMInt8.cs | 2 +- Assets/extDebug/Scripts/Menu/DMLogs.cs | 2 +- Assets/extDebug/Scripts/Menu/DMString.cs | 2 +- Assets/extDebug/Scripts/Menu/DMUInt16.cs | 2 +- Assets/extDebug/Scripts/Menu/DMUInt32.cs | 2 +- Assets/extDebug/Scripts/Menu/DMUInt64.cs | 2 +- Assets/extDebug/Scripts/Menu/DMUInt8.cs | 5 +- .../Scripts/Menu/DMUnityFloatStruct.cs | 4 +- .../extDebug/Scripts/Menu/DMUnityIntStruct.cs | 4 +- Assets/extDebug/Scripts/Menu/DMValue.cs | 40 +++++++++++++-- Assets/extDebug/Scripts/Menu/IDMContainer.cs | 23 +++++---- 21 files changed, 156 insertions(+), 108 deletions(-) diff --git a/Assets/extDebug/Examples/extDebug.Menu/Example.cs b/Assets/extDebug/Examples/extDebug.Menu/Example.cs index c3133e0..87aca27 100644 --- a/Assets/extDebug/Examples/extDebug.Menu/Example.cs +++ b/Assets/extDebug/Examples/extDebug.Menu/Example.cs @@ -111,7 +111,11 @@ public int GetLogsCount() #region Private Vars - private string _string = "Hello, World!"; + private readonly string _string = "Hello, World!"; + + private string _string2 = "Variant 2"; + + private readonly string[] _stringVariants = new string[] { "Variant 1", "Variant 2", "Variant 3" }; private byte _uint8; @@ -184,10 +188,12 @@ public int GetLogsCount() private void Start() { var storage = new DMPlayerStorage(); - + var order = 0; + // Simple Menus - DM.Add("Simple Menus/Action", action => Debug.Log("Hello, Action!"), "Simple Action", order: 0); - DM.Add("Simple Menus/String", () => _string, order: 1); + DM.Add("Simple Menus/Action", action => Debug.Log("Hello, Action!"), "Simple Action", order: -1); + DM.Add("Simple Menus/String", () => _string, order: 0); + DM.Add("Simple Menus/String Variants", () => _string2, v => _string2 = v, _stringVariants, order: 1); DM.Add("Simple Menus/UInt8", () => _uint8, v => _uint8 = v, order: 2); DM.Add("Simple Menus/UInt16", () => _uint16, v => _uint16 = v, order: 3); DM.Add("Simple Menus/UInt32", () => _uint32, v => _uint32 = v, order: 4); diff --git a/Assets/extDebug/Scripts/Menu/DM.cs b/Assets/extDebug/Scripts/Menu/DM.cs index ffae8c6..7accbaa 100644 --- a/Assets/extDebug/Scripts/Menu/DM.cs +++ b/Assets/extDebug/Scripts/Menu/DM.cs @@ -94,53 +94,56 @@ public static DMBranch Add(string path, string description = "", int order = 0) public static DMString Add(string path, Func getter, int order = 0) => Container.Add(path, getter, order); + public static DMString Add(string path, Func getter, Action setter, string[] variants, int order = 0) => + Container.Add(path, getter, setter, variants, order); + // Action public static DMAction Add(string path, Action action, string description = "", int order = 0) => Container.Add(path, action, description, order); // Bool - public static DMBool Add(string path, Func getter, Action setter = null, int order = 0) => - Container.Add(path, getter, setter, order); + public static DMBool Add(string path, Func getter, Action setter = null, bool[] variants = null, int order = 0) => + Container.Add(path, getter, setter, variants, order); // Enum - public static DMEnum Add(string path, Func getter, Action setter = null, int order = 0) where T : struct, Enum => - Container.Add(path, getter, setter, order); + public static DMEnum Add(string path, Func getter, Action setter = null, T[] variants = null, int order = 0) where T : struct, Enum => + Container.Add(path, getter, setter, variants, order); // UInt8 - public static DMUInt8 Add(string path, Func getter, Action setter = null, int order = 0) => - Container.Add(path, getter, setter, order); + public static DMUInt8 Add(string path, Func getter, Action setter = null, byte[] variants = null, int order = 0) => + Container.Add(path, getter, setter, variants, order); // UInt16 - public static DMUInt16 Add(string path, Func getter, Action setter = null, int order = 0) => - Container.Add(path, getter, setter, order); + public static DMUInt16 Add(string path, Func getter, Action setter = null, UInt16[] variants = null, int order = 0) => + Container.Add(path, getter, setter, variants, order); // UInt32 - public static DMUInt32 Add(string path, Func getter, Action setter = null, int order = 0) => - Container.Add(path, getter, setter, order); + public static DMUInt32 Add(string path, Func getter, Action setter = null, UInt32[] variants = null, int order = 0) => + Container.Add(path, getter, setter, variants, order); // UInt64 - public static DMUInt64 Add(string path, Func getter, Action setter = null, int order = 0) => - Container.Add(path, getter, setter, order); + public static DMUInt64 Add(string path, Func getter, Action setter = null, UInt64[] variants = null, int order = 0) => + Container.Add(path, getter, setter, variants, order); // Int8 - public static DMInt8 Add(string path, Func getter, Action setter = null, int order = 0) => - Container.Add(path, getter, setter, order); + public static DMInt8 Add(string path, Func getter, Action setter = null, sbyte[] variants = null, int order = 0) => + Container.Add(path, getter, setter, variants, order); // Int16 - public static DMInt16 Add(string path, Func getter, Action setter = null, int order = 0) => - Container.Add(path, getter, setter, order); + public static DMInt16 Add(string path, Func getter, Action setter = null, Int16[] variants = null, int order = 0) => + Container.Add(path, getter, setter, variants, order); // Int32 - public static DMInt32 Add(string path, Func getter, Action setter = null, int order = 0) => - Container.Add(path, getter, setter, order); + public static DMInt32 Add(string path, Func getter, Action setter = null, Int32[] variants = null, int order = 0) => + Container.Add(path, getter, setter, variants, order); // Int64 - public static DMInt64 Add(string path, Func getter, Action setter = null, int order = 0) => - Container.Add(path, getter, setter, order); + public static DMInt64 Add(string path, Func getter, Action setter = null, Int64[] variants = null, int order = 0) => + Container.Add(path, getter, setter, variants, order); // Float - public static DMFloat Add(string path, Func getter, Action setter = null, int order = 0) => - Container.Add(path, getter, setter, order); + public static DMFloat Add(string path, Func getter, Action setter = null, float[] variants = null, int order = 0) => + Container.Add(path, getter, setter, variants, order); // Vector 2 public static DMVector2 Add(string path, Func getter, Action setter = null, int order = 0) => diff --git a/Assets/extDebug/Scripts/Menu/DMBool.cs b/Assets/extDebug/Scripts/Menu/DMBool.cs index c637da0..0991822 100644 --- a/Assets/extDebug/Scripts/Menu/DMBool.cs +++ b/Assets/extDebug/Scripts/Menu/DMBool.cs @@ -8,7 +8,7 @@ public class DMBool : DMValue { #region Public Methods - public DMBool(DMBranch parent, string path, Func getter, Action setter = null, int order = 0) : base(parent, path, getter, setter, order) + public DMBool(DMBranch parent, string path, Func getter, Action setter = null, bool[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order) { } #endregion diff --git a/Assets/extDebug/Scripts/Menu/DMBranch.cs b/Assets/extDebug/Scripts/Menu/DMBranch.cs index 610d493..720c9ab 100644 --- a/Assets/extDebug/Scripts/Menu/DMBranch.cs +++ b/Assets/extDebug/Scripts/Menu/DMBranch.cs @@ -85,44 +85,47 @@ public void Clear() public DMBranch Add(string path, string description = "", int order = 0) => Get(path) ?? new DMBranch(this, path, description, order); - public DMString Add(string path, Func getter, int order = 0) => - new DMString(this, path, getter, order); + public DMString Add(string path, Func getter, int order = 0) => + new DMString(this, path, getter, order: order); + + public DMString Add(string path, Func getter, Action setter, string[] variants, int order = 0) => + new DMString(this, path, getter, setter, variants, order); public DMAction Add(string path, Action action, string description = "", int order = 0) => new DMAction(this, path, description, action, order); - public DMBool Add(string path, Func getter, Action setter = null, int order = 0) => - new DMBool(this, path, getter, setter, order); + public DMBool Add(string path, Func getter, Action setter = null, bool[] variants = null, int order = 0) => + new DMBool(this, path, getter, setter, variants, order); - public DMEnum Add(string path, Func getter, Action setter = null, int order = 0) where T : struct, Enum => - new DMEnum(this, path, getter, setter, order); + public DMEnum Add(string path, Func getter, Action setter = null, T[] variants = null, int order = 0) where T : struct, Enum => + new DMEnum(this, path, getter, setter, variants, order); - public DMUInt8 Add(string path, Func getter, Action setter = null, int order = 0) => - new DMUInt8(this, path, getter, setter, order); + public DMUInt8 Add(string path, Func getter, Action setter = null, byte[] variants = null, int order = 0) => + new DMUInt8(this, path, getter, setter, variants, order); - public DMUInt16 Add(string path, Func getter, Action setter = null, int order = 0) => - new DMUInt16(this, path, getter, setter, order); + public DMUInt16 Add(string path, Func getter, Action setter = null, ushort[] variants = null, int order = 0) => + new DMUInt16(this, path, getter, setter, variants, order); - public DMUInt32 Add(string path, Func getter, Action setter = null, int order = 0) => - new DMUInt32(this, path, getter, setter, order); + public DMUInt32 Add(string path, Func getter, Action setter = null, uint[] variants = null, int order = 0) => + new DMUInt32(this, path, getter, setter, variants, order); - public DMUInt64 Add(string path, Func getter, Action setter = null, int order = 0) => - new DMUInt64(this, path, getter, setter, order); + public DMUInt64 Add(string path, Func getter, Action setter = null, ulong[] variants = null, int order = 0) => + new DMUInt64(this, path, getter, setter, variants, order); - public DMInt8 Add(string path, Func getter, Action setter = null, int order = 0) => - new DMInt8(this, path, getter, setter, order); + public DMInt8 Add(string path, Func getter, Action setter = null, sbyte[] variants = null, int order = 0) => + new DMInt8(this, path, getter, setter, variants, order); - public DMInt16 Add(string path, Func getter, Action setter = null, int order = 0) => - new DMInt16(this, path, getter, setter, order); + public DMInt16 Add(string path, Func getter, Action setter = null, short[] variants = null, int order = 0) => + new DMInt16(this, path, getter, setter, variants, order); - public DMInt32 Add(string path, Func getter, Action setter = null, int order = 0) => - new DMInt32(this, path, getter, setter, order); + public DMInt32 Add(string path, Func getter, Action setter = null, int[] variants = null, int order = 0) => + new DMInt32(this, path, getter, setter, variants, order); - public DMInt64 Add(string path, Func getter, Action setter = null, int order = 0) => - new DMInt64(this, path, getter, setter, order); + public DMInt64 Add(string path, Func getter, Action setter = null, long[] variants = null, int order = 0) => + new DMInt64(this, path, getter, setter, variants, order); - public DMFloat Add(string path, Func getter, Action setter = null, int order = 0) => - new DMFloat(this, path, getter, setter, order); + public DMFloat Add(string path, Func getter, Action setter = null, float[] variants = null, int order = 0) => + new DMFloat(this, path, getter, setter, variants, order); public DMVector2 Add(string path, Func getter, Action setter = null, int order = 0) => new DMVector2(this, path, getter, setter, order); diff --git a/Assets/extDebug/Scripts/Menu/DMContainer.cs b/Assets/extDebug/Scripts/Menu/DMContainer.cs index 4b03f14..5df6209 100644 --- a/Assets/extDebug/Scripts/Menu/DMContainer.cs +++ b/Assets/extDebug/Scripts/Menu/DMContainer.cs @@ -168,53 +168,56 @@ public DMBranch Add(string path, string description = "", int order = 0) => public DMString Add(string path, Func getter, int order = 0) => Root.Add(path, getter, order); + public DMString Add(string path, Func getter, Action setter, string[] variants, int order = 0) => + Root.Add(path, getter, setter, variants, order); + // Action public DMAction Add(string path, Action action, string description = "", int order = 0) => Root.Add(path, action, description, order); // Bool - public DMBool Add(string path, Func getter, Action setter = null, int order = 0) => - Root.Add(path, getter, setter, order); + public DMBool Add(string path, Func getter, Action setter = null, bool[] variants = null, int order = 0) => + Root.Add(path, getter, setter, variants, order); // Enums - public DMEnum Add(string path, Func getter, Action setter = null, int order = 0) where T : struct, Enum => - Root.Add(path, getter, setter, order); + public DMEnum Add(string path, Func getter, Action setter = null, T[] variants = null, int order = 0) where T : struct, Enum => + Root.Add(path, getter, setter, variants, order); // UInt8 - public DMUInt8 Add(string path, Func getter, Action setter = null, int order = 0) => - Root.Add(path, getter, setter, order); + public DMUInt8 Add(string path, Func getter, Action setter = null, byte[] variants = null, int order = 0) => + Root.Add(path, getter, setter, variants, order); // UInt16 - public DMUInt16 Add(string path, Func getter, Action setter = null, int order = 0) => - Root.Add(path, getter, setter, order); + public DMUInt16 Add(string path, Func getter, Action setter = null, UInt16[] variants = null, int order = 0) => + Root.Add(path, getter, setter, variants, order); // UInt32 - public DMUInt32 Add(string path, Func getter, Action setter = null, int order = 0) => - Root.Add(path, getter, setter, order); + public DMUInt32 Add(string path, Func getter, Action setter = null, UInt32[] variants = null, int order = 0) => + Root.Add(path, getter, setter, variants, order); // UInt64 - public DMUInt64 Add(string path, Func getter, Action setter = null, int order = 0) => - Root.Add(path, getter, setter, order); + public DMUInt64 Add(string path, Func getter, Action setter = null, UInt64[] variants = null, int order = 0) => + Root.Add(path, getter, setter, variants, order); // Int8 - public DMInt8 Add(string path, Func getter, Action setter = null, int order = 0) => - Root.Add(path, getter, setter, order); + public DMInt8 Add(string path, Func getter, Action setter = null, sbyte[] variants = null, int order = 0) => + Root.Add(path, getter, setter, variants, order); // Int16 - public DMInt16 Add(string path, Func getter, Action setter = null, int order = 0) => - Root.Add(path, getter, setter, order); + public DMInt16 Add(string path, Func getter, Action setter = null, Int16[] variants = null, int order = 0) => + Root.Add(path, getter, setter, variants, order); // Int32 - public DMInt32 Add(string path, Func getter, Action setter = null, int order = 0) => - Root.Add(path, getter, setter, order); + public DMInt32 Add(string path, Func getter, Action setter = null, Int32[] variants = null, int order = 0) => + Root.Add(path, getter, setter, variants, order); // Int64 - public DMInt64 Add(string path, Func getter, Action setter = null, int order = 0) => - Root.Add(path, getter, setter, order); + public DMInt64 Add(string path, Func getter, Action setter = null, Int64[] variants = null, int order = 0) => + Root.Add(path, getter, setter, variants, order); // Float - public DMFloat Add(string path, Func getter, Action setter = null, int order = 0) => - Root.Add(path, getter, setter, order); + public DMFloat Add(string path, Func getter, Action setter = null, float[] variants = null, int order = 0) => + Root.Add(path, getter, setter, variants, order); // Vector 2 public DMVector2 Add(string path, Func getter, Action setter = null, int order = 0) => diff --git a/Assets/extDebug/Scripts/Menu/DMEnum.cs b/Assets/extDebug/Scripts/Menu/DMEnum.cs index 5545ab4..7e2d6e3 100644 --- a/Assets/extDebug/Scripts/Menu/DMEnum.cs +++ b/Assets/extDebug/Scripts/Menu/DMEnum.cs @@ -40,7 +40,7 @@ private static T PrevEnum(T value) #region Public Methods - public DMEnum(DMBranch parent, string path, Func getter, Action setter = null, int order = 0) : base(parent, path, getter, setter, order) + public DMEnum(DMBranch parent, string path, Func getter, Action setter = null, T[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order) { if (setter != null) { @@ -67,7 +67,7 @@ public DMEnum(DMBranch parent, string path, Func getter, Action setter = n var intValue = (int)(object)value; setter.Invoke((T)(object)(intGetter ^ intValue)); - }, i); + }, order: i); } _flagBranch.Add("Back", BackAction, string.Empty, int.MaxValue); diff --git a/Assets/extDebug/Scripts/Menu/DMFloat.cs b/Assets/extDebug/Scripts/Menu/DMFloat.cs index 46bc317..4680361 100644 --- a/Assets/extDebug/Scripts/Menu/DMFloat.cs +++ b/Assets/extDebug/Scripts/Menu/DMFloat.cs @@ -28,7 +28,7 @@ public class DMFloat : DMValue #region Public Methods - public DMFloat(DMBranch parent, string path, Func getter, Action setter = null, int order = 0) : base(parent, path, getter, setter, order) + public DMFloat(DMBranch parent, string path, Func getter, Action setter = null, float[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order) { SetPrecision(2); } diff --git a/Assets/extDebug/Scripts/Menu/DMInt16.cs b/Assets/extDebug/Scripts/Menu/DMInt16.cs index af40a3a..7836bfd 100644 --- a/Assets/extDebug/Scripts/Menu/DMInt16.cs +++ b/Assets/extDebug/Scripts/Menu/DMInt16.cs @@ -18,7 +18,7 @@ public class DMInt16 : DMValue #region Public Methods - public DMInt16(DMBranch parent, string path, Func getter, Action setter = null, int order = 0) : base(parent, path, getter, setter, order) + public DMInt16(DMBranch parent, string path, Func getter, Action setter = null, Int16[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order) { } #endregion diff --git a/Assets/extDebug/Scripts/Menu/DMInt32.cs b/Assets/extDebug/Scripts/Menu/DMInt32.cs index 6727040..1f6478b 100644 --- a/Assets/extDebug/Scripts/Menu/DMInt32.cs +++ b/Assets/extDebug/Scripts/Menu/DMInt32.cs @@ -18,9 +18,8 @@ public class DMInt32 : DMValue #region Public Methods - public DMInt32(DMBranch parent, string path, Func getter, Action setter = null, int order = 0) : base(parent, path, getter, setter, order) - { - } + public DMInt32(DMBranch parent, string path, Func getter, Action setter = null, Int32[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order) + { } #endregion diff --git a/Assets/extDebug/Scripts/Menu/DMInt64.cs b/Assets/extDebug/Scripts/Menu/DMInt64.cs index dd083f9..036826e 100644 --- a/Assets/extDebug/Scripts/Menu/DMInt64.cs +++ b/Assets/extDebug/Scripts/Menu/DMInt64.cs @@ -18,7 +18,7 @@ public class DMInt64 : DMValue #region Public Methods - public DMInt64(DMBranch parent, string path, Func getter, Action setter = null, int order = 0) : base(parent, path, getter, setter, order) + public DMInt64(DMBranch parent, string path, Func getter, Action setter = null, Int64[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order) { } #endregion diff --git a/Assets/extDebug/Scripts/Menu/DMInt8.cs b/Assets/extDebug/Scripts/Menu/DMInt8.cs index a9d13f9..1650e83 100644 --- a/Assets/extDebug/Scripts/Menu/DMInt8.cs +++ b/Assets/extDebug/Scripts/Menu/DMInt8.cs @@ -18,7 +18,7 @@ public class DMInt8 : DMValue #region Public Methods - public DMInt8(DMBranch parent, string path, Func getter, Action setter = null, int order = 0) : base(parent, path, getter, setter, order) + public DMInt8(DMBranch parent, string path, Func getter, Action setter = null, sbyte[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order) { } #endregion diff --git a/Assets/extDebug/Scripts/Menu/DMLogs.cs b/Assets/extDebug/Scripts/Menu/DMLogs.cs index 7b0e1a4..2000b4b 100644 --- a/Assets/extDebug/Scripts/Menu/DMLogs.cs +++ b/Assets/extDebug/Scripts/Menu/DMLogs.cs @@ -75,7 +75,7 @@ public DMLogs(DMBranch parent, string path, string description, IDMLogsContainer _itemsLogs[i] = logItem; } - _items[size] = new DMString(null, string.Empty, GetLogsPagination, int.MaxValue); + _items[size] = new DMString(null, string.Empty, GetLogsPagination, order: int.MaxValue); } public void RequestRepaint() => _canRepaint = true; diff --git a/Assets/extDebug/Scripts/Menu/DMString.cs b/Assets/extDebug/Scripts/Menu/DMString.cs index ad21155..2e1dfe6 100644 --- a/Assets/extDebug/Scripts/Menu/DMString.cs +++ b/Assets/extDebug/Scripts/Menu/DMString.cs @@ -8,7 +8,7 @@ public class DMString : DMValue { #region Public Methods - public DMString(DMBranch parent, string path, Func getter, int order = 0) : base(parent, path, getter, null, order) + public DMString(DMBranch parent, string path, Func getter, Action setter = null, string[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order) { } #endregion diff --git a/Assets/extDebug/Scripts/Menu/DMUInt16.cs b/Assets/extDebug/Scripts/Menu/DMUInt16.cs index 05b7f50..a0a2f0c 100644 --- a/Assets/extDebug/Scripts/Menu/DMUInt16.cs +++ b/Assets/extDebug/Scripts/Menu/DMUInt16.cs @@ -18,7 +18,7 @@ public class DMUInt16 : DMValue #region Public Methods - public DMUInt16(DMBranch parent, string path, Func getter, Action setter = null, int order = 0) : base(parent, path, getter, setter, order) + public DMUInt16(DMBranch parent, string path, Func getter, Action setter = null, UInt16[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order) { } #endregion diff --git a/Assets/extDebug/Scripts/Menu/DMUInt32.cs b/Assets/extDebug/Scripts/Menu/DMUInt32.cs index 8db49e0..92278eb 100644 --- a/Assets/extDebug/Scripts/Menu/DMUInt32.cs +++ b/Assets/extDebug/Scripts/Menu/DMUInt32.cs @@ -18,7 +18,7 @@ public class DMUInt32 : DMValue #region Public Methods - public DMUInt32(DMBranch parent, string path, Func getter, Action setter = null, int order = 0) : base(parent, path, getter, setter, order) + public DMUInt32(DMBranch parent, string path, Func getter, Action setter = null, UInt32[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order) { } #endregion diff --git a/Assets/extDebug/Scripts/Menu/DMUInt64.cs b/Assets/extDebug/Scripts/Menu/DMUInt64.cs index 88fdae6..9a0bd2c 100644 --- a/Assets/extDebug/Scripts/Menu/DMUInt64.cs +++ b/Assets/extDebug/Scripts/Menu/DMUInt64.cs @@ -18,7 +18,7 @@ public class DMUInt64 : DMValue #region Public Methods - public DMUInt64(DMBranch parent, string path, Func getter, Action setter = null, int order = 0) : base(parent, path, getter, setter, order) + public DMUInt64(DMBranch parent, string path, Func getter, Action setter = null, UInt64[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order) { } #endregion diff --git a/Assets/extDebug/Scripts/Menu/DMUInt8.cs b/Assets/extDebug/Scripts/Menu/DMUInt8.cs index 7f4a4aa..58373f2 100644 --- a/Assets/extDebug/Scripts/Menu/DMUInt8.cs +++ b/Assets/extDebug/Scripts/Menu/DMUInt8.cs @@ -18,9 +18,8 @@ public class DMUInt8 : DMValue #region Public Methods - public DMUInt8(DMBranch parent, string path, Func getter, Action setter = null, int order = 0) : base(parent, path, getter, setter, order) - { - } + public DMUInt8(DMBranch parent, string path, Func getter, Action setter = null, byte[] variants = null, int order = 0) : base(parent, path, getter, setter, variants, order) + { } #endregion diff --git a/Assets/extDebug/Scripts/Menu/DMUnityFloatStruct.cs b/Assets/extDebug/Scripts/Menu/DMUnityFloatStruct.cs index eb2961f..b0e1f74 100644 --- a/Assets/extDebug/Scripts/Menu/DMUnityFloatStruct.cs +++ b/Assets/extDebug/Scripts/Menu/DMUnityFloatStruct.cs @@ -66,7 +66,7 @@ public void AddPreset(string name, TStruct value) #region Protected Methods protected DMUnityFloatStruct(DMBranch parent, string path, Func getter, Action setter = null, - int order = 0) : base(parent, path, getter, setter, order) + int order = 0) : base(parent, path, getter, setter, null, order) { if (setter != null) { @@ -86,7 +86,7 @@ protected DMUnityFloatStruct(DMBranch parent, string path, Func getter, var vector = getter.Invoke(); StructFieldSetter(ref vector, fieldIndex, v); setter.Invoke(vector); - }, i); + }, order: i); } _fieldsBranch.Add("Back", BackAction, string.Empty, int.MaxValue); diff --git a/Assets/extDebug/Scripts/Menu/DMUnityIntStruct.cs b/Assets/extDebug/Scripts/Menu/DMUnityIntStruct.cs index 4aafa34..8cd6557 100644 --- a/Assets/extDebug/Scripts/Menu/DMUnityIntStruct.cs +++ b/Assets/extDebug/Scripts/Menu/DMUnityIntStruct.cs @@ -51,7 +51,7 @@ public void AddPreset(string name, TStruct value) #region Protected Methods protected DMUnityIntStruct(DMBranch parent, string path, Func getter, Action setter = null, - int order = 0) : base(parent, path, getter, setter, order) + int order = 0) : base(parent, path, getter, setter, null, order) { if (setter != null) { @@ -71,7 +71,7 @@ protected DMUnityIntStruct(DMBranch parent, string path, Func getter, A var vector = getter.Invoke(); StructFieldSetter(ref vector, fieldIndex, v); setter.Invoke(vector); - }, i); + }, order: i); } _fieldsBranch.Add("Back", BackAction, string.Empty, int.MaxValue); diff --git a/Assets/extDebug/Scripts/Menu/DMValue.cs b/Assets/extDebug/Scripts/Menu/DMValue.cs index 655a1bc..b8bb517 100644 --- a/Assets/extDebug/Scripts/Menu/DMValue.cs +++ b/Assets/extDebug/Scripts/Menu/DMValue.cs @@ -1,6 +1,7 @@ /* Copyright (c) 2023 dr. ext (Vladimir Sigalkin) */ using System; +using System.Collections.Generic; namespace extDebug.Menu { @@ -20,19 +21,22 @@ public abstract class DMValue : DMItem private T _defaultValue; + private T[] _variants; + private IDMStorage _storage; #endregion #region Public Methods - protected DMValue(DMBranch parent, string path, Func getter, Action setter = null, int order = 0) : base(parent, path, string.Empty, string.Empty, order) + protected DMValue(DMBranch parent, string path, Func getter, Action setter = null, T[] variants = null, int order = 0) : base(parent, path, string.Empty, string.Empty, order) { _getter = getter; _setter = setter; _path = path; _defaultValue = getter.Invoke(); + _variants = variants; } public void SetStorage(IDMStorage storage) @@ -64,13 +68,31 @@ protected override void OnEvent(EventArgs eventArgs) { if (eventArgs.Key == EventKey.Left && _setter != null) { - var value = ValueDecrement(_getter.Invoke(), eventArgs.IsShift); + T value; + + if (_variants != null && _variants.Length > 0) + { + value = PrevVariant(_getter.Invoke()); + } + else + { + value = ValueDecrement(_getter.Invoke(), eventArgs.IsShift); + } ChangeValue(value, false); } else if (eventArgs.Key == EventKey.Right && _setter != null) { - var value = ValueIncrement(_getter.Invoke(), eventArgs.IsShift); + T value; + + if (_variants != null && _variants.Length > 0) + { + value = NextVariant(_getter.Invoke()); + } + else + { + value = ValueIncrement(_getter.Invoke(), eventArgs.IsShift); + } ChangeValue(value, false); } @@ -87,6 +109,18 @@ protected override void OnEvent(EventArgs eventArgs) protected abstract T ValueDecrement(T value, bool isShift); + protected virtual T NextVariant(T value) + { + var index = Math.Max(Array.IndexOf(_variants, value), 0) + 1; + return index >= _variants.Length ? _variants[0] : _variants[index]; + } + + protected virtual T PrevVariant(T value) + { + var index = Math.Max(Array.IndexOf(_variants, value), 0) - 1; + return index < 0 ? _variants[_variants.Length] : _variants[index]; + } + #endregion #region Private Methods diff --git a/Assets/extDebug/Scripts/Menu/IDMContainer.cs b/Assets/extDebug/Scripts/Menu/IDMContainer.cs index 71a9847..2efbc15 100644 --- a/Assets/extDebug/Scripts/Menu/IDMContainer.cs +++ b/Assets/extDebug/Scripts/Menu/IDMContainer.cs @@ -16,42 +16,43 @@ public interface IDMContainer // String public DMString Add(string path, Func getter, int order = 0); + public DMString Add(string path, Func getter, Action setter, string[] variants, int order = 0); // Action public DMAction Add(string path, Action action, string description = "", int order = 0); // Bool - public DMBool Add(string path, Func getter, Action setter = null, int order = 0); + public DMBool Add(string path, Func getter, Action setter = null, bool[] variants = null, int order = 0); // Enum - public DMEnum Add(string path, Func getter, Action setter = null, int order = 0) where T : struct, Enum; + public DMEnum Add(string path, Func getter, Action setter = null, T[] variants = null, int order = 0) where T : struct, Enum; // UInt8 - public DMUInt8 Add(string path, Func getter, Action setter = null, int order = 0); + public DMUInt8 Add(string path, Func getter, Action setter = null, byte[] variants = null, int order = 0); // UInt16 - public DMUInt16 Add(string path, Func getter, Action setter = null, int order = 0); + public DMUInt16 Add(string path, Func getter, Action setter = null, UInt16[] variants = null, int order = 0); // UInt32 - public DMUInt32 Add(string path, Func getter, Action setter = null, int order = 0); + public DMUInt32 Add(string path, Func getter, Action setter = null, UInt32[] variants = null, int order = 0); // UInt64 - public DMUInt64 Add(string path, Func getter, Action setter = null, int order = 0); + public DMUInt64 Add(string path, Func getter, Action setter = null, UInt64[] variants = null, int order = 0); // Int8 - public DMInt8 Add(string path, Func getter, Action setter = null, int order = 0); + public DMInt8 Add(string path, Func getter, Action setter = null, sbyte[] variants = null, int order = 0); // Int16 - public DMInt16 Add(string path, Func getter, Action setter = null, int order = 0); + public DMInt16 Add(string path, Func getter, Action setter = null, Int16[] variants = null, int order = 0); // Int32 - public DMInt32 Add(string path, Func getter, Action setter = null, int order = 0); + public DMInt32 Add(string path, Func getter, Action setter = null, Int32[] variants = null, int order = 0); // Int64 - public DMInt64 Add(string path, Func getter, Action setter = null, int order = 0); + public DMInt64 Add(string path, Func getter, Action setter = null, Int64[] variants = null, int order = 0); // Float - public DMFloat Add(string path, Func getter, Action setter = null, int order = 0); + public DMFloat Add(string path, Func getter, Action setter = null, float[] variants = null, int order = 0); // Vector 2 public DMVector2 Add(string path, Func getter, Action setter = null, int order = 0);