internal static bool TryGetSettings(out ApexSettings settings) { if (_instance != null) { settings = _instance; return(true); } var apexRoot = AssetPath.GetApexRoot(false); var dataFolder = AssetPath.GetApexDataFolder(false); var relativeDataFolder = AssetPath.GetApexDataFolder(true); string settingsPath = AssetPath.Combine(relativeDataFolder, "ApexSettings.asset"); AssetPath.EnsurePath(relativeDataFolder); _instance = AssetDatabase.LoadAssetAtPath(settingsPath, typeof(ApexSettings)) as ApexSettings; bool settingsFound = (_instance != null); if (!settingsFound) { _instance = ScriptableObject.CreateInstance <ApexSettings>(); AssetDatabase.CreateAsset(_instance, settingsPath); AssetDatabase.SaveAssets(); } _instance.rootFolder = apexRoot; _instance.dataFolder = dataFolder; _instance.relativeDataFolder = relativeDataFolder; settings = _instance; return(settingsFound); }
private bool ChangeStorageFolder(string proposedFolder) { if (string.Equals(proposedFolder, _storagePath, StringComparison.OrdinalIgnoreCase) || !AssetPath.IsProjectPath(proposedFolder)) { return(false); } proposedFolder = AssetPath.ProjectRelativePath(proposedFolder); bool apexified = proposedFolder.EndsWith("Resources/" + AIManager.StorageFolder); if (!proposedFolder.EndsWith("Resources") && !apexified) { EditorUtility.DisplayDialog("Invalid Storage Folder", "The storage folder selected must be a Resources folder. This can however be anywhere inside the Assets folder.", "Ok"); return(false); } if (!apexified) { proposedFolder = AssetPath.Combine(proposedFolder, AIManager.StorageFolder); } AssetPath.EnsurePath(proposedFolder); //Move files from current storage location to new location. var fullStoragePath = AssetPath.GetFullPath(_storagePath); if (Directory.Exists(fullStoragePath)) { foreach (var asset in Directory.GetFiles(fullStoragePath, "*.asset", SearchOption.TopDirectoryOnly)) { var fileName = Path.GetFileName(asset); var msg = AssetDatabase.MoveAsset(AssetPath.ProjectRelativePath(asset), AssetPath.Combine(proposedFolder, fileName)); if (!string.IsNullOrEmpty(msg)) { EditorUtility.DisplayDialog("Error Moving Assets", msg, "Ok"); return(false); } } AssetDatabase.DeleteAsset(_storagePath); } _storagePath = proposedFolder; 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(); } }
private bool ChangeNameMapFolder(string proposedFolder) { if (string.Equals(proposedFolder, _nameMapPath, StringComparison.OrdinalIgnoreCase) || !AssetPath.IsProjectPath(proposedFolder)) { return(false); } proposedFolder = AssetPath.ProjectRelativePath(proposedFolder); AssetPath.EnsurePath(proposedFolder); //Move map from current location to new location. if (!string.IsNullOrEmpty(_nameMapPath)) { var existingFile = AssetPath.Combine(AssetPath.GetFullPath(_nameMapPath), NameMapFileName); if (File.Exists(existingFile)) { var oldFilePath = AssetPath.Combine(_nameMapPath, NameMapFileName); var newFilePath = AssetPath.Combine(proposedFolder, NameMapFileName); var msg = AssetDatabase.MoveAsset(oldFilePath, newFilePath); if (!string.IsNullOrEmpty(msg)) { EditorUtility.DisplayDialog("Error Moving Asset", msg, "Ok"); return(false); } else { AssetDatabase.Refresh(); } } } _nameMapPath = proposedFolder; return(true); }