public override void OnInspectorGUI() { Graphmesh modifier = target as Graphmesh; modifier.nodeGraph = EditorGUILayout.ObjectField("Node Graph", modifier.nodeGraph, typeof(GraphmeshNodeGraph), true) as GraphmeshNodeGraph; //Display exposed inputs if (modifier.nodeGraph != null) { //Get all exposed inputs ExposedInput[] inputNodes = modifier.nodeGraph.nodes.Where(x => x is ExposedInput).Select(x => x as ExposedInput).ToArray(); for (int i = 0; i < inputNodes.Length; i++) { ExposedInput inputNode = inputNodes[i]; System.Type inputType = inputNode.GetOutputType(); //If inputType is null, it means the ExposedInput node isn't connected. Don't display it. if (inputType == null) { continue; } Object obj = modifier.outputCache.GetCachedObject(inputNode, "value") as Object; EditorGUI.BeginChangeCheck(); obj = EditorGUILayout.ObjectField(inputNode.label, obj, inputNode.GetOutputType(), true); if (EditorGUI.EndChangeCheck()) { modifier.outputCache.Cache(inputNode, obj, "value"); } } } GUILayout.Space(20); displayDefaultInspector = EditorGUILayout.Toggle("Default Inspector", displayDefaultInspector); if (displayDefaultInspector) { base.OnInspectorGUI(); } }
public override void OnInspectorGUI() { Graphmesh.Graphmesh graphmesh = target as Graphmesh.Graphmesh; graphmesh.graph = EditorGUILayout.ObjectField("Node Graph", graphmesh.graph, typeof(GraphmeshGraph), true) as GraphmeshGraph; GUILayout.Space(20); //Display exposed inputs if (graphmesh.graph != null) { //Get all exposed inputs ExposedInput[] inputNodes = graphmesh.graph.nodes.Where(x => x is ExposedInput).Select(x => x as ExposedInput).ToArray(); for (int i = 0; i < inputNodes.Length; i++) { //We do this by modifying one node field directly and then copying the result to the other nodes EditorGUI.BeginChangeCheck(); ExposedInput inputNode = inputNodes[i]; NodePort port = inputNode.GetOutputPort("value"); NodePort targetPort = port.Connection; if (targetPort == null) { continue; } Node targetNode = targetPort.node; SerializedObject targetSo = new SerializedObject(targetNode); SerializedProperty targetProperty = targetSo.FindProperty(targetPort.fieldName); if (inputNode.GetOutputType().IsSubclassOf(typeof(Object))) { Object obj = graphmesh.outputCache.GetCachedObject(inputNode, "value"); obj = EditorGUILayout.ObjectField(inputNode.label, obj, inputNode.GetOutputType(), true); if (EditorGUI.EndChangeCheck()) { graphmesh.outputCache.Cache(inputNode, obj, "value"); if (NodeEditor.onUpdateNode != null) { NodeEditor.onUpdateNode(inputNode); } } } else { EditorGUILayout.PropertyField(targetProperty, new GUIContent(inputNode.label), true); targetSo.ApplyModifiedProperties(); if (EditorGUI.EndChangeCheck()) { object newValue = targetNode.GetType().GetField(targetProperty.propertyPath).GetValue(targetNode); if (newValue is int) { graphmesh.outputCache.Cache(inputNode, (int)newValue, "value"); } else if (newValue is string) { graphmesh.outputCache.Cache(inputNode, (string)newValue, "value"); } else if (newValue is float) { graphmesh.outputCache.Cache(inputNode, (float)newValue, "value"); } else if (newValue is bool) { graphmesh.outputCache.Cache(inputNode, (bool)newValue, "value"); } if (NodeEditor.onUpdateNode != null) { NodeEditor.onUpdateNode(inputNode); } } } } } GUILayout.Space(20); displayDefaultInspector = EditorGUILayout.Toggle("Default Inspector", displayDefaultInspector); if (displayDefaultInspector) { base.OnInspectorGUI(); } }