How to custom inspector with dynamic options (e.g. Light Component)
I'm writing a component that allowed users to choose which kinds of algorithm on the runtime. And each algorithm have some custom options to config.
For example: A light component have 4 types: Spot, Directional, Point, Area and each type have some special options.
Is there any good ideas how to implement this kind of customer inspector? When a user press Play button, the settings of that component must keep the same in the Edit Mode as well
Below is my view of how the Unity Light Component implemented
using UnityEngine;
public class MyLight : MonoBehaviour
{
public interface ILightType
{
void DoCommonThings();
}
public Spot: ILightType
{
int range;
int spotAngle;
public void DoCommonThings()
{
// ...
}
}
public Point: ILightType
{
int range;
public void DoCommonThings()
{
// ...
}
}
ILightType types = new Spot();
// ...
}
The reason why I use ILightType interface is that I think there're some common things to do between each kind of LightType implementation. And I think expose all the LightType specific field in the MyLight class will make MyLight class less readable.
But I don't know how to create a custom inspector to dynamic choose a concrete ILightType implementation and make the on the runtime.
Thank you so much.
Answer by tchindadesire · Jul 18, 2018 at 02:22 PM
maybe this can help someone https://medium.com/@stephen_gou/unity-dynamic-property-field-in-inspector-b1e208223c89