-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #312 from hadashiA/ku/diagnostics-window
VContainer Diagnostics Window
- Loading branch information
Showing
42 changed files
with
1,334 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
VContainer/Assets/VContainer/Editor/Diagnostics/SplitterGUILayout.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace VContainer.Editor.Diagnostics | ||
{ | ||
// reflection call of UnityEditor.SplitterGUILayout | ||
static class SplitterGUILayout | ||
{ | ||
static BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static; | ||
|
||
static readonly Lazy<Type> SplitterStateType = new Lazy<Type>(() => | ||
{ | ||
var type = typeof(EditorWindow).Assembly.GetTypes().First(x => x.FullName == "UnityEditor.SplitterState"); | ||
return type; | ||
}); | ||
|
||
static readonly Lazy<ConstructorInfo> SplitterStateCtor = new Lazy<ConstructorInfo>(() => | ||
{ | ||
var type = SplitterStateType.Value; | ||
return type.GetConstructor(flags, null, new Type[] { typeof(float[]), typeof(int[]), typeof(int[]) }, null); | ||
}); | ||
|
||
static readonly Lazy<Type> SplitterGUILayoutType = new Lazy<Type>(() => | ||
{ | ||
var type = typeof(EditorWindow).Assembly.GetTypes().First(x => x.FullName == "UnityEditor.SplitterGUILayout"); | ||
return type; | ||
}); | ||
|
||
static readonly Lazy<MethodInfo> BeginVerticalSplitInfo = new Lazy<MethodInfo>(() => | ||
{ | ||
var type = SplitterGUILayoutType.Value; | ||
return type.GetMethod("BeginVerticalSplit", flags, null, new Type[] { SplitterStateType.Value, typeof(GUILayoutOption[]) }, null); | ||
}); | ||
|
||
static readonly Lazy<MethodInfo> EndVerticalSplitInfo = new Lazy<MethodInfo>(() => | ||
{ | ||
var type = SplitterGUILayoutType.Value; | ||
return type.GetMethod("EndVerticalSplit", flags, null, Type.EmptyTypes, null); | ||
}); | ||
|
||
static readonly Lazy<MethodInfo> BeginHorizontalSplitInfo = new Lazy<MethodInfo>(() => | ||
{ | ||
var type = SplitterGUILayoutType.Value; | ||
return type.GetMethod("BeginHorizontalSplit", flags, null, new Type[] { SplitterStateType.Value, typeof(GUILayoutOption[]) }, null); | ||
}); | ||
|
||
static readonly Lazy<MethodInfo> EndHorizontalSplitInfo = new Lazy<MethodInfo>(() => | ||
{ | ||
var type = SplitterGUILayoutType.Value; | ||
return type.GetMethod("EndHorizontalSplit", flags, null, Type.EmptyTypes, null); | ||
}); | ||
|
||
public static object CreateSplitterState(float[] relativeSizes, int[] minSizes, int[] maxSizes) | ||
{ | ||
return SplitterStateCtor.Value.Invoke(new object[] { relativeSizes, minSizes, maxSizes }); | ||
} | ||
|
||
public static void BeginVerticalSplit(object splitterState, params GUILayoutOption[] options) | ||
{ | ||
BeginVerticalSplitInfo.Value.Invoke(null, new object[] { splitterState, options }); | ||
} | ||
|
||
public static void EndVerticalSplit() | ||
{ | ||
EndVerticalSplitInfo.Value.Invoke(null, Array.Empty<object>()); | ||
} | ||
|
||
public static void BeginHorizontalSplit(object splitterState, params GUILayoutOption[] options) | ||
{ | ||
BeginHorizontalSplitInfo.Value.Invoke(null, new object[] { splitterState, options }); | ||
} | ||
|
||
public static void EndHorizontalSplit() | ||
{ | ||
EndHorizontalSplitInfo.Value.Invoke(null, Array.Empty<object>()); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
VContainer/Assets/VContainer/Editor/Diagnostics/SplitterGUILayout.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
VContainer/Assets/VContainer/Editor/Diagnostics/TypeNameHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace VContainer.Editor.Diagnostics | ||
{ | ||
static class TypeNameHelper | ||
{ | ||
static readonly IReadOnlyDictionary<Type, string> TypeAlias = new Dictionary<Type, string> | ||
{ | ||
{ typeof(bool), "bool" }, | ||
{ typeof(byte), "byte" }, | ||
{ typeof(char), "char" }, | ||
{ typeof(decimal), "decimal" }, | ||
{ typeof(double), "double" }, | ||
{ typeof(float), "float" }, | ||
{ typeof(int), "int" }, | ||
{ typeof(long), "long" }, | ||
{ typeof(object), "object" }, | ||
{ typeof(sbyte), "sbyte" }, | ||
{ typeof(short), "short" }, | ||
{ typeof(string), "string" }, | ||
{ typeof(uint), "uint" }, | ||
{ typeof(ulong), "ulong" }, | ||
{ typeof(void), "void" } | ||
}; | ||
|
||
public static string GetTypeAlias(Type type) | ||
{ | ||
if (TypeAlias.TryGetValue(type, out var alias)) | ||
{ | ||
return alias; | ||
} | ||
if (type.IsGenericType) | ||
{ | ||
var typeParameters = type.GetGenericArguments().Select(GetTypeAlias); | ||
var typeNameBase = type.Name.Split('`')[0]; | ||
return $"{typeNameBase}<{string.Join(",", typeParameters)}>"; | ||
} | ||
return type.Name; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
VContainer/Assets/VContainer/Editor/Diagnostics/TypeNameHelper.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
cdcb5ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: