Exemplo n.º 1
0
        private void PlayModeChange()
        {
            if (_started && !EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPlaying)
            {
                // Stop is called within the playmode scene

                if (_currentStory != null)
                {
                    Debug.Log("Saving imiation data");
                    var imitation = QAIManager.SaveImitation("Imitation set " + (_currentStory.ImitationExperiences.Count + 1));
                    _currentStory.ImitationExperiences.Add(imitation);
                    _currentStory.Save(STORY_PATH);
                }
                _currentStory = null;
            }
            if (_started && !EditorApplication.isPlaying)
            {
                // Stop is called within the editor scene
                _started = false;

                // Do something that should happen on stop
                _init = false;
                Init();

                _mode = QAIMode.Runnning;
                _manager.ModeOverride = _mode;
                _currentStory         = null;

                _learningStory++;
                if (_learnAllStories && _learningStory < _stories.Count)
                {
                    Debug.Log("Starting next learning story");
                    _remake     = false;
                    _forceStart = true;
                    _mode       = QAIMode.Learning;
                }
                else
                {
                    _learnAllStories = false;
                    _benchmark       = false;
                    _learningStory   = 0;
                    _remake          = false;
                }
            }
            if (_starting && EditorApplication.isPlaying)
            {
                // Start is called within the playmode scene
                _starting = false;
                _started  = true;

                // Do something that should happen on start
            }
        }
Exemplo n.º 2
0
        private void OnGUI()
        {
            Init();
            if (_manager == null || _manager != FindObjectOfType <QAIManager>())
            {
                _init = false;
            }

            _mode = _manager.ModeOverride;

            _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);
            EditorApplication.playmodeStateChanged -= PlayModeChange;
            EditorApplication.playmodeStateChanged += PlayModeChange;

            //PROGRESS BAR
            ProgressBars();

            //SETUP
            GUILayout.Space(10);
            EditorGUILayout.LabelField("Setup");
            _agent  = (GameObject)EditorGUILayout.ObjectField("Current Agent", _agent, typeof(GameObject), true);
            _tester = (QTester)EditorGUILayout.ObjectField("Current Tester", _tester, typeof(QTester), true);
            _term   = EditorGUILayout.IntField("Iterations", _term);
            GUILayout.Space(10);

            //BUTTONS
            Buttons();
            if (GUILayout.Button("Reload all", GUILayout.Height(15)))
            {
                _init = false;
            }

            //IMITATION LEARNING
            if (_stories.Count == 0)
            {
                var newStory = new QStory();
                newStory.ScenePath = EditorApplication.currentScene;
                newStory.Save(STORY_PATH);
                _stories.Add(newStory);
            }
            var story = _stories[0];

            GUILayout.Space(20);
            EditorGUILayout.LabelField("Training data");

            //Imitation training
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(17);
            GUILayout.Label("Imitation learning");
            if (GUILayout.Button("Record"))
            {
                _mode         = QAIMode.Imitating;
                _currentStory = story;
                ChangePlayMode();
            }
            EditorGUILayout.EndHorizontal();
            foreach (var exp in story.ImitationExperiences)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(35);
                GUILayout.Label(exp.Name);
                if (GUILayout.Button("Delete"))
                {
                    story.ImitationExperiences.Remove(exp);
                    story.Save(STORY_PATH);
                    return;
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndScrollView();

            if (_showAdvanced = EditorGUILayout.Foldout(_showAdvanced, "Advanced options"))
            {
                EditorGUI.indentLevel++;
                _visualize = EditorGUILayout.Toggle("Visualize Network", _visualize);
                _manager.PrioritizedSweeping = EditorGUILayout.Toggle("Priority Sweeping", _manager.PrioritizedSweeping);
            }


            // Set the values in the AI manager to be saved with the scene.
            if (_manager.ActiveAgent != _agent ||
                _manager.Remake != _remake ||
                _manager.Terminator != _term ||
                _manager.ActiveAgent != _agent ||
                _manager.Tester != _tester ||
                _manager.Mode != _mode ||
                _manager.VisualizeNetwork != _visualize)
            {
                EditorApplication.MarkSceneDirty();
            }

            _manager.Remake           = _remake;
            _manager.Benchmark        = _benchmark;
            _manager.Terminator       = _term;
            _manager.ActiveAgent      = _agent;
            _manager.Tester           = _tester;
            _manager.VisualizeNetwork = _visualize;
            _manager.Mode             = _mode;
            _manager.ModeOverride     = _mode;

//            _manager.OptionWindow = this;

            if (_forceStart)
            {
                _forceStart = false;
                ChangePlayMode();
            }
        }