void SetValueOfReference(T value) { GenericVariable <T> refObj = GenericVariable <T> .GetAsType(Variable); if (refObj != null) { refObj.Value = value; } }
T GetValueFromReference() { GenericVariable <T> refObj = GenericVariable <T> .GetAsType(Variable); if (refObj != null) { //if (refObj.Value) try { return((T)refObj.Value); } catch { return(default(T)); } } else { return(default(T)); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (dropdownStyle == null) { dropdownStyle = GUI.skin.FindStyle("PaneOptions"); dropdownStyle.imagePosition = ImagePosition.ImageOnly; } //Create string to show variable asset's value bool useConstant = property.FindPropertyRelative(PARAM_USECONSTANTBOOL).boolValue; GenericVariable varObj = (GenericVariable)property.FindPropertyRelative(PARAM_VARIABLE).objectReferenceValue; string valueString = "--"; if (varObj != null) { if (varObj.Value != null) { valueString = varObj.Value.ToString(); } } string useVariableLabel = string.Format(useVariableLabelFormat, valueString); //Using BeginProperty / EndProperty on the parent property means that prefab override logic works on the entire property. EditorGUI.BeginProperty(position, label, property); position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); int indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; //Don't make child fields be indented //Field sizes float dropdownWidth = 20; Rect valueRect = new Rect(position.x + dropdownWidth, position.y, position.width - dropdownWidth, position.height); Rect dropdownRect = new Rect(position.x, position.y, dropdownWidth, position.height); dropdownRect.yMin += dropdownStyle.margin.top; dropdownRect.width = dropdownStyle.fixedWidth + dropdownStyle.margin.right; position.xMin = dropdownRect.xMax; //Draw dropdown if (EditorGUI.DropdownButton(dropdownRect, new GUIContent(), FocusType.Passive, dropdownStyle)) { //Create generic menu GenericMenu menu = new GenericMenu(); AddMenuItem(menu, useConstantLabel, new MenuObject(property, PARAM_USECONSTANTBOOL, 0, true)); AddMenuItem(menu, useVariableLabel, new MenuObject(property, PARAM_USECONSTANTBOOL, 0, false)); menu.ShowAsContext(); } //Draw fields based on dropdown value if (useConstant) { SerializedProperty sp = property.FindPropertyRelative(PARAM_CONSTANTVALUE); if (sp.propertyType == SerializedPropertyType.Float) { sp.floatValue = EditorGUI.FloatField(valueRect, sp.floatValue); } else if (sp.propertyType == SerializedPropertyType.Integer) { sp.intValue = EditorGUI.IntField(valueRect, sp.intValue); } else if (sp.propertyType == SerializedPropertyType.String) { sp.stringValue = EditorGUI.TextField(valueRect, sp.stringValue); } else if (sp.propertyType == SerializedPropertyType.Boolean) { sp.boolValue = EditorGUI.Toggle(valueRect, sp.boolValue); } else { Debug.LogWarning("Unimplemented constant variable type: " + sp.propertyType.ToString()); } } else { EditorGUI.PropertyField(valueRect, property.FindPropertyRelative(PARAM_VARIABLE), GUIContent.none); } //Reset indent EditorGUI.indentLevel = indent; EditorGUI.EndProperty(); }