Esempio n. 1
0
        private void Init()
        {
            if (_target == null)
            {
                _target = (UtilityAIComponent)this.target;
            }

            var currentSelectedAIs = _target.aiConfigs;

            if (currentSelectedAIs == null)
            {
                return;
            }

            _aiNames = new string[currentSelectedAIs.Length];

            for (int i = 0; i < currentSelectedAIs.Length; i++)
            {
                var ai = currentSelectedAIs[i] != null?StoredAIs.GetById(currentSelectedAIs[i].aiId) : null;

                if (ai != null)
                {
                    _aiNames[i] = ai.name;
                }
                else
                {
                    _aiNames[i] = "?";
                }
            }
        }
Esempio n. 2
0
        internal static AIUI Load(string aiId, bool refreshState)
        {
            var data = StoredAIs.GetById(aiId);

            if (data == null)
            {
                EditorUtility.DisplayDialog("Load Failed.", "The requested AI can no longer be found.", "Ok");
                return(null);
            }

            return(Load(data, refreshState));
        }
Esempio n. 3
0
        internal void Save(string newName)
        {
            if (_ai == null || _ai.rootSelector == null)
            {
                return;
            }

            // new name is not null or empty when using 'Save As'
            if (!string.IsNullOrEmpty(newName))
            {
                this.name = StoredAIs.EnsureValidName(newName, _aiStorage);

                // If we are saving under a new name (as opposed to saving a new AI), we need to save copy of the current AI with new Ids.
                if (_aiStorage != null)
                {
                    _aiStorage = null;
                    _ai.RegenerateIds();
                }
            }

            bool saveNew = (_aiStorage == null);

            if (saveNew)
            {
                _aiStorage = AIStorage.Create(_ai.id.ToString(), this.name);
                StoredAIs.AIs.Add(_aiStorage);
                AssetPath.EnsurePath(AIGeneralSettings.instance.storagePath);
                var assetPath = AssetPath.Combine(AIGeneralSettings.instance.storagePath, this.name + ".asset");
                AssetDatabase.CreateAsset(_aiStorage, assetPath);
            }

            _aiStorage.version             = _aiVersion.version;
            _aiStorage.configuration       = SerializationMaster.Serialize(_ai);
            _aiStorage.editorConfiguration = GuiSerializer.Serialize(this.canvas);

            EditorUtility.SetDirty(_aiStorage);
            AssetDatabase.SaveAssets();
            this.isDirty = false;
            _undoRedo.SetSavePoint();

            if (saveNew && UserSettings.instance.autoGenerateNameMap)
            {
                AINameMapGenerator.WriteNameMapFile();
            }
        }
Esempio n. 4
0
        private void OnEnable()
        {
            _props = this.GetProperties("relevantAIId", "mode");

            _target = this.target as ContextVisualizerComponent;
            if (string.IsNullOrEmpty(_target.relevantAIId))
            {
                _relevantAiName = "All";
                return;
            }

            var ai = StoredAIs.GetById(_target.relevantAIId);

            if (ai != null)
            {
                _relevantAiName = ai.name;
            }
            else
            {
                _relevantAiName = "?";
            }
        }
        private static bool ExecuteCommand(string cmd, int delay)
        {
            var ais = selectedAIs.ToArray();

            if (ais.Length == 0)
            {
                return(false);
            }

            bool consumeEvent = false;

            switch (cmd)
            {
            case "Open":
            {
                _pendingAction = () =>
                {
                    for (int i = 0; i < ais.Length; i++)
                    {
                        AIEditorWindow.Open(ais[i].aiId);
                    }
                };

                consumeEvent = true;
                break;
            }

            case "Delete":
            case "SoftDelete":
            {
                //reload all windows with deleted ais
                var aisBefore = StoredAIs.AIs.ToArray();
                _pendingAction = () =>
                {
                    StoredAIs.Refresh();
                    var aisAfter   = StoredAIs.AIs.ToArray();
                    var deletedIds = aisBefore.Except(aisAfter).Select(ai => ai.aiId).ToArray();

                    AIEditorWindow.Unload(deletedIds);
                };

                break;
            }

            case "Duplicate":
            {
                //identify all additions and re-ID them.
                var aisBefore = StoredAIs.AIs.ToArray();
                _pendingAction = () =>
                {
                    StoredAIs.Refresh();
                    var aisAfter = StoredAIs.AIs.ToArray();
                    var addedAis = aisAfter.Except(aisBefore);
                    foreach (var copiedAI in addedAis)
                    {
                        var ui = AIUI.Load(copiedAI, false);
                        if (ui != null)
                        {
                            ui.ai.RegenerateIds();
                            copiedAI.aiId = ui.ai.id.ToString();
                            ui.Save(null);
                        }
                        else
                        {
                            var path = AssetDatabase.GetAssetPath(copiedAI);
                            AssetDatabase.DeleteAsset(path);
                        }
                    }
                };

                break;
            }
            }

            EditorAsync.ExecuteDelayed(
                () =>
            {
                _pendingAction();
                _pendingAction = null;
            },
                delay);

            return(consumeEvent);
        }