예제 #1
0
        public void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            if (variableSceneTypes.Keys.Count == 0 || variableSceneTypes == null)
            {
                GetAvailableVariableTypes.GetFlowReactorVariableTypes(out variableSceneTypes);
            }

            eventBoard = (EventBoard)target;
        }
        public void OnEnable()
        {
            try
            {
                data = (FlowReactor.BlackboardSystem.BlackBoard)target;


                if (variableSceneTypes.Keys.Count == 0 || variableSceneTypes == null)
                {
                    GetAvailableVariableTypes.GetFlowReactorVariableTypes(out variableSceneTypes);
                }

                SetupList();
            }
            catch {}
        }
        void DrawInspectorForNode(Node _node, int _nodeIndex)
        {
            if (editorSkin == null)
            {
                LoadEditorResources();
            }


            if (_node != null)
            {
                if (nodeInspector != null)
                {
                    // when comment node is selected do not use scroll view
                    // it somehow eats all user input from the canvas. Therefore delete button would not work
                    if (_node.nodeData.nodeType == NodeAttributes.NodeType.Comment)
                    {
                    }
                    else
                    {
                        using (var _scrollView = new EditorGUILayout.ScrollViewScope(nodeInspectorScrollPosition))
                        {
                            nodeInspectorScrollPosition = _scrollView.scrollPosition;

                            using (new GUILayout.HorizontalScope("ToolbarButton"))
                            {
                                foldoutNodeInfo = EditorGUILayout.Foldout(foldoutNodeInfo, _node.nodeData.title);
                            }
                            if (foldoutNodeInfo)
                            {
                                using (new GUILayout.VerticalScope("Box"))
                                {
                                    GUILayout.Label("Node type", GUILayout.Width(100));
                                    GUILayout.Label(_node.nodeData.typeName, "TextArea");


                                    GUILayout.Label("Title");

                                    using (new GUILayout.HorizontalScope())
                                    {
                                        if (!editNodeTitle)
                                        {
                                            GUI.enabled          = editNodeTitle;
                                            _node.nodeData.title = GUILayout.TextField(_node.nodeData.title);
                                            GUI.enabled          = true;

                                            if (GUILayout.Button(editIcon, GUILayout.Width(20), GUILayout.Height(20)))
                                            {
                                                editNodeTitle = true;
                                                newNodeTitle  = _node.nodeData.title;
                                            }
                                        }
                                        else
                                        {
                                            newNodeTitle = GUILayout.TextField(newNodeTitle);

                                            if (!string.IsNullOrEmpty(newNodeTitle))
                                            {
                                                if (GUILayout.Button(okIcon, GUILayout.Width(20), GUILayout.Height(20)))
                                                {
                                                    if (rootGraph.exposedNodeVariables.ContainsKey(_node.nodeData.title))
                                                    {
                                                        // Update node title and exposed variables
                                                        if (!rootGraph.exposedNodeVariables.ContainsKey(newNodeTitle))
                                                        {
                                                            rootGraph.exposedNodeVariables.UpdateKey(_node.nodeData.title, newNodeTitle);

                                                            _node.nodeData.title = newNodeTitle;

                                                            List <FRVariable> _nodeVariables = new List <FRVariable>();
                                                            FlowReactor.Editor.GetAvailableVariableTypes.GetAllFRVariablesOnNode(_node, out _nodeVariables);
                                                            for (int v = 0; v < _nodeVariables.Count; v++)
                                                            {
                                                                if (_nodeVariables[v].type == FRVariable.VariableType.exposed)
                                                                {
                                                                    _nodeVariables[v].exposedNodeName = newNodeTitle;
                                                                }
                                                            }

                                                            editNodeTitle = false;
                                                        }
                                                        else
                                                        {
                                                            if (_node.nodeData.title != newNodeTitle)
                                                            {
                                                                EditorUtility.DisplayDialog("Node title already exists", "Title: " + newNodeTitle + " already exists!" + "\nThis node has exposed variables, therefore the new title must be unique to make sure it does not collide with another exposed node with the same title.", "ok");
                                                                editNodeTitle = false;
                                                            }
                                                            else
                                                            {
                                                                editNodeTitle = false;
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        _node.nodeData.title = newNodeTitle;
                                                    }

                                                    editNodeTitle = false;
                                                }
                                            }

                                            if (GUILayout.Button(cancelIcon, GUILayout.Width(20), GUILayout.Height(20)))
                                            {
                                                editNodeTitle = false;
                                            }
                                        }
                                    }



                                    GUILayout.Label("Description");
                                    _node.nodeData.description = GUILayout.TextArea(_node.nodeData.description, GUILayout.Height(50));

                                    if (GUILayout.Button("Clear"))
                                    {
                                        _node.nodeData.description = "";
                                    }
                                }
                            }

                            // Default node inspector
                                                        #if FLOWREACTOR_DEBUG
                            // Always draw default inspector in debug mode
                            _node.disableDefaultInspector = false;
                            GUI.color = Color.yellow;
                            GUILayout.Label("DEBUG MODE:");
                            GUI.color = Color.white;
                                                        #endif
                            if (!_node.disableDefaultInspector)
                            {
                                EditorHelpers.DrawUILine();
                                using (new GUILayout.VerticalScope(editorSkin.GetStyle("BoxLine")))
                                {
                                    NodeDefaultInspector.DrawDefaultInspectorWithoutScriptField(nodeInspector);
                                    //nodeInspector.DrawDefaultInspector();
                                }
                            }



                            //if (nodeVariableFields == null || nodeVariableFields.Length == 0)
                            //{
                            //	GetAvailableNodeVariables(_node);
                            //}

                            //for (int f = 0; f < nodeVariableFields.Length; f ++)
                            //{
                            //	if (nodeVariableFields[f].FieldType == typeof(FlowReactor.Nodes.Modules.FRNodeEventDispatch))
                            //	{
                            //		GUILayout.Label("EVENTBOARD");
                            //		var _module = nodeVariableFields[f].GetValue(_node) as FlowReactor.Nodes.Modules.FRNodeEventDispatch;
                            //		//_eventBoard = EditorGUILayout.ObjectField(_eventBoard, typeof(EventBoard), false) as EventBoard;

                            //		var _lr = GUILayoutUtility.GetLastRect();

                            //		//nodeVariableFields[f].SetValue(_node, (object)_eventBoard);
                            //		FRNodeEventDispatcherEditor.DrawEditor(_module, _node.rootGraph, _lr);
                            //	}
                            //}


                            if (!_node.disableDrawCustomInspector)
                            {
                                EditorHelpers.DrawUILine();
                                using (new GUILayout.VerticalScope(editorSkin.GetStyle("BoxLine")))
                                {
                                    if (_node != null)
                                    {
                                        _node.DrawCustomInspector();
                                    }
                                }
                            }



                            if (!_node.disableVariableInspector)
                            {
                                EditorHelpers.DrawUILine();
                                using (new GUILayout.VerticalScope(editorSkin.GetStyle("BoxLine")))
                                {
                                    // Get all available variable types
                                    if (variableLocalTypes.Keys.Count == 0 || variableLocalTypes == null)
                                    {
                                        GetAvailableVariableTypes.ReturnExistingTypesOfType <FRVariable>(out variableLocalTypes);
                                    }


                                    GUILayout.Label("Variables:", "boldLabel");


                                    _node.DrawNodeVariables(true);
                                }
                            }

                            GUILayout.Space(25);



                            //using (new GUILayout.HorizontalScope("toolbar"))
                            //{
                            //	selectedInspectorPanelNode = GUILayout.SelectionGrid(selectedInspectorPanelNode, inspectorPanelOptions, 7, GUI.skin.GetStyle("toolbarButton"));
                            //}
                        }
                    }
                }
            }
        }
예제 #4
0
        public static void UpdateGraph(Graph graph)
        {
            if (graph.version != EditorHelpers.GetEditorVersion() || string.IsNullOrEmpty(graph.version))
            {
                if (EditorHelpers.GetEditorVersion() == "version 1.2.0" ||
                    EditorHelpers.GetEditorVersion() == "version 1.2.0p1" ||
                    EditorHelpers.GetEditorVersion() == "version 1.2.0p2")
                {
                    // update nodes name to title
                    //////////////////////////////
                    for (int n = 0; n < graph.nodes.Count; n++)
                    {
                        if (string.IsNullOrEmpty(graph.nodes[n].nodeData.title))
                        {
                            graph.nodes[n].nodeData.title    = graph.nodes[n].nodeData.name;
                            graph.nodes[n].nodeData.typeName = graph.nodes[n].nodeData.name;
                        }
                    }



                    // check if nodevariables connected to blackboard variables are correctly registered to the connected node list
                    //////////////////////////////
                    for (int n = 0; n < graph.nodes.Count; n++)
                    {
                        List <FRVariable> _nodeVariables;
                        GetAvailableVariableTypes.GetAllFRVariablesOnNode(graph.nodes[n], out _nodeVariables);

                        for (int v = 0; v < _nodeVariables.Count; v++)
                        {
                            if (_nodeVariables[v].type == FRVariable.VariableType.blackboard)
                            {
                                // loop through all blackboards in graph and check if node is assigned to the connected nodes list of the blackboard variable
                                foreach (var bbKey in graph.rootGraph.blackboards.Keys)
                                {
                                    foreach (var bbVarKey in graph.rootGraph.blackboards[bbKey].blackboard.variables.Keys)
                                    {
                                        if (_nodeVariables[v].variableGuid == bbVarKey.ToString())
                                        {
                                            bool _assigned = false;
                                            if (graph.rootGraph.blackboards[bbKey].blackboard.variables[bbVarKey].connectedNodes == null)
                                            {
                                                graph.rootGraph.blackboards[bbKey].blackboard.variables[bbVarKey].connectedNodes = new List <Nodes.Node>();
                                            }

                                            for (int c = 0; c < graph.rootGraph.blackboards[bbKey].blackboard.variables[bbVarKey].connectedNodes.Count; c++)
                                            {
                                                if (graph.rootGraph.blackboards[bbKey].blackboard.variables[bbVarKey].connectedNodes[c] == null)
                                                {
                                                    graph.rootGraph.blackboards[bbKey].blackboard.variables[bbVarKey].connectedNodes.RemoveAt(c);
                                                }
                                                else
                                                {
                                                    if (graph.rootGraph.blackboards[bbKey].blackboard.variables[bbVarKey].connectedNodes[c].node == graph.nodes[n])
                                                    {
                                                        _assigned = true;
                                                    }
                                                }
                                            }

                                            if (!_assigned)
                                            {
                                                graph.rootGraph.blackboards[bbKey].blackboard.variables[bbVarKey].connectedNodes.Add(graph.nodes[n]);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }



                    for (int s = 0; s < graph.subGraphs.Count; s++)
                    {
                        graph.subGraphs[s].UpdateGraph(graph.subGraphs[s]);
                    }

                    graph.version = EditorHelpers.GetEditorVersion();

                                        #if FLOWREACTOR_DEBUG
                    Debug.Log("FlowReactor: Graph - " + graph.name + " has been updated to: " + graph.version);
                                        #endif
                }
            }
        }