private void SetDefaultValue(SerializedProperty serializedInput) { Type nodeInputType = SerializedPropertyUtils.GetSerializedPropertyType(serializedInput); NodeGraphComponent nodeGraphComponent = (NodeGraphComponent)target; //Default Transform nodes to this GameObject's Transform if (nodeInputType == typeof(NodeGraphComponent.TransformInput)) { DynamicTransformRef transformRef = nodeGraphComponent.transform; SerializedProperty valueProp = serializedInput.FindPropertyRelative("_valueSource"); SerializedPropertyUtils.SetSerializedPropertyValue(valueProp, transformRef); } //Default Material nodes to this GameObject's Renderer's material else if (nodeInputType == typeof(NodeGraphComponent.MaterialInput)) { Renderer renderer = nodeGraphComponent.GetComponent <Renderer>(); if (renderer != null) { DynamicMaterialRef materialRef = DynamicMaterialRef.InstancedMaterialRef(renderer); SerializedProperty valueProp = serializedInput.FindPropertyRelative("_valueSource"); SerializedPropertyUtils.SetSerializedPropertyValue(valueProp, materialRef); } } //Default GameObject nodes to this GameObject else if (nodeInputType == typeof(NodeGraphComponent.GameObjectInput)) { DynamicGameObjectRef gameObjectRef = nodeGraphComponent.gameObject; SerializedProperty valueProp = serializedInput.FindPropertyRelative("_valueSource"); SerializedPropertyUtils.SetSerializedPropertyValue(valueProp, gameObjectRef); } }
void OnEnable() { NodeGraphComponent nodeGraphComponent = (NodeGraphComponent)target; _unscaledTime = serializedObject.FindProperty("_unscaledTime"); _runInEditor = serializedObject.FindProperty("_runInEditor"); _nodeGraphRef = serializedObject.FindProperty("_nodeGraphRef"); _nodeGraphRefAsset = _nodeGraphRef.FindPropertyRelative("_file"); _floatInputs = serializedObject.FindProperty("_floatInputs"); _intInputs = serializedObject.FindProperty("_intInputs"); _floatRangeInputs = serializedObject.FindProperty("_floatRangeInputs"); _intRangeInputs = serializedObject.FindProperty("_intRangeInputs"); _vector2Inputs = serializedObject.FindProperty("_vector2Inputs"); _vector3Inputs = serializedObject.FindProperty("_vector3Inputs"); _vector4Inputs = serializedObject.FindProperty("_vector4Inputs"); _quaternionInputs = serializedObject.FindProperty("_quaternionInputs"); _colorInputs = serializedObject.FindProperty("_colorInputs"); _stringInputs = serializedObject.FindProperty("_stringInputs"); _boolInputs = serializedObject.FindProperty("_boolInputs"); _gradientInputs = serializedObject.FindProperty("_gradientInputs"); _animationCurveInputs = serializedObject.FindProperty("_animationCurveInputs"); _transformInputs = serializedObject.FindProperty("_transformInputs"); _gameObjectInputs = serializedObject.FindProperty("_gameObjectInputs"); _componentInputs = serializedObject.FindProperty("_componentInputs"); _materialInputs = serializedObject.FindProperty("_materialInputs"); _textureInputs = serializedObject.FindProperty("_textureInputs"); if (nodeGraphComponent.GetNodeGraph() == null) { nodeGraphComponent.LoadNodeGraph(); } _nodeGraph = nodeGraphComponent.GetNodeGraph(); }
private void RenderInputArray(NodeGraphComponent nodeGraphComponent, SerializedProperty inputArrayProperty, ref bool foldout) { if (inputArrayProperty != null && inputArrayProperty.arraySize > 0) { foldout = EditorGUILayout.Foldout(foldout, inputArrayProperty.displayName); if (foldout) { EditorGUI.indentLevel++; for (int i = 0; i < inputArrayProperty.arraySize; i++) { SerializedProperty serializedInput = inputArrayProperty.GetArrayElementAtIndex(i); SerializedProperty nodeIdProp = serializedInput.FindPropertyRelative("_nodeId"); Node node = _nodeGraph.GetNode(nodeIdProp.intValue); SerializedProperty arrayItem = inputArrayProperty.GetArrayElementAtIndex(i); SerializedProperty prop = arrayItem.FindPropertyRelative("_valueSource"); EditorGUILayout.PropertyField(prop, new GUIContent(node._editorDescription)); } EditorGUI.indentLevel--; } } }
public override void OnInspectorGUI() { EditorGUILayout.PropertyField(_unscaledTime); { _nodeGraphRefFoldOut = EditorGUILayout.Foldout(_nodeGraphRefFoldOut, "Node Graph"); if (_nodeGraphRefFoldOut) { int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(_nodeGraphRefAsset); if (EditorGUI.EndChangeCheck()) { SyncInputNodes(new Node[0]); serializedObject.ApplyModifiedProperties(); ReloadNodeGraph(); } if (!_nodeGraphRefAsset.hasMultipleDifferentValues) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(GUIContent.none, GUILayout.Width(EditorUtils.GetLabelWidth())); if (GUILayout.Button("Edit")) { NodeGraphEditorWindow.Load(_nodeGraphRefAsset.objectReferenceValue as TextAsset); } else if (GUILayout.Button("Refresh")) { ReloadNodeGraph(); } } EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel = origIndent; } } if (_nodeGraph != null && !_nodeGraphRefAsset.hasMultipleDifferentValues) { _inputsFoldOut = EditorGUILayout.Foldout(_inputsFoldOut, "Inputs"); if (_inputsFoldOut) { int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; Node[] inputNodes = _nodeGraph.GetInputNodes(); SyncInputNodes(inputNodes); foreach (Node inputNode in inputNodes) { RenderInputNode(inputNode); } EditorGUI.indentLevel = origIndent; } _outputsFoldOut = EditorGUILayout.Foldout(_outputsFoldOut, "Outputs"); if (_outputsFoldOut) { int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; Node[] outputNodes; NodeGraphComponent nodeGraphComponent = (NodeGraphComponent)target; //Is the application is running then get the output node directly from the component so can see the live value if (Application.isPlaying && nodeGraphComponent.GetOutputNodes() != null) { outputNodes = nodeGraphComponent.GetOutputNodes(); } else { outputNodes = _nodeGraph.GetOutputNodes(); } foreach (Node outputNode in outputNodes) { RenderOutputNode(outputNode); } EditorGUI.indentLevel = origIndent; } } serializedObject.ApplyModifiedProperties(); }
private void ReloadNodeGraph() { NodeGraphComponent nodeGraphComponent = (NodeGraphComponent)target; _nodeGraph = nodeGraphComponent._nodeGraphRef.LoadNodeGraph(); }
public override void OnInspectorGUI() { NodeGraphComponent nodeGraphComponent = (NodeGraphComponent)target; EditorGUILayout.PropertyField(_unscaledTime); { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(_runInEditor); if (EditorGUI.EndChangeCheck() && _runInEditor.boolValue) { nodeGraphComponent.LoadNodeGraph(); _nodeGraph = nodeGraphComponent.GetNodeGraph(); } } { _nodeGraphRefOut = EditorGUILayout.Foldout(_nodeGraphRefOut, "Node Graph"); if (_nodeGraphRefOut) { int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(_nodeGraphRefAsset); if (EditorGUI.EndChangeCheck()) { SyncInputNodes(new Node[0]); serializedObject.ApplyModifiedProperties(); nodeGraphComponent.LoadNodeGraph(); _nodeGraph = nodeGraphComponent.GetNodeGraph(); } EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(GUIContent.none, GUILayout.Width(EditorGUIUtility.labelWidth - (EditorGUI.indentLevel * 15.0f) + 11)); if (GUILayout.Button("Edit")) { NodeGraphEditorWindow.Load(_nodeGraphRefAsset.objectReferenceValue as TextAsset); } else if (GUILayout.Button("Refresh")) { nodeGraphComponent.LoadNodeGraph(); _nodeGraph = nodeGraphComponent.GetNodeGraph(); } } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel = origIndent; } } if (_nodeGraph != null) { _inputsFoldOut = EditorGUILayout.Foldout(_inputsFoldOut, "Inputs"); if (_inputsFoldOut) { int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; Node[] inputNodes = _nodeGraph.GetInputNodes(); //First sync nodes with objects in _inputObjects SyncInputNodes(inputNodes); RenderInputArray(nodeGraphComponent, _floatInputs, ref _floatsInputsFoldOut); RenderInputArray(nodeGraphComponent, _intInputs, ref _intInputsFoldOut); RenderInputArray(nodeGraphComponent, _floatRangeInputs, ref _floatRangeInputsFoldOut); RenderInputArray(nodeGraphComponent, _intRangeInputs, ref _intRangeInputsFoldOut); RenderInputArray(nodeGraphComponent, _vector2Inputs, ref _vector2InputsFoldOut); RenderInputArray(nodeGraphComponent, _vector3Inputs, ref _vector3InputsFoldOut); RenderInputArray(nodeGraphComponent, _vector4Inputs, ref _vector4InputsFoldOut); RenderInputArray(nodeGraphComponent, _quaternionInputs, ref _quaternionInputsFoldOut); RenderInputArray(nodeGraphComponent, _colorInputs, ref _colorInputsFoldOut); RenderInputArray(nodeGraphComponent, _stringInputs, ref _stringInputsFoldOut); RenderInputArray(nodeGraphComponent, _boolInputs, ref _boolInputsFoldOut); RenderInputArray(nodeGraphComponent, _gradientInputs, ref _gradientInputsFoldOut); RenderInputArray(nodeGraphComponent, _animationCurveInputs, ref _animationCurveInputsFoldOut); RenderInputArray(nodeGraphComponent, _transformInputs, ref _transformInputsFoldOut); RenderInputArray(nodeGraphComponent, _gameObjectInputs, ref _gameObjectInputsFoldOut); RenderInputArray(nodeGraphComponent, _componentInputs, ref _componentInputsFoldOut); RenderInputArray(nodeGraphComponent, _materialInputs, ref _materialInputsFoldOut); RenderInputArray(nodeGraphComponent, _textureInputs, ref _textureInputsFoldOut); EditorGUI.indentLevel = origIndent; } } serializedObject.ApplyModifiedProperties(); }