Wanzyee Studio
PopupMenuAttribute

UnityEngine.PropertyAttribute to set property by a popup menu. More...

Inherits PropertyAttribute.

Public Member Functions

 PopupMenuAttribute (params object[] values)
 Setup values of the menu. More...
 
 PopupMenuAttribute (bool manual, params object[] values)
 Setup values of the menu. More...
 
 PopupMenuAttribute (object[] values, string[] options, bool manual=false)
 Setup values and option names of the menu, show object.ToString() if an option is empty. More...
 

Public Attributes

readonly bool manual
 Whether if to allow manual editing. More...
 
readonly object[] values
 Values to select on menu. More...
 
readonly string[] options
 Option names to display on menu. More...
 

Detailed Description

UnityEngine.PropertyAttribute to set property by a popup menu.

Only support types assignable to attribute, or deserializable by UnityEngine.JsonUtility. Any specified option value can't be null.

Note, this doesn't accept class, reference type, even serializable. 'Coz a reference value mustn't be directly assigned in, but generated by deserializing. It means the reference is changed everytime when the drawer was constructed. And, this sets the property to the first option and logs warning if the value isn't included. That happens when an invalid value is left in serialize system after script reload.

Declaring examples below, even used for UnityEngine.Color32, or UnityEngine.Vector3, etc.

[PopupMenu("One", "Two", "Whatever", "More'n'More")]
public string text;
[PopupMenu(true, 0.1, 0.02, 0.03f)]
public float number;
[PopupMenu("{\"r\":0,\"g\":0,\"b\":0,\"a\":255}", "{\"r\":255,\"g\":255,\"b\":255,\"a\":255}")]
public Color32 color;
[PopupMenu(
new object[]{"{\"x\":1,\"y\":0,\"z\":0}", "{\"x\":0,\"y\":1,\"z\":0}", "{\"x\":0,\"y\":0,\"z\":1}"},
new string[]{"Right", "Up", "Forward"}
)]
public Vector3 axis;

It may become simpler if you implement WanzyeeStudio.Converter.BaseStringConverter:

[PopupMenu("(1, 0)", "(-1, 0)", "(0, 1)", "(0, -1)")]
public Vector2 face;
[PopupMenu(
new object[]{"(0, 0, 4, 3)", "(0, 0, 8, 6)", "(0, 0, 16, 12)"},
new string[]{"Small", "Medium", "Large"}
)]
public Rect box;

Constructor & Destructor Documentation

PopupMenuAttribute ( params object[]  values)

Setup values of the menu.

Parameters
valuesValues to select on menu.
Returns
The instance.
PopupMenuAttribute ( bool  manual,
params object[]  values 
)

Setup values of the menu.

Parameters
manualWhether if to allow manual editing.
valuesValues to select on menu.
Returns
The instance.
PopupMenuAttribute ( object[]  values,
string[]  options,
bool  manual = false 
)

Setup values and option names of the menu, show object.ToString() if an option is empty.

Parameters
valuesValues to select on menu.
optionsOption names to display on menu.
manualWhether if to allow manual editing.
Returns
The instance.

Member Data Documentation

readonly bool manual

Whether if to allow manual editing.

readonly object [] values

Values to select on menu.

readonly string [] options

Option names to display on menu.