Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/inspector generic names #900

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ public static void DrawComponents(IEntity entity)
public static void DrawComponent(bool[] unfoldedComponents, string[] componentMemberSearch, IEntity entity, int index, IComponent component)
{
var componentType = component.GetType();
var componentName = componentType.Name.RemoveComponentSuffix();
var customNameProvider = component as ICustomDisplayName;
var componentName = customNameProvider != null
? customNameProvider.DisplayName
: TypeHelper.GetTypeName(componentType).RemoveComponentSuffix();

if (EditorLayout.MatchesSearchString(componentName.ToLower(), componentNameSearchString.ToLower()))
{
var boxStyle = getColoredBoxStyle(entity, index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
<Compile Include="Entitas.VisualDebugging.Unity\Entity\DontDrawComponentAttribute.cs" />
<Compile Include="Entitas.VisualDebugging.Unity\Entity\EntityBehaviour.cs" />
<Compile Include="Entitas.VisualDebugging.Unity\GameObjectDestroyExtension.cs" />
<Compile Include="Entitas.VisualDebugging.Unity\ICustomDisplayName.cs" />
<Compile Include="Entitas.VisualDebugging.Unity\TypeHelper.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Entitas\Entitas.csproj">
<Project>{A0A11CC3-8B1E-4345-A5FA-01FC60E581D8}</Project>
<Name>Entitas</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Entitas.VisualDebugging.Unity\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,22 @@ public class SystemInfo {
_interfaceFlags = getInterfaceFlags(system);

var debugSystem = system as DebugSystems;
_systemName = debugSystem != null
? debugSystem.name
: system.GetType().Name.RemoveSystemSuffix();
if (debugSystem != null)
{
_systemName = debugSystem.name;
}
else
{
var customNameProvider = system as ICustomDisplayName;
if (customNameProvider != null)
{
_systemName = customNameProvider.DisplayName;
}
else
{
_systemName = TypeHelper.GetTypeName(system.GetType()).RemoveSystemSuffix();
}
}

isActive = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Entitas.VisualDebugging.Unity
{
public interface ICustomDisplayName
{
string DisplayName { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;

namespace Entitas.VisualDebugging.Unity
{
public static class TypeHelper
{
/// <summary>
/// Returns a type name including generic type parameters.
/// </summary>
public static string GetTypeName(Type type)
{
if (type.IsGenericType)
{
var simpleName = type.Name.Substring(0, type.Name.IndexOf('`'));
string genericTypeParams = string.Empty;
var args = !type.IsGenericTypeDefinition
? type.GetGenericArguments()
: Type.EmptyTypes;

for (int i = 0; i < args.Length; i++)
{
if (i > 0) genericTypeParams += ",";
genericTypeParams += GetTypeName(args[i]);
}
return string.Format("{0}<{1}>", simpleName, genericTypeParams);
}
return type.Name;
}
}
}