Skip to content

Commit

Permalink
feat(Menu): added vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Iam1337 committed Dec 31, 2021
1 parent 53a63b9 commit 29c1a71
Show file tree
Hide file tree
Showing 22 changed files with 522 additions and 158 deletions.
42 changes: 27 additions & 15 deletions Assets/extDebug/Examples/extDebug.Menu/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ private enum ExampleFlags

#region Private Vars

private string _string = string.Empty;

private byte _uint8;

private UInt16 _uint16;
Expand All @@ -51,6 +53,12 @@ private enum ExampleFlags

private bool _bool;

private Vector2 _vector2;

private Vector3 _vector3;

private Vector4 _vector4;

private ExampleEnums _enum;

private ExampleFlags _flags;
Expand Down Expand Up @@ -79,29 +87,33 @@ private enum ExampleFlags

private ExampleFlags _flagsStorage;

#endregion
#endregion

#region Unity Methods

private void Start()
{
var storage = new DMPlayerStorage();

// Simple Menus
DM.Add("Simple Menus/Action", action => Debug.Log("Hello/Action"), order: 0);
DM.Add("Simple Menus/UInt8", () => _uint8, v => _uint8 = v, order: 1);
DM.Add("Simple Menus/UInt16", () => _uint16, v => _uint16 = v, order: 2);
DM.Add("Simple Menus/UInt32", () => _uint32, v => _uint32 = v, order: 3);
DM.Add("Simple Menus/UInt64", () => _uint64, v => _uint64 = v, order: 4);
DM.Add("Simple Menus/Int8", () => _int8, v => _int8 = v, order: 5);
DM.Add("Simple Menus/Int16", () => _int16, v => _int16 = v, order: 6);
DM.Add("Simple Menus/Int32", () => _int32, v => _int32 = v, order: 7);
DM.Add("Simple Menus/Int64", () => _int64, v => _int64 = v, order: 8);
DM.Add("Simple Menus/Float", () => _float, v => _float = v, order: 9).SetPrecision(2);
DM.Add("Simple Menus/Bool", () => _bool, v => _bool = v, order: 10);
DM.Add("Simple Menus/Enum", () => _enum, v => _enum = v, order: 11);
DM.Add("Simple Menus/Flags", () => _flags, v => _flags = v, order: 12);

DM.Add("Simple Menus/String", () => _string, 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);
DM.Add("Simple Menus/UInt64", () => _uint64, v => _uint64 = v, order: 5);
DM.Add("Simple Menus/Int8", () => _int8, v => _int8 = v, order: 6);
DM.Add("Simple Menus/Int16", () => _int16, v => _int16 = v, order: 7);
DM.Add("Simple Menus/Int32", () => _int32, v => _int32 = v, order: 8);
DM.Add("Simple Menus/Int64", () => _int64, v => _int64 = v, order: 9);
DM.Add("Simple Menus/Float", () => _float, v => _float = v, order: 10).SetPrecision(2);
DM.Add("Simple Menus/Bool", () => _bool, v => _bool = v, order: 11);
DM.Add("Simple Menus/Enum", () => _enum, v => _enum = v, order: 12);
DM.Add("Simple Menus/Flags", () => _flags, v => _flags = v, order: 13);
DM.Add("Simple Menus/Vector 2", () => _vector2, v => _vector2 = v, order: 14);
DM.Add("Simple Menus/Vector 3", () => _vector3, v => _vector3 = v, order: 15);
DM.Add("Simple Menus/Vector 4", () => _vector4, v => _vector4 = v, order: 16);

// Storage
DM.Add("Storage Values/UInt8", () => _uint8Storage, v => _uint8Storage = v, order: 1).SetStorage(storage);
DM.Add("Storage Values/UInt16", () => _uint16Storage, v => _uint16Storage = v, order: 2).SetStorage(storage);
Expand Down
13 changes: 13 additions & 0 deletions Assets/extDebug/Scripts/FloatUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Copyright (c) 2021 dr. ext (Vladimir Sigalkin) */

namespace extDebug
{
internal static class FloatUtils
{
#region Public Vars

public static readonly string[] Formats = new[] { "0", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8" };

#endregion
}
}
11 changes: 11 additions & 0 deletions Assets/extDebug/Scripts/FloatUtils.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 27 additions & 44 deletions Assets/extDebug/Scripts/Menu/DM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,81 +93,64 @@ static DM()
public static void Notify(DMItem item, Color? nameColor = null, Color? valueColor = null) => Notice?.Notify(item, nameColor, valueColor);

// Branch
public static DMBranch Add(string path, string description = "", int order = 0) => Add(Root, path, description, order);
public static DMBranch Add(string path, string description = "", int order = 0) => Container.Add(path, description, order);

public static DMBranch Add(DMBranch parent, string path, string description = "", int order = 0) => parent == null ? new DMBranch(null, path, description, order) : Root.Get(path) ?? new DMBranch(parent, path, description, order);
// String
public static DMString Add(string path, Func<string> getter, int order = 0) => Container.Add(path, getter, order);

// Action
public static DMAction Add(string path, Action<DMAction> action, string description = "", int order = 0) => Add(Root, path, action, description, order);

public static DMAction Add(DMBranch parent, string path, Action<DMAction> action, string description = "", int order = 0) => new DMAction(parent, path, description, action, order);
public static DMAction Add(string path, Action<DMAction> action, string description = "", int order = 0) => Container.Add(path, action, description, order);

// Bool
public static DMBool Add(string path, Func<bool> getter, Action<bool> setter = null, int order = 0) => Add(Root, path, getter, setter, order);

public static DMBool Add(DMBranch parent, string path, Func<bool> getter, Action<bool> setter = null, int order = 0) => new DMBool(parent, path, getter, setter, order);
public static DMBool Add(string path, Func<bool> getter, Action<bool> setter = null, int order = 0) => Container.Add(path, getter, setter, order);

// Enum
public static DMEnum<T> Add<T>(string path, Func<T> getter, Action<T> setter = null, int order = 0) where T : struct, Enum => Add(Root, path, getter, setter, order);

public static DMEnum<T> Add<T>(DMBranch parent, string path, Func<T> getter, Action<T> setter = null, int order = 0) where T : struct, Enum => new DMEnum<T>(parent, path, getter, setter, order);
public static DMEnum<T> Add<T>(string path, Func<T> getter, Action<T> setter = null, int order = 0) where T : struct, Enum => Container.Add(path, getter, setter, order);

// UInt8
public static DMUInt8 Add(string path, Func<byte> getter, Action<byte> setter = null, int order = 0) => Add(Root, path, getter, setter, order);

public static DMUInt8 Add(DMBranch parent, string path, Func<byte> getter, Action<byte> setter = null, int order = 0) => new DMUInt8(parent, path, getter, setter, order);

public static DMUInt8 Add(string path, Func<byte> getter, Action<byte> setter = null, int order = 0) => Container.Add(path, getter, setter, order);

// UInt16
public static DMUInt16 Add(string path, Func<UInt16> getter, Action<UInt16> setter = null, int order = 0) => Add(Root, path, getter, setter, order);

public static DMUInt16 Add(DMBranch parent, string path, Func<UInt16> getter, Action<UInt16> setter = null, int order = 0) => new DMUInt16(parent, path, getter, setter, order);
public static DMUInt16 Add(string path, Func<UInt16> getter, Action<UInt16> setter = null, int order = 0) => Container.Add(path, getter, setter, order);

// UInt32
public static DMUInt32 Add(string path, Func<UInt32> getter, Action<UInt32> setter = null, int order = 0) => Add(Root, path, getter, setter, order);
public static DMUInt32 Add(string path, Func<UInt32> getter, Action<UInt32> setter = null, int order = 0) => Container.Add(path, getter, setter, order);

public static DMUInt32 Add(DMBranch parent, string path, Func<UInt32> getter, Action<UInt32> setter = null, int order = 0) => new DMUInt32(parent, path, getter, setter, order);

// UInt64
public static DMUInt64 Add(string path, Func<UInt64> getter, Action<UInt64> setter = null, int order = 0) => Add(Root, path, getter, setter, order);

public static DMUInt64 Add(DMBranch parent, string path, Func<UInt64> getter, Action<UInt64> setter = null, int order = 0) => new DMUInt64(parent, path, getter, setter, order);
public static DMUInt64 Add(string path, Func<UInt64> getter, Action<UInt64> setter = null, int order = 0) => Container.Add(path, getter, setter, order);

// Int8
public static DMInt8 Add(string path, Func<sbyte> getter, Action<sbyte> setter = null, int order = 0) => Add(Root, path, getter, setter, order);

public static DMInt8 Add(DMBranch parent, string path, Func<sbyte> getter, Action<sbyte> setter = null, int order = 0) => new DMInt8(parent, path, getter, setter, order);
public static DMInt8 Add(string path, Func<sbyte> getter, Action<sbyte> setter = null, int order = 0) => Container.Add(path, getter, setter, order);

// Int16
public static DMInt16 Add(string path, Func<Int16> getter, Action<Int16> setter = null, int order = 0) => Add(Root, path, getter, setter, order);

public static DMInt16 Add(DMBranch parent, string path, Func<Int16> getter, Action<Int16> setter = null, int order = 0) => new DMInt16(parent, path, getter, setter, order);
public static DMInt16 Add(string path, Func<Int16> getter, Action<Int16> setter = null, int order = 0) => Container.Add(path, getter, setter, order);

// Int32
public static DMInt32 Add(string path, Func<Int32> getter, Action<Int32> setter = null, int order = 0) => Add(Root, path, getter, setter, order);

public static DMInt32 Add(DMBranch parent, string path, Func<Int32> getter, Action<Int32> setter = null, int order = 0) => new DMInt32(parent, path, getter, setter, order);
public static DMInt32 Add(string path, Func<Int32> getter, Action<Int32> setter = null, int order = 0) => Container.Add(path, getter, setter, order);

// Int64
public static DMInt64 Add(string path, Func<Int64> getter, Action<Int64> setter = null, int order = 0) => Add(Root, path, getter, setter, order);

public static DMInt64 Add(DMBranch parent, string path, Func<Int64> getter, Action<Int64> setter = null, int order = 0) => new DMInt64(parent, path, getter, setter, order);
public static DMInt64 Add(string path, Func<Int64> getter, Action<Int64> setter = null, int order = 0) => Container.Add(path, getter, setter, order);

// Float
public static DMFloat Add(string path, Func<float> getter, Action<float> setter = null, int order = 0) => Add(Root, path, getter, setter, order);
public static DMFloat Add(string path, Func<float> getter, Action<float> setter = null, int order = 0) => Container.Add(path, getter, setter, order);

// Vector 2
public static DMVector2 Add(string path, Func<Vector2> getter, Action<Vector2> setter = null, int order = 0) => Container.Add(path, getter, setter, order);

public static DMFloat Add(DMBranch parent, string path, Func<float> getter, Action<float> setter = null, int order = 0) => new DMFloat(parent, path, getter, setter, order);
// Vector 3
public static DMVector3 Add(string path, Func<Vector3> getter, Action<Vector3> setter = null, int order = 0) => Container.Add(path, getter, setter, order);

// Dynamic
public static DMBranch Add<T>(string path, Func<IEnumerable<T>> getter, Action<DMBranch, T> buildCallback = null, Func<T, string> nameCallback = null, string description = "", int order = 0) => Add(Root, path, getter, buildCallback, nameCallback, description, order);
// Vector 4
public static DMVector4 Add(string path, Func<Vector4> getter, Action<Vector4> setter = null, int order = 0) => Container.Add(path, getter, setter, order);

// Dynamic
public static DMBranch Add<T>(string path, Func<IEnumerable<T>> getter, Action<DMBranch, T> buildCallback = null, Func<T, string> nameCallback = null, string description = "", int order = 0) => Container.Add(path, getter, buildCallback, nameCallback, description, order);

public static DMBranch Add<T>(DMBranch parent, string path, Func<IEnumerable<T>> getter, Action<DMBranch, T> buildCallback = null, Func<T, string> nameCallback = null, string description = "", int order = 0) => Container.Add(parent, path, getter, buildCallback, nameCallback, description, order);

#endregion

#region Private Methods


private static void Update()
private static void Update()
{
Container.Update();
}
Expand Down
64 changes: 50 additions & 14 deletions Assets/extDebug/Scripts/Menu/DMBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,33 +84,69 @@ public void Clear()
}

// Container
public DMBranch Add(string path, string description = "", int order = 0) => Container.Add(this, path, description, order);
public DMBranch Add(string path, string description = "", int order = 0) => Get(path) ?? new DMBranch(this, path, description, order);

public DMString Add(string path, Func<string> getter, int order = 0) => new DMString(this, path, getter, order);

public DMAction Add(string path, Action<DMAction> action, string description = "", int order = 0) => Container.Add(this, path, action, description, order);
public DMAction Add(string path, Action<DMAction> action, string description = "", int order = 0) => new DMAction(this, path, description, action, order);

public DMBool Add(string path, Func<bool> getter, Action<bool> setter = null, int order = 0) => Container.Add(this, path, getter, setter, order);
public DMBool Add(string path, Func<bool> getter, Action<bool> setter = null, int order = 0) => new DMBool(this, path, getter, setter, order);

public DMEnum<T> Add<T>(string path, Func<T> getter, Action<T> setter = null, int order = 0) where T : struct, Enum => Container.Add(this, path, getter, setter, order);
public DMEnum<T> Add<T>(string path, Func<T> getter, Action<T> setter = null, int order = 0) where T : struct, Enum => new DMEnum<T>(this, path, getter, setter, order);

public DMUInt8 Add(string path, Func<byte> getter, Action<byte> setter = null, int order = 0) => Container.Add(this, path, getter, setter, order);
public DMUInt8 Add(string path, Func<byte> getter, Action<byte> setter = null, int order = 0) => new DMUInt8(this, path, getter, setter, order);

public DMUInt16 Add(string path, Func<ushort> getter, Action<ushort> setter = null, int order = 0) => Container.Add(this, path, getter, setter, order);
public DMUInt16 Add(string path, Func<ushort> getter, Action<ushort> setter = null, int order = 0) => new DMUInt16(this, path, getter, setter, order);

public DMUInt32 Add(string path, Func<uint> getter, Action<uint> setter = null, int order = 0) => Container.Add(this, path, getter, setter, order);
public DMUInt32 Add(string path, Func<uint> getter, Action<uint> setter = null, int order = 0) => new DMUInt32(this, path, getter, setter, order);

public DMUInt64 Add(string path, Func<ulong> getter, Action<ulong> setter = null, int order = 0) => Container.Add(this, path, getter, setter, order);
public DMUInt64 Add(string path, Func<ulong> getter, Action<ulong> setter = null, int order = 0) => new DMUInt64(this, path, getter, setter, order);

public DMInt8 Add(string path, Func<sbyte> getter, Action<sbyte> setter = null, int order = 0) => Container.Add(this, path, getter, setter, order);
public DMInt8 Add(string path, Func<sbyte> getter, Action<sbyte> setter = null, int order = 0) => new DMInt8(this, path, getter, setter, order);

public DMInt16 Add(string path, Func<short> getter, Action<short> setter = null, int order = 0) => Container.Add(this, path, getter, setter, order);
public DMInt16 Add(string path, Func<short> getter, Action<short> setter = null, int order = 0) => new DMInt16(this, path, getter, setter, order);

public DMInt32 Add(string path, Func<int> getter, Action<int> setter = null, int order = 0) => Container.Add(this, path, getter, setter, order);
public DMInt32 Add(string path, Func<int> getter, Action<int> setter = null, int order = 0) => new DMInt32(this, path, getter, setter, order);

public DMInt64 Add(string path, Func<long> getter, Action<long> setter = null, int order = 0) => Container.Add(this, path, getter, setter, order);
public DMInt64 Add(string path, Func<long> getter, Action<long> setter = null, int order = 0) => new DMInt64(this, path, getter, setter, order);

public DMFloat Add(string path, Func<float> getter, Action<float> setter = null, int order = 0) => Container.Add(this, path, getter, setter, order);
public DMFloat Add(string path, Func<float> getter, Action<float> setter = null, int order = 0) => new DMFloat(this, path, getter, setter, order);
public DMVector2 Add(string path, Func<Vector2> getter, Action<Vector2> setter = null, int order = 0) => new DMVector2(this, path, getter, setter, order);

public DMBranch Add<T>(string path, Func<IEnumerable<T>> getter, Action<DMBranch, T> buildCallback = null, Func<T, string> nameCallback = null, string description = "", int order = 0) => Container.Add(this, path, getter, buildCallback, nameCallback, description, order);
public DMVector3 Add(string path, Func<Vector3> getter, Action<Vector3> setter = null, int order = 0) => new DMVector3(this, path, getter, setter, order);

public DMVector4 Add(string path, Func<Vector4> getter, Action<Vector4> setter = null, int order = 0) => new DMVector4(this, path, getter, setter, order);

public DMBranch Add<T>(string path, Func<IEnumerable<T>> getter, Action<DMBranch, T> buildCallback = null, Func<T, string> nameCallback = null, string description = "", int order = 0)
{
if (getter == null)
throw new NullReferenceException(nameof(getter));

var dynamicBranch = Add(path, description, order);
dynamicBranch.OnOpen += dBranch =>
{
dBranch.Clear();

var index = 0;
var objects = getter.Invoke();

foreach (var obj in objects)
{
var name = nameCallback != null ? nameCallback.Invoke(obj) : obj.ToString();
var objectTemp = obj;
var objectBranch = dBranch.Add(name, string.Empty, index++);

objectBranch.Data = objectTemp;
objectBranch.OnOpen += oBranch =>
{
oBranch.Clear();
buildCallback?.Invoke(oBranch, objectTemp);
};
}
};

return dynamicBranch;
}

// Repaint
public void RequestRepaint() => _canRepaint = true;
Expand Down
Loading

0 comments on commit 29c1a71

Please sign in to comment.