- Home /
Question by
Shiver · Sep 09, 2014 at 05:52 AM ·
editorserializationcustom-inspectorpropertydrawer
Select a readonly value from dropdown using PropertyDrawers
I'm wondering if it's possible to use PropertyDrawers to select a value from a dropdown to assign a property's value to be that of a readonly static variable.
Example, say I have a CustomColor type which has a bunch of static readonly CustomColors (colors used for simplicity)
class CustomColor
{
static public readonly CustomColor RED = new CustomColor(255, 0, 0);
static public readonly CustomColor BLUE = new CustomColor(0, 0, 255);
}
I would like to create a PropertyDrawer so that whenever I expose a CustomColor to the editor via SerializableProperty, that it generates a dropdown which allows the user to select between RED and BLUE and that the property becomes set to the static readonly instance of that object once the object is loaded.
//somewhere inside a serializable object
[SerializableField]
public CustomColor myColor;//editor should allow only either RED or BLUE;
I currently can get a dropdown via EditorGUI.PopUp but I cannot get the myColor variable to reference the same instance as RED.
Comment