static void DropAreaGUI(Rect _rect, FRVariable _nodeVariable, Node _node, GUISkin _skin)
        {
            Rect  _dropArea = new Rect(_rect.x - 2, _rect.y - 2, _rect.width + 4, _rect.height + 4);
            Event _evt      = Event.current;

            if (_dropArea.Contains(_evt.mousePosition) && BlackBoardVariableDragProperties.isDragging)
            {
                if (BlackBoardVariableDragProperties.variable.GetType() == _nodeVariable.GetType())
                {
                    GUI.color = Color.green;
                }
                else
                {
                    GUI.color = Color.red;
                }

                GUI.Box(_dropArea, "", _skin.GetStyle("FRVariable"));
            }

            GUI.color = Color.white;



            if (_evt.type == EventType.MouseUp && _dropArea.Contains(_evt.mousePosition))
            {
                if (BlackBoardVariableDragProperties.variable != null && _nodeVariable != null)
                {
                    if (BlackBoardVariableDragProperties.variable.GetType() == _nodeVariable.GetType())
                    {
                        var bb = _node.graphOwner.blackboards.Keys.Select(x => x.ToString()).ToArray();

                        // Connect BB variable to node variable
                        _nodeVariable.type               = FRVariable.VariableType.blackboard;
                        _nodeVariable.variableGuid       = BlackBoardVariableDragProperties.blackboardVariableGuid.ToString();
                        _nodeVariable.blackboardGuid     = BlackBoardVariableDragProperties.blackboardGuid.ToString();
                        _nodeVariable.assignedBlackboard = _node.rootGraph.blackboards[BlackBoardVariableDragProperties.blackboardGuid].blackboard;
                        _nodeVariable.graph              = _node.rootGraph;


                        if (!_node.rootGraph.blackboards[Guid.Parse(_nodeVariable.blackboardGuid)].blackboard.variables[Guid.Parse(_nodeVariable.variableGuid)].sceneReferenceOnly && _nodeVariable.sceneReferenceOnly)
                        {
                            _node.rootGraph.blackboards[Guid.Parse(_nodeVariable.blackboardGuid)].blackboard.variables[Guid.Parse(_nodeVariable.variableGuid)].sceneReferenceOnly = true;
                        }

                        if (BlackBoardVariableDragProperties.variable.connectedNodes == null)
                        {
                            BlackBoardVariableDragProperties.variable.connectedNodes = new List <FlowReactor.Nodes.Node>();
                        }

                        BlackBoardVariableDragProperties.variable.connectedNodes.Add(_node);

                        BlackBoardVariableDragProperties.isDragging = false;

                        GUI.FocusControl("");

                        BlackBoardVariableDragProperties.editor.SetupListWithoutResLoading();
                    }
                    else
                    {
                        BlackBoardVariableDragProperties.isDragging = false;
                    }
                }
                else
                {
                    BlackBoardVariableDragProperties.isDragging = false;
                }

                BlackBoardVariableDragProperties.variable = null;


                _evt.Use();
            }
        }
示例#2
0
            public override void OnGUI(Rect rect)
            {
                var bb     = blackboards.Keys.Select(x => x.ToString()).ToArray();
                var bbName = blackboards.Values.Select(x => x.blackboard != null ? x.blackboard.name.ToString() : "empty").ToArray();

                GUILayout.Label("Blackboards:", "boldLabel");
                selectedBB = EditorGUILayout.Popup(selectedBB, bbName);

                if (blackboards.Keys.Count == 0)
                {
                    EditorGUILayout.HelpBox("Please add a blackboard", MessageType.Info);
                    return;
                }

                if (blackboards[Guid.Parse(bb[selectedBB])].blackboard != null)
                {
                    selectedBlackboardGuid.SetValue(targetObject, Guid.Parse(bb[selectedBB]));

                    // find all compatible override variables of type field.fieldType
                    var _compatibleTypes = new Dictionary <string, Guid>();

                    //if (GUILayout.Button("EXPOSE"))
                    //{
                    //	rootGraph.exposedNodeVariables = new Dictionary<FlowReactor.Nodes.Node, Graph.ExposedVariables>();


                    //	variable.type = FRVariable.VariableType.exposed;
                    //	variable.graph = node.graphOwner;
                    //	variable.nodeOwner = node;


                    //	if (rootGraph.exposedNodeVariables == null)
                    //	{
                    //		rootGraph.exposedNodeVariables = new Dictionary<FlowReactor.Nodes.Node, Graph.ExposedVariables>();
                    //	}

                    //	rootGraph.exposedNodeVariables.Add(node, new Graph.ExposedVariables(variable));
                    //}

                    using (new GUILayout.VerticalScope("Box"))
                    {
                        GUILayout.Label("name:");
                        newVariableName = EditorGUILayout.TextField(newVariableName);
                        if (GUILayout.Button("create new variable"))
                        {
                            var _v = (FRVariable)Activator.CreateInstance(variable.GetType());

                            if (string.IsNullOrEmpty(newVariableName))
                            {
                                _v.name = "My" + variable.GetType().Name.ToString();
                            }
                            else
                            {
                                _v.name = newVariableName;
                            }
                            _v.type               = FRVariable.VariableType.blackboard;
                            _v.blackboardGuid     = Guid.Parse(bb[selectedBB]).ToString();
                            _v.variableGuid       = Guid.NewGuid().ToString();
                            _v.assignedBlackboard = blackboards[Guid.Parse(bb[selectedBB])].blackboard;
                            _v.graph              = rootGraph;
                            _v.sceneReferenceOnly = variable.sceneReferenceOnly;


                            variable.type               = FRVariable.VariableType.blackboard;
                            variable.blackboardGuid     = Guid.Parse(bb[selectedBB]).ToString();
                            variable.variableGuid       = _v.variableGuid;
                            variable.assignedBlackboard = blackboards[Guid.Parse(bb[selectedBB])].blackboard;
                            variable.graph              = rootGraph;


                            rootGraph.blackboards[Guid.Parse(bb[selectedBB])].blackboard.variables.Add(Guid.Parse(_v.variableGuid), _v);

                            rootGraph.blackboards[Guid.Parse(bb[selectedBB])].blackboard.tempVariablesList = new List <BlackboardSystem.BlackBoard.VariablesData>();
                            foreach (var key in rootGraph.blackboards[Guid.Parse(bb[selectedBB])].blackboard.variables.Keys)
                            {
                                rootGraph.blackboards[Guid.Parse(bb[selectedBB])].blackboard.tempVariablesList.Add(new BlackboardSystem.BlackBoard.VariablesData(key.ToString()));
                            }

                            if (rootGraph.blackboards[Guid.Parse(bb[selectedBB])].blackboard.variables[Guid.Parse(_v.variableGuid)].connectedNodes == null)
                            {
                                rootGraph.blackboards[Guid.Parse(bb[selectedBB])].blackboard.variables[Guid.Parse(_v.variableGuid)].connectedNodes = new List <FlowReactor.Nodes.Node>();
                            }

                            rootGraph.blackboards[Guid.Parse(bb[selectedBB])].blackboard.variables[Guid.Parse(_v.variableGuid)].connectedNodes.Add(node);



                            rootGraph.blackboards[Guid.Parse(bb[selectedBB])].blackboard.tempVariablesList = new List <BlackboardSystem.BlackBoard.VariablesData>();

                            foreach (var key in rootGraph.blackboards[Guid.Parse(bb[selectedBB])].blackboard.variables.Keys)
                            {
                                rootGraph.blackboards[Guid.Parse(bb[selectedBB])].blackboard.tempVariablesList.Add(new BlackboardSystem.BlackBoard.VariablesData(key.ToString()));
                            }

                            EditorUtility.SetDirty(rootGraph.blackboards[Guid.Parse(bb[selectedBB])].blackboard);



                            editorWindow.Close();
                        }
                    }

                    foreach (var bbKey in blackboards[Guid.Parse(bb[selectedBB])].blackboard.variables.Keys)
                    {
                        if (variableField != null)
                        {
                            if (blackboards[Guid.Parse(bb[selectedBB])].blackboard.variables[bbKey].GetType() == variableField.FieldType)
                            {
                                var _name = blackboards[Guid.Parse(bb[selectedBB])].blackboard.variables[bbKey].name;
                                if (string.IsNullOrEmpty(blackboards[Guid.Parse(bb[selectedBB])].blackboard.variables[bbKey].name) || _compatibleTypes.ContainsKey(_name))
                                {
                                    _name = bbKey.ToString();
                                }
                                _compatibleTypes.Add(_name, bbKey);
                            }
                        }
                        else
                        {
                            if (blackboards[Guid.Parse(bb[selectedBB])].blackboard.variables[bbKey].GetType() == variable.GetType())
                            {
                                var _name = blackboards[Guid.Parse(bb[selectedBB])].blackboard.variables[bbKey].name;
                                if (string.IsNullOrEmpty(blackboards[Guid.Parse(bb[selectedBB])].blackboard.variables[bbKey].name) || _compatibleTypes.ContainsKey(_name))
                                {
                                    _name = bbKey.ToString();
                                }
                                _compatibleTypes.Add(_name, bbKey);
                            }
                        }
                    }


                    selections = new Dictionary <string, Guid>(_compatibleTypes);

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

                    using (new GUILayout.HorizontalScope())
                    {
                        GUI.SetNextControlName("Filter");
                        searchTypeString = GUILayout.TextField(searchTypeString, "SearchTextField");

                        if (GUILayout.Button("", GUI.skin.FindStyle("SearchCancelButton")))
                        {
                            searchTypeString = "";
                        }
                    }

                    var _index = 0;

                    using (var scrollView = new GUILayout.ScrollViewScope(scrollPosition))
                    {
                        scrollPosition = scrollView.scrollPosition;

                        foreach (var entry in selections.Keys)
                        {
                            //Debug.Log(searchTypeString);
                            if (entry.ToLower().Contains(searchTypeString.ToLower()) || string.IsNullOrEmpty(searchTypeString))
                            {
                                using (new GUILayout.HorizontalScope())
                                {
                                    if (GUILayout.Button(entry.ToString()))
                                    {
                                        //DataboxEditor.duplicateToTable = entry.ToString();
                                        searchTypeString = "";
                                        editorWindow.Close();
                                        selected = entry.ToString();

                                        selectedVariableGuid.SetValue(targetObject, selections[entry]);                                         //entry.ToString());

                                        if (selectedName != null)
                                        {
                                            selectedName.SetValue(targetObject, field2Value);
                                        }

                                        if (variableField == null)
                                        {
                                            variable.type               = FRVariable.VariableType.blackboard;
                                            variable.blackboardGuid     = Guid.Parse(bb[selectedBB]).ToString();
                                            variable.variableGuid       = selections[entry].ToString();
                                            variable.assignedBlackboard = blackboards[Guid.Parse(bb[selectedBB])].blackboard;
                                            variable.graph              = rootGraph;

                                            if (rootGraph.blackboards[Guid.Parse(variable.blackboardGuid)].blackboard.variables[Guid.Parse(variable.variableGuid)].connectedNodes == null)
                                            {
                                                rootGraph.blackboards[Guid.Parse(variable.blackboardGuid)].blackboard.variables[Guid.Parse(variable.variableGuid)].connectedNodes = new List <FlowReactor.Nodes.Node>();
                                            }

                                            rootGraph.blackboards[Guid.Parse(variable.blackboardGuid)].blackboard.variables[Guid.Parse(variable.variableGuid)].connectedNodes.Add(node);


                                            //if (rootGraph.blackboards[Guid.Parse(variable.blackboardGuid)].blackboard.variables[Guid.Parse(variable.variableGuid)].sceneReferenceOnly)
                                            //{
                                            //	EditorUtility.DisplayDialog("Scene only variable", "You are connecting a node variable with a blackboard variable which already has a scene only variable connection. You can only assign a scene object (Blackboard scene override) to this variable.", "Ok");
                                            //}

                                            // set scene reference only. If a connected variable has a scene reference only attribute set the blackboard variable to scene ref only as well.
                                            // even though it might be connected with other non scene ref only variables. (scene ref always overrides others)
                                            if (!rootGraph.blackboards[Guid.Parse(variable.blackboardGuid)].blackboard.variables[Guid.Parse(variable.variableGuid)].sceneReferenceOnly && variable.sceneReferenceOnly)
                                            {
                                                rootGraph.blackboards[Guid.Parse(variable.blackboardGuid)].blackboard.variables[Guid.Parse(variable.variableGuid)].sceneReferenceOnly = variable.sceneReferenceOnly;
                                            }
                                        }
                                    }
                                }
                            }

                            _index++;
                        }
                    }
                }
            }