Пример #1
0
        private Rect DrawGlobalGuiControls()
        {
            var controlsArea = new Rect(0, 0, position.width, position.height / 8);

            GUILayout.BeginArea(controlsArea);

            GUILayout.BeginVertical();
            if (currentGraph != null)
            {
                GUILayout.Label(currentGraph.Name, _skin.GetStyle("H1"));
            }
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();

            EditorGUI.BeginChangeCheck();
            currentGraph =
                EditorGUILayout.ObjectField(currentGraph, typeof(BehaviorTreeGraph), false) as BehaviorTreeGraph;
            if (EditorGUI.EndChangeCheck())
            {
                GUI.FocusControl(null);
                if (currentGraph != null)
                {
                    RemoveNotification();
                    LoadTreeGraph();
                    GraphInstanceID = currentGraph.GetInstanceID();
                }
            }

            EditorGUILayout.Separator();
            EditorGUI.BeginChangeCheck();
            _autoSave = EditorGUILayout.Toggle("Autosave Enabled", _autoSave);
            if (EditorGUI.EndChangeCheck())
            {
                GUI.FocusControl(null);
            }

            EditorGUI.BeginChangeCheck();
            _saveOnClose = EditorGUILayout.Toggle("Save on window close", _saveOnClose);
            if (EditorGUI.EndChangeCheck())
            {
                GUI.FocusControl(null);
            }

            EditorGUI.BeginChangeCheck();
            _saveOnPlay = EditorGUILayout.Toggle("Save on Play Pressed", _saveOnPlay);
            if (EditorGUI.EndChangeCheck())
            {
                GUI.FocusControl(null);
            }


            if (GUILayout.Button("Save Graph Data"))
            {
                SaveGraphData();
            }

            /*
             * if (GUILayout.Button("Show window"))
             *  _showWindows = !_showWindows;*/

            if (GUILayout.Button("Reset zoom"))
            {
                _currentZoom = 1;
            }

            if (DebugMode)
            {
                if (_entryView != null)
                {
                    GUILayout.Label("entry X:" + _entryView.windowRect.xMin + " Y:" + _entryView.windowRect.yMin);
                    //GUILayout.Label("editor X:" + position.xMax + " Y:" + position.yMax);
                    if (_entryView.children != null && _entryView.children.Count > 0)
                    {
                        GUILayout.Label(_entryView.children[0].windowTitle);
                    }
                }
            }

            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            //GUILayout.BeginVertical();
            //_zoom = GUILayout.HorizontalSlider(_zoom, 0, 6);
            //GUILayout.EndVertical();

            GUILayout.EndArea();
            return(controlsArea);
        }
Пример #2
0
        private void EditorApplicationOnPlayModeStateChanged(PlayModeStateChange state)
        {
            switch (state)
            {
            case PlayModeStateChange.ExitingEditMode:

                nodeIds.Clear();
                _blackBoardVariablesID.Clear();

                if (currentGraph != null)
                {
                    if (_saveOnPlay)
                    {
                        SaveGraphData();
                    }
                    GraphInstanceID = currentGraph.GetInstanceID();

                    foreach (var savedNode in currentGraph.SavedNodes)
                    {
                        int[] variablesID = new int[savedNode.variables.Count];

                        for (int i = 0; i < savedNode.variables.Count; i++)
                        {
                            variablesID[i] = savedNode.variables[i].GetInstanceID();
                        }

                        _blackBoardVariablesID.Add(new IDsListWrapper(variablesID));
                        nodeIds.Add(savedNode.GetInstanceID());
                    }

                    EditorUtility.SetDirty(currentGraph);
                }

                if (_tooltipWindow != null)
                {
                    _tooltipWindow.Close();
                }

                break;

            case PlayModeStateChange.EnteredPlayMode:
                //onenable is being called
                currentGraph = EditorUtility.InstanceIDToObject(GraphInstanceID) as BehaviorTreeGraph;

                for (var index = 0; index < currentGraph.SavedNodes.Count; index++)
                {
                    currentGraph.SavedNodes[index] = EditorUtility.InstanceIDToObject(nodeIds[index]) as BaseNodeView;

                    for (int i = 0; i < _blackBoardVariablesID[index].ids.Length; i++)
                    {
                        currentGraph.SavedNodes[index].variables[i] = EditorUtility.InstanceIDToObject(_blackBoardVariablesID[index].ids[i]) as BlackBoardVariable;
                    }
                }
                EditorUtility.SetDirty(currentGraph);


                break;

            case PlayModeStateChange.EnteredEditMode:
                StartEditor(true);
                break;

            default:
                UDebug.Log("Entering :" + state);
                break;
            }
        }