private bool MatchItem(AIStorage ai, string search) { search = search.Replace(" ", string.Empty); var name = ai.name.Replace(" ", string.Empty); return(name.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0); }
private void CreateAIs(PlanetsStorage planetsStorage, SystemsUpdater systemsUpdater) { var aiStorage = new AIStorage( planetsStorage.GetAIContexts(), systemsUpdater, _aiFireInterval ); }
private AIReference GetAIReference(AIStorage ai) { AIReference aiRef; if (!_aiReferences.TryGetValue(ai.aiId, out aiRef)) { aiRef = new AIReference(ai.aiId, ai.name); _aiReferences.Add(ai.aiId, aiRef); } return(aiRef); }
internal static AIUI Load(AIStorage ai, bool refreshState) { var gui = new AIUI(); gui.name = ai.name; if (!gui.LoadFrom(ai, refreshState)) { return(null); } return(gui); }
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); }
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(); } }
internal static string EnsureValidName(string name, AIStorage target) { if (string.IsNullOrEmpty(name)) { name = "New AI"; } else { var invalidChars = System.IO.Path.GetInvalidFileNameChars(); var transformer = new StringBuilder(name.Length); for (int i = 0; i < name.Length; i++) { var allowChar = true; for (int j = 0; j < invalidChars.Length; j++) { var invalidChar = invalidChars[j]; if (invalidChar.Equals(name[i])) { allowChar = false; break; } } if (allowChar) { transformer.Append(name[i]); } } name = transformer.ToString(); } var nameBase = name; int idx = 0; var stored = AIs.FirstOrDefault(a => a.name.Equals(name, StringComparison.OrdinalIgnoreCase)); while (stored != null && !object.ReferenceEquals(stored, target)) { idx++; name = string.Concat(nameBase, " ", idx.ToString("##")); stored = AIs.FirstOrDefault(a => a.name.Equals(name, StringComparison.OrdinalIgnoreCase)); } return(name); }
private void Start() { templates = GameObject.FindGameObjectWithTag("Rooms").GetComponent <AIStorage>(); hasEntered = false; }
private GUIContent RenderListItem(AIStorage ai) { _listItemContent.text = ai.name; return(_listItemContent); }