void DrawNodeProperty(NodeContainer container) { NodeBase node = container.node; if (serializedObject != null) { string[] subTypes = NodeMaker.Instance.GetSubTypes(node.nodeType); int curIndex = 0; for (int i = 0; i < subTypes.Length; i++) { if (subTypes[i] == node.subType) { curIndex = i; } } int newIndex = EditorGUILayout.Popup("Node Type", curIndex, subTypes); if(newIndex != curIndex) { NodeBase newNode = NodeMaker.Instance.CreateNode(node.nodeType, subTypes[newIndex]); newNode.name = node.name; for(int i = 0; i<node.inputs.Length; i++) { newNode.inputs[i] = node.inputs[i]; } foreach(var n in nodeContainers) { for(int i =0; i<n.node.inputs.Length; i++) { if(n.node.inputs[i] == node) { n.node.inputs[i] = newNode; } } } container.SetNode(newNode); } if (SerializedObjectDrawer.DrawProperty(serializedObject)) { //Repaint(); } } }
public void OnEnable() { if (nodeContainers.Count == 0) { NodeContainer height = new NodeContainer(); height.SetNode(NodeMaker.Instance.CreateNode(NodeType.Output)); height.rect = new Rect(-200, -120, 128, 128 + 16); nodeContainers.Add(height); NodeContainer perlin = new NodeContainer(); perlin.SetNode(NodeMaker.Instance.CreateNode(NodeType.Generator, "Perlin Noise")); perlin.rect = new Rect(100, -120, 128, 128 + 16); nodeContainers.Add(perlin); height.node.inputs[0] = perlin.node; } }
void AddNode(NodeBase node,Vector2 pos) { node.name = getNewName(node.name); NodeContainer c = ScriptableObject.CreateInstance<NodeContainer>(); c.SetNode(node); c.winID = getNewWinID(); c.rect = new Rect(pos + scrollPosition - new Vector2(workspaceWidth/2,workspaceHeight/2), new Vector2(128, 128 + 16)); c.rect.x = (int)c.rect.x; c.rect.y = (int)c.rect.y; c.container = target; nodeContainers.Add(c); target.Sort(); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); }