Example #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);
        }
 public static void RepairAis()
 {
     RepairWindow.ShowWindow();
 }