private void DrawElement (Rect rect, int index, bool isActive, bool isFocused) { var item = (Variable)list.list[index]; var width = rect.width; var height = rect.height; rect.y += EditorGUIUtility.standardVerticalSpacing; rect.height = EditorGUIUtility.singleLineHeight; XGUI.ResetToStyle(GUI.skin.label); XGUI.RichText = true; var str = item.Value == null ? null : item.Value.TypeString; XGUI.Label(rect, string.Format("<b>{0}</b> <i>{1}</i>", item.Name, str)); rect.y += rect.height + EditorGUIUtility.standardVerticalSpacing; rect.height = height - EditorGUIUtility.singleLineHeight - EditorGUIUtility.standardVerticalSpacing * 4; EditorGUI.BeginChangeCheck(); var type = item.Value == null ? null : Type.GetType(item.Value.TypeString); if (type != null) { if (typeof(UnityEngine.Object).IsAssignableFrom(type)) { item.Value.Value = EditorGUI.ObjectField(rect, (UnityEngine.Object)item.Value.Value, type, true); } else { var oldValue = item.Value.Value; var newValue = GUIExtension.DrawField(rect, oldValue, type, XGUI.None, true); item.Value.Value = newValue; } } else { XGUI.ResetToStyle(GUI.skin.label); XGUI.Enabled = false; XGUI.TextField(rect, "Unknown Type"); } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(editor.Graph); } }
public override void OnGUI (Rect rect, SerializedProperty prop, GUIContent label) { rect.height = EditorGUIUtility.singleLineHeight; var typeLabel = new GUIContent(label.text + " Type"); var valueLabel = new GUIContent(label.text + " Value"); var typeStr = prop.FindPropertyRelative("typeStr"); var type = Type.GetType(typeStr.stringValue); EditorGUI.PropertyField(rect, typeStr, typeLabel); rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; if (type != null) { if (typeof(UnityEngine.Object).IsAssignableFrom(type)) { var obj = prop.FindPropertyRelative("obj"); EditorGUI.ObjectField(rect, obj, type); } else { var strProp = prop.FindPropertyRelative("str"); var str = strProp.stringValue; var oldValue = DynamicValue.DeserializeValue(str, type); var newValue = GUIExtension.DrawField(rect, oldValue, type, valueLabel, true); if (newValue != oldValue) { strProp.stringValue = DynamicValue.SerializeValue(newValue); } } } else { GUI.enabled = false; EditorGUI.TextField(rect, valueLabel, "Unknown Type"); GUI.enabled = true; } prop.serializedObject.ApplyModifiedProperties(); }