private void SelectMatInfo(SerializedProperty property, Graph_State stateNode, object target) { GraphStateAttribute nodeFilter = (GraphStateAttribute)attribute; property.objectReferenceValue = stateNode; FieldInfo fi = ReflectionUtility.GetField(target, property.name); object oldValue = fi.GetValue(target); property.serializedObject.ApplyModifiedProperties(); // We must apply modifications so that the new value is updated in the serialized object object newValue = fi.GetValue(target); property.serializedObject.Update(); if (stateNode) { EditorGUIUtility.PingObject(stateNode); } MethodInfo callbackMethod = ReflectionUtility.GetMethod(target, nodeFilter.CallbackName); PropertyUtility.InvoKeCallback(callbackMethod, property, target, fieldInfo, oldValue, newValue); }
private void ContextPopUp(Rect position, SerializedProperty property, GUIContent label) { // Throw error on wrong type if (property.propertyType != SerializedPropertyType.ObjectReference) { throw new ArgumentException("Parameter selected must be of type System.Enum"); } // Add label // position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); EditorGUI.BeginChangeCheck(); // Store old indent level and set it to 0, the PrefixLabel takes care of it position = EditorGUI.PrefixLabel(position, label); //int indent = EditorGUI.indentLevel; //EditorGUI.indentLevel = 0; Rect buttonRect = position; Rect buttonGo = position; string buttonLabel = "Select"; Graph_State currentStateGraph = property.objectReferenceValue as Graph_State; if (currentStateGraph != null) { buttonRect.width -= 30; buttonRect.position = new Vector2(position.x + 30, position.y); buttonGo.width = 30; buttonLabel = currentStateGraph.name; } if (GUI.Button(buttonRect, buttonLabel)) { GraphStateAttribute attr = (GraphStateAttribute)attribute; if (attr.UseNodeEnum) { NodeEditorWindow.current.onLateGUI += () => ShowContextMenuAtMouse(property, currentStateGraph); } else { ShowContextMenuAtMouse(property, currentStateGraph); } } if (currentStateGraph != null) { if (GUI.Button(buttonGo, gotoIcon)) { EditorGUIUtility.PingObject(currentStateGraph); NodeEditorWindow.Open(currentStateGraph); Selection.activeObject = currentStateGraph; } } // position.x += buttonRect.width + 4; // position.width -= buttonRect.width + 4; //EditorGUI.ObjectField(position, property, typeof(StateNode), GUIContent.none); if (EditorGUI.EndChangeCheck()) { property.serializedObject.ApplyModifiedProperties(); } //EditorGUI.indentLevel = indent; }