예제 #1
0
        public SerializedNode AddNode(AbstractLogicNodeEditor logicNodeEditor)
        {
            _logicGraphEditorObject.RegisterCompleteObjectUndo("Add Node " + logicNodeEditor.NodeType());

            SerializedNode serializedNode = new SerializedNode
            {
                NodeType = logicNodeEditor.NodeType(),
                JSON     = JsonUtility.ToJson(logicNodeEditor)
            };

            logicNodeEditor.SerializedNode = serializedNode;
            if (logicNodeEditor is IInputNode)
            {
                _logicGraphEditorObject.LogicGraphData.SerializedInputNodes.Add(serializedNode);
            }
            else if (logicNodeEditor is IOutputNode)
            {
                _logicGraphEditorObject.LogicGraphData.SerializedOutputNodes.Add(serializedNode);
            }
            else
            {
                _logicGraphEditorObject.LogicGraphData.SerializedNodes.Add(serializedNode);
            }

            logicNodeEditor.Owner = _graphView;
            var nodeView = new LogicNodeView {
                userData = logicNodeEditor
            };

            _graphView.AddElement(nodeView);
            nodeView.Initialize(logicNodeEditor, _edgeConnectorListener);
            nodeView.MarkDirtyRepaint();
            return(serializedNode);
        }
        public void AddNode(NodeEditor nodeEditor)
        {
            _logicGraphEditorObject.RegisterCompleteObjectUndo("Add Node " + nodeEditor.NodeType());

            SerializedNode serializedNode = new SerializedNode
            {
                NodeType = nodeEditor.NodeType(),
                JSON     = JsonUtility.ToJson(nodeEditor)
            };

            nodeEditor.SerializedNode = serializedNode;
            if (nodeEditor is IInputNode)
            {
                _logicGraphEditorObject.LogicGraphData.SerializedInputNodes.Add(serializedNode);
            }
            else if (nodeEditor is IOutputNode)
            {
                _logicGraphEditorObject.LogicGraphData.SerializedOutputNodes.Add(serializedNode);
            }
            else
            {
                _logicGraphEditorObject.LogicGraphData.SerializedNodes.Add(serializedNode);
            }

            nodeEditor.Owner = _graphView;
            var nodeView = new LogicNodeView {
                userData = nodeEditor
            };

            _graphView.AddElement(nodeView);
            nodeView.Initialize(nodeEditor, _edgeConnectorListener);
            nodeView.Dirty(ChangeType.Repaint);
        }
예제 #3
0
        private void AddNode(SerializedNode serializedNode)
        {
            AbstractLogicNodeEditor logicNodeEditor = null;

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var type in assembly.GetTypes())
                {
                    if (type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(AbstractLogicNodeEditor)))
                    {
                        var attrs = type.GetCustomAttributes(typeof(NodeEditorType), false) as NodeEditorType[];
                        if (attrs != null && attrs.Length > 0)
                        {
                            if (attrs[0].NodeType.Name == serializedNode.NodeType)
                            {
                                logicNodeEditor = (AbstractLogicNodeEditor)Activator.CreateInstance(type);
                            }
                        }
                    }
                }
            }

            if (logicNodeEditor != null)
            {
                JsonUtility.FromJsonOverwrite(serializedNode.JSON, logicNodeEditor);
                logicNodeEditor.SerializedNode = serializedNode;
                logicNodeEditor.Owner          = _graphView;
                var nodeView = new LogicNodeView {
                    userData = logicNodeEditor
                };
                _graphView.AddElement(nodeView);
                nodeView.Initialize(logicNodeEditor, _edgeConnectorListener);
                nodeView.MarkDirtyRepaint();
            }
            else
            {
                Debug.LogWarning("No NodeEditor found for " + serializedNode);
            }
        }