public override void OnBodyGUI() { ExposedInput node = target as ExposedInput; EditorGUILayout.PropertyField(serializedObject.FindProperty("label")); Type type = node.GetOutputType(); string typeName = type != null?type.ToString() : "Not set"; NodeEditorGUILayout.PortField(new GUIContent(typeName, typeName), node.GetOutputPort("value")); }
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(); } }