Skip to content

Commit

Permalink
Merge pull request #312 from hadashiA/ku/diagnostics-window
Browse files Browse the repository at this point in the history
VContainer Diagnostics Window
  • Loading branch information
hadashiA authored Oct 11, 2021
2 parents cb2b300 + f5aa682 commit cdcb5ad
Show file tree
Hide file tree
Showing 42 changed files with 1,334 additions and 87 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ The extra fast DI (Dependency Injection) library running on Unity Game Engine.
- Flexible scoping
- Application can freely create nested Lifetime Scope with any async way for you like.
- Pre IL Code generation optimization mode
- Diagnositcs window on unity editor
- UniTask Integration
- ECS Integration *beta*

## Documentation

Visit [vcontainer.hadashikick.jp](https://vcontainer.hadashikick.jp) to view the full documentation.

## Performance

![](./website/static/img/benchmark_result.png)
Expand All @@ -38,7 +43,6 @@ The extra fast DI (Dependency Injection) library running on Unity Game Engine.
![](./website/static/img/screenshot_profiler_zenject.png)



## Installation

*Requires Unity 2018.4+*
Expand Down Expand Up @@ -231,6 +235,8 @@ using (LifetimeScope.Enqueue(builder =>
}
```

See [scoping](https://vcontainer.hadashikick.jp/scoping/lifetime-overview) for more information.

## UniTask

```csharp
Expand All @@ -249,13 +255,14 @@ public class FooController : IAsyncStartable
builder.RegisterEntryPoint<FooController>();
```

## Documentation
See [integrations](https://vcontainer.hadashikick.jp/scoping/lifetime-overview) for more information.

Visit [vcontainer.hadashikick.jp](https://vcontainer.hadashikick.jp) to view the full documentation.

## Getting Started
## Diagnostics Window

![](./website/static/img/screenshot_diagnostics_window.png)

Visit [vcontainer.hadashikick.jp/getting-started](https://vcontainer.hadashikick.jp/getting-started/installation) to get started.
See [diagnostics](https://vcontainer.hadashikick.jp/scoping/lifetime-overview) for more information.

## Credits

Expand Down
3 changes: 3 additions & 0 deletions VContainer/Assets/VContainer/Editor/Diagnostics.meta

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

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>());
}
}
}

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

43 changes: 43 additions & 0 deletions VContainer/Assets/VContainer/Editor/Diagnostics/TypeNameHelper.cs
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;
}
}
}

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

Loading

1 comment on commit cdcb5ad

@vercel
Copy link

@vercel vercel bot commented on cdcb5ad Oct 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.