TypeReferenceSerialize a System.Type
WarningThis function saves the target's domain and type name. Which means if you change the name, the data will be lost. Carefully think about it before using it.
By default, it searchs the current assembly and referenced assembly and shows all visible (public) types.
You can add an extra [TypeReference] to control the behavior.
Parameters:
EType eType = EType.Current: Options. See belowType[] superTypes = null: A list of type/interface, the option list types are inhirent from these types. The type in the list is also included in list.string[] onlyAssemblies = null: only use these assembly namesstring[] extraAssemblies = null: extrally add these assemblies to the result listsstring defultSearch = "": input a default search string when opening up the popup
EType:
[Flags] public enum EType { /// <summary> /// Current assembly /// </summary> CurrentOnly = 1, /// <summary> /// Current referenced assemblies. /// </summary> CurrentReferenced = 1 << 1, /// <summary> /// Current & referenced assemblies. /// </summary> Current = CurrentOnly | CurrentReferenced, /// <summary> /// Include "mscorlib" assembly. /// </summary> MsCorLib = 1 << 2, /// <summary> /// Include "System" assembly. /// </summary> System = 1 << 3, /// <summary> /// Include "System.Core" assembly. /// </summary> SystemCore = 1 << 4, /// <summary> /// Anything except "mscorlib", "System", "System.Core" assemblies. /// </summary> NonEssential = 1 << 5, /// <summary> /// All assemblies. /// </summary> AllAssembly = MsCorLib | System | SystemCore | NonEssential, /// <summary> /// Allow non-public types. /// </summary> AllowInternal = 1 << 6, }
Please note: if you have many type options, the big dropdown list will be SLOW.
Example:
using SaintsField; // default using current & referenced assembly public TypeReference typeReference; // current assembly, and group it [TypeReference(EType.CurrentOnly | EType.GroupAssmbly)] [BelowButton(nameof(TestCreate))] public TypeReference typeReference2; private void TestCreate(TypeReference tr) { // you can also use `tr.Type` object t = Activator.CreateInstance(tr); Debug.Log(t); } // all assembly with non-public types, and group it [TypeReference(EType.AllAssembly | EType.AllowInternal)] public TypeReference typeReference3; public interface IMyTypeRef {} private struct MyTypeStruct: IMyTypeRef{} private class MyTypeClass : IMyTypeRef{} // Only types that implement IMyTypeRef [TypeReference(EType.AllAssembly | EType.AllowInternal, superTypes: new[]{typeof(IMyTypeRef)})] public TypeReference typeReferenceOf;

This feature is heavily inspired by ClassTypeReference-for-Unity, please go give them a star!