Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Assets/Sample/MyMonoBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

public interface IMyInterface<T> {}
public class MyIntObject : IMyInterface<int> {}
public class MyGenericObject<T> : IMyInterface<T> {}
public struct StructWillNotShow : IMyInterface<int> {}
public class MyMonoBehavior : MonoBehaviour
{
[GenericSerializeReference]
public IMyInterface<int> Value { get; set; }

[GenericSerializeReference("_serialized")]
public IMyInterface<int> Foo { get; set; }
private int __Foo;
//
// [GenericSerializeReference("_serialized")]
// public IMyInterface<int> Foo { get; set; }
// private int __Foo;
}
9 changes: 9 additions & 0 deletions Packages/generic-serialize-reference/Editor/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
Expand All @@ -25,6 +26,14 @@ public static int FindLastIndexOf<T>(this IList<T> list, Predicate<T> predicate)
}
}

internal static class ReflectionExtension
{
public static string ToReadableName(this Type type)
{
return type.IsGenericType ? Regex.Replace(type.ToString(), @"(\w+)`\d+\[(.*)\]", "$1<$2>") : type.ToString();
}
}

internal static class CecilExtension
{
public static TypeDefinition ToTypeDefinition<T>(this ModuleDefinition module) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private void AddItemToContextMenu(Type type, GenericMenu genericMenuContext, Ser
{
// it must have a BaseType
var assemblyName = type.BaseType.Assembly.ToString().Split('(', ',')[0];
var entryName = type.BaseType + " ( " + assemblyName + " )";
var entryName = type.BaseType.ToReadableName() + " ( " + assemblyName + " )";
genericMenuContext.AddItem(new GUIContent(entryName), false, AssignNewInstanceCommand, new GenericMenuParameterForAssignInstanceCommand(type, property));
}

Expand Down
2 changes: 1 addition & 1 deletion Packages/generic-serialize-reference/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.quabug.generic-serialize-reference",
"description": "Automatically alter generic field of SerializeReference into its non-generic form",
"version": "1.1.0",
"version": "1.1.1",
"unity": "2020.2",
"displayName": "GenericSerializeReference",
"samples": [
Expand Down