Пример #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.Dirty(ChangeType.Repaint);
            return(serializedNode);
        }
Пример #2
0
        private void AddNodeFromload(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.Dirty(ChangeType.Repaint);
            }
            else
            {
                Debug.LogWarning("No NodeEditor found for " + serializedNode);
            }
        }