Esempio n. 1
0
        private bool LoadFrom(AIStorage data, bool refreshState)
        {
            _aiStorage = data;

            try
            {
                if (EditorApplication.isPlaying)
                {
                    _ai = _visualizedAI = AIManager.GetAI(new Guid(data.aiId));
                }
                else
                {
                    _ai = _visualizedAI = SerializationMaster.Deserialize <UtilityAI>(_aiStorage.configuration);
                }

                this.canvas = GuiSerializer.Deserialize(this, _aiStorage.editorConfiguration);
            }
            catch (Exception e)
            {
                if (EditorUtility.DisplayDialog("Load Error", "The AI could not be loaded, deserialization failed - see the console for details.\n\nDo you wish to open the AI repair tool?.", "Yes", "No"))
                {
                    RepairWindow.ShowWindow(data.name, data.aiId);
                }

                Debug.LogWarning("Failed to load AI: " + e.Message);
                return(false);
            }

            var selectorViews = this.canvas.selectorViews.ToArray();
            int selectorCount = _ai.selectorCount;

            if (!VerifyCountMatch(selectorCount, selectorViews.Length))
            {
                return(false);
            }

            for (int i = 0; i < selectorCount; i++)
            {
                if (!selectorViews[i].Reconnect(_ai[i]))
                {
                    return(false);
                }
            }

            if (refreshState)
            {
                this.inspectorState.Refresh();
            }

            return(true);
        }
Esempio n. 2
0
        private StageElement GetEditorDoc(int index)
        {
            if (_stagedEditorConfigs == null)
            {
                _stagedEditorConfigs = new StageElement[_ais.Length];
            }

            if (_stagedEditorConfigs[index] == null)
            {
                _stagedEditorConfigs[index] = SerializationMaster.Deserialize(_ais[index].editorConfiguration);
            }

            return(_stagedEditorConfigs[index]);
        }
Esempio n. 3
0
        public override void OnInspectorGUI()
        {
            var ai = (AIStorage)this.target;

            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Apex AI: " + ai.name);

            this.serializedObject.Update();
            EditorGUILayout.Separator();
            EditorGUILayout.PropertyField(_description);
            this.serializedObject.ApplyModifiedProperties();

            if (GUILayout.Button("Open"))
            {
                AIEditorWindow.Open(ai.aiId);
            }

            EditorGUILayout.Separator();
            _debug = EditorGUILayout.ToggleLeft("Show debug options", _debug);
            if (_debug)
            {
                if (GUILayout.Button("Copy AI Configuration to clipboard"))
                {
                    try
                    {
                        var json    = new StringBuilder();
                        var aiData  = SerializationMaster.Deserialize(ai.configuration);
                        var guiData = SerializationMaster.Deserialize(ai.editorConfiguration);
                        json.AppendLine(SerializationMaster.Serialize(aiData, true));
                        json.AppendLine(SerializationMaster.Serialize(guiData, true));
                        EditorGUIUtility.systemCopyBuffer = json.ToString();
                    }
                    catch
                    {
                        EditorUtility.DisplayDialog("Error", "Copying failed, unable to read AI Configuration.", "OK");
                    }
                }
            }
        }
Esempio n. 4
0
        private static void ReadAndInit(AIManager.AIData data)
        {
            List <IInitializeAfterDeserialization> initializeAfterDeserializations = new List <IInitializeAfterDeserialization>();

            try
            {
                data.ai      = SerializationMaster.Deserialize <UtilityAI>(data.storedData.configuration, initializeAfterDeserializations);
                data.ai.name = data.storedData.name;
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                UnityEngine.Debug.LogWarning(string.Format("Unable to load the AI: {0}. Additional details: {1}\n{2}", data.storedData.name, exception.Message, exception.StackTrace));
                return;
            }
            int count = initializeAfterDeserializations.Count;

            for (int i = 0; i < count; i++)
            {
                initializeAfterDeserializations[i].Initialize(data.ai);
            }
        }
Esempio n. 5
0
        private static void ReadAndInit(AIData data)
        {
            var requiresInit = new List <IInitializeAfterDeserialization>();

            try
            {
                data.ai      = SerializationMaster.Deserialize <UtilityAI>(data.storedData.configuration, requiresInit);
                data.ai.name = data.storedData.name;
            }
            catch (Exception e)
            {
                Debug.LogWarning(string.Format("Unable to load the AI: {0}. Additional details: {1}\n{2}", data.storedData.name, e.Message, e.StackTrace));
                return;
            }

            var initCount = requiresInit.Count;

            for (int i = 0; i < initCount; i++)
            {
                requiresInit[i].Initialize(data.ai);
            }
        }
        internal static void DeserializeSnippet(string data, AIUI targetUI, Vector2 mousePos, bool regenIds)
        {
            var root        = SerializationMaster.Deserialize(data);
            var snippetType = root.AttributeValue <string>(AttributeName.SnippetType);
            var aiElements  = root.Element(ElementName.AIPart).Elements().ToArray();

            if (snippetType == ElementName.ViewSnippet)
            {
                var uiPart       = root.Element(ElementName.UIPart);
                var referencePos = uiPart.ValueOrDefault(ElementName.ReferencePosition, Vector2.zero);

                var newViews = new List <TopLevelView>(uiPart.Items().Count());

                using (targetUI.undoRedo.bulkOperation)
                {
                    //Deserialize links first so that connections are not lost
                    var linkElements = uiPart.Elements(ElementName.AILinkView).ToArray();
                    DeserializeAILinkViews(linkElements, targetUI, referencePos, mousePos, newViews);

                    var selectorElements = uiPart.Elements(ElementName.SelectorView).ToArray();
                    DeserializeSelectorViews(aiElements, selectorElements, targetUI, referencePos, mousePos, newViews, regenIds);
                }

                targetUI.MultiSelectViews(newViews);
                return;
            }

            var viewElement = root.Element(ElementName.UIPart).Elements().First();

            if (snippetType == ElementName.QualifierSnippet)
            {
                DeserializeQualifier(aiElements[0], viewElement, targetUI);
            }
            else if (snippetType == ElementName.ActionSnippet)
            {
                DeserializeAction(aiElements[0], viewElement, targetUI);
            }
        }
Esempio n. 7
0
        internal void Begin(AIStorage[] ais)
        {
            _ais             = ais;
            _repairedAIIds   = null;
            _identifiedTypes = new Dictionary <string, Type>();
            _stagedAis       = new StageElement[ais.Length];
            for (int i = 0; i < ais.Length; i++)
            {
                _stagedAis[i] = SerializationMaster.Deserialize(ais[i].configuration);
            }

            if (_customTasks == null)
            {
                _customTasks = (from t in ApexReflection.GetRelevantTypes()
                                where !t.IsAbstract && typeof(IRepairTask).IsAssignableFrom(t) && t.GetConstructor(Type.EmptyTypes) != null
                                select Activator.CreateInstance(t) as IRepairTask).OrderByDescending(t => t.versionThreshold).ToArray();
            }

            if (_customTasks.Length > 0)
            {
                for (int i = 0; i < ais.Length; i++)
                {
                    var aiVersion = new AIVersion(ais[i].version).ToVersion();
                    for (int j = 0; j < _customTasks.Length; j++)
                    {
                        var task = _customTasks[j];
                        if (task.versionThreshold >= aiVersion)
                        {
                            var editorCfg = task.repairsEditorConfiguration ? GetEditorDoc(i) : null;
                            if (task.Repair(_stagedAis[i], editorCfg))
                            {
                                this.customRepairsMade = true;
                            }
                        }
                    }
                }
            }
        }