Exemplo n.º 1
0
        // called by the BaseGraph when the node is added to the graph
        public void Initialize(BaseGraph graph)
        {
            this.graph = graph;

            ExceptionToLog.Call(() => Enable());
            inputPorts  = new NodeInputPortContainer(this);
            outputPorts = new NodeOutputPortContainer(this);
            nodeFields  = new Dictionary <string, NodeFieldInformation>();
            customPortTypeBehaviorMap = new Dictionary <Type, CustomPortTypeBehaviorDelegate>();

            InitializeInOutDatas();
            InitializePorts();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 只有两种情况会调用到这个函数
        /// 1.打开GraphEditorWindow(初次打开或者在已经打开的基础上更换GraphAsset)
        /// 2.编译/进入PlayMode而导致的GraphEditorWindow重载
        /// </summary>
        /// <param name="graph"></param>
        public void InitializeGraph(BaseGraph graph)
        {
            if (this.graph != null && graph != this.graph)
            {
                // Save the graph to the disk
                GraphCreateAndSaveHelper.SaveGraphToDisk(this.graph);
                // Unload the graph
                graphUnloaded?.Invoke(this.graph);
            }

            graphLoaded?.Invoke(graph);
            this.graph = graph;

            if (graphView != null)
            {
                rootView.Remove(graphView);
            }

            InitializeWindow(graph);
            rootView.Add(graphView);

            graphView = rootView.Children().FirstOrDefault(e => e is BaseGraphView) as BaseGraphView;

            if (graphView == null)
            {
                Debug.LogError("GraphView has not been added to the BaseGraph root view !");
                return;
            }

            graphView.Initialize(graph);

            InitializeGraphView(graphView);

            // TOOD: onSceneLinked...

            if (graph.IsLinkedToScene())
            {
                LinkGraphWindowToScene(graph.GetLinkedScene());
            }
            else
            {
                graph.onSceneLinked += LinkGraphWindowToScene;
            }
            //防止在外部调用InitializeGraph时重复执行InitializeGraph
            reloadWorkaround = false;
        }
Exemplo n.º 3
0
        public void Initialize(BaseGraph graph)
        {
            if (this.graph != null)
            {
                SaveGraphToDisk();
            }

            this.graph = graph;

            connectorListener = new EdgeConnectorListener(this);

            InitializeNodeViews();
            InitializeEdgeViews();
            InitializeViews();
            InitializeCommentBlocks();

            UpdateComputeOrder();
        }
        public void InitializeGraph(BaseGraph graph)
        {
            this.graph = graph;

            if (graphView != null)
            {
                rootView.Remove(graphView);
            }

            //Initialize will provide the BaseGraphView
            Initialize(graph);

            graphView = rootView.Children().FirstOrDefault(e => e is BaseGraphView) as BaseGraphView;

            if (graphView == null)
            {
                Debug.LogError("GraphView has not been added to the BaseGraph root view !");
                return;
            }

            graphView.Initialize(graph);
        }
Exemplo n.º 5
0
        PushDataDelegate CreatePushDataDelegateForEdge(SerializableEdge edge)
        {
            try
            {
                //Creation of the delegate to move the data from the input node to the output node:
                FieldInfo inputField  = edge.inputNode.GetType().GetField(edge.inputFieldName, BindingFlags.Public | BindingFlags.Instance);
                FieldInfo outputField = edge.outputNode.GetType().GetField(edge.outputFieldName, BindingFlags.Public | BindingFlags.Instance);

// We keep slow checks inside the editor
#if UNITY_EDITOR
                if (!BaseGraph.TypesAreConnectable(inputField.FieldType, outputField.FieldType))
                {
                    Debug.LogError("Can't convert from " + inputField.FieldType + " to " + outputField.FieldType + ", you must specify a custom port function (i.e CustomPortInput or CustomPortOutput) for non-implicit convertions");
                }
#endif

                // TODO: TypeAdapter convertion method here

                Expression inputParamField  = Expression.Field(Expression.Constant(edge.inputNode), inputField);
                Expression outputParamField = Expression.Field(Expression.Constant(edge.outputNode), outputField);

                // If there is a user defined convertion function, then we call it
                if (TypeAdapter.AreAssignable(outputField.FieldType, inputField.FieldType))
                {
                    outputParamField = Expression.Call(TypeAdapter.GetConvertionMethod(outputField.FieldType, inputField.FieldType), outputParamField);
                }
                else                 // otherwise we cast
                {
                    outputParamField = Expression.Convert(outputParamField, inputField.FieldType);
                }

                BinaryExpression assign = Expression.Assign(inputParamField, outputParamField);
                return(Expression.Lambda <PushDataDelegate>(assign).Compile());
            } catch (Exception e) {
                Debug.LogError(e);
                return(null);
            }
        }
Exemplo n.º 6
0
        // called by the BaseGraph when the node is added to the graph
        public void Initialize(BaseGraph graph)
        {
            this.graph = graph;

            Enable();

            foreach (var nodeFieldKP in nodeFields)
            {
                var nodeField = nodeFieldKP.Value;

                if (nodeField.behavior != null)
                {
                    UpdatePortsForField(nodeField.fieldName);
                }
                else
                {
                    // If we don't have a custom behavor on the node, we just have to create a simple port
                    AddPort(nodeField.input, nodeField.fieldName, new PortData {
                        acceptMultipleEdges = nodeField.isMultiple, displayName = nodeField.name
                    });
                }
            }
        }
Exemplo n.º 7
0
        // called by the BaseGraph when the node is added to the graph
        public void Initialize(BaseGraph graph)
        {
            this.graph = graph;

            Enable();
        }
 protected virtual void OnEnable()
 {
     graph = target as BaseGraph;
     graph.onExposedParameterListChanged += UpdateExposedParameters;
     graph.onExposedParameterModified    += UpdateExposedParameters;
 }
 /// <summary>
 /// Manage graph scheduling and processing
 /// </summary>
 /// <param name="graph">Graph to be processed</param>
 public ProcessGraphProcessor(BaseGraph graph) : base(graph)
 {
 }