TylerTemp / SaintsField

A Unity Inspector extension tool focusing on script fields inspector enhancement
MIT License
148 stars 9 forks source link

pick a component of interface? #46

Closed laurentopia closed 1 month ago

laurentopia commented 1 month ago

Is this possible? image image I'm getting that image

TylerTemp commented 1 month ago

Hi,

Correct me if I'm wrong: SerializeReference does not work with a pure Interface.

A way to do it is SaintsInterface. See related document for more information.

public class MCPhysicsRelay: MonoBehaviour
{
    public SaintsInterface<UnityEngine.Object, IPhysicsReceiver> receiver1;

    // For old Unity, inherit to a non-generic class first
    [Serializable]
    public class PhysicsReceiverInterface : SaintsInterface<UnityEngine.Object, IPhysicsReceiver> { }
    public PhysicsReceiverInterface receiver2;

    // this also works with the GetComponent* decorators
    [GetComponentInChildren] public PhysicsReceiverInterface receiver3;

    // at this point it does not work with `RequireType` but I'm working on it

    private void Awake()
    {
        Debug.Log(receiver3.I);  // get the actual interface
    }
}

image

TylerTemp commented 1 month ago

Hi, this issue is closed as answered. If you still have related issue, please comment below and I'll open it again