Skip to content

Unity property drawer to chose implementation in inspector for SerializeReference field

License

Notifications You must be signed in to change notification settings

unitycoder/Select-implementation-property-drawer

 
 

Repository files navigation

Select-implementation-property-drawer

Unity property drawer to choose implementation in an inspector for marked field as SerializeReference.

Example

Code

using UnityEngine;
using System;

public interface IMyInterface { }

[Serializable]
public class MyImplementInterfaceClass : IMyInterface { public int myImplementInterfaceClass; }

public abstract class MyAbstractClass { public string myAbstractClass; }

[Serializable]
public class MyInheritedFromAbstractClass : MyAbstractClass { public float myInheritedFromAbstractClass; }

[Serializable]
public class MyInheritedFromAbstractClassAndInterface : MyAbstractClass, IMyInterface { public bool myInheritedFromAbstractClassAndInterface; }

public class SelectIimplementationDrawerExample : MonoBehaviour
{
    [SerializeReference, SelectImplementation(typeof(IMyInterface))]
    public IMyInterface interfaceField;
    
    [SerializeReference, SelectImplementation(typeof(MyAbstractClass))]
    public MyAbstractClass abstractClassField;
}

And in the inspector it will be like that

Installation

You can install this package via Package manager by link to the current repo https://github.com/medvedya/Select-implementation-property-drawer.git

About

Unity property drawer to chose implementation in inspector for SerializeReference field

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%