using System; using System.Collections; using System.Collections.Generic; using System.IO; #if UNITY_EDITOR using UnityEditor; #endif using UnityEngine; using UnityEngine.SceneManagement; namespace Gaia { public static class GaiaDirectories { public const string SESSION_OPERATIONS_DIRECTORY = "/Session Operations"; public const string SESSION_SCENE_PROFILE_DIRECTORY = "/Scene Profiles"; public const string TERRAIN_SCENES_DIRECTORY = "/Terrain Scenes"; public const string TERRAIN_DATA_DIRECTORY = "/Terrain Data"; public const string SETTINGS_DIRECTORY = "/Settings"; public const string STAMP_DIRECTORY = "/Stamps"; public const string USER_STAMP_DIRECTORY = "/My Saved Stamps"; public const string TERRAIN_LAYERS_DIRECTORY = "/Terrain Layers"; public const string EXPORT_DIRECTORY = "/Exports"; public const string STAMPER_EXPORT_DIRECTORY = "/Stamper Exports"; public const string STAMPER_TERRAIN_EXPORT_DIRECTORY = "/Stamper Terrain Exports"; public const string SCANNER_EXPORT_DIRECTORY = "/Scanner Exports"; public const string MASK_MAP_EXPORT_DIRECTORY = "/Mask Maps"; public const string COLLISION_DATA_DIRECTORY = "/TerrainCollisionData"; public const string GAIA_PRO = "/Procedural Worlds/Gaia/Gaia Pro"; public const string GAIA_SHADER_DIRECTORY = "/Procedural Worlds/PW Shader Library"; public const string TERRAIN_MESH_EXPORT_DIRECTORY = "/Mesh Terrains"; public const string GAIA_WATER_MATERIAL_DIRECTORY = "/Gaia Lighting and Water/Gaia Water/Ocean Water/Resources/Material"; public const string TEMP_EXPORT_PATH = "Assets/Temp Export"; /// /// Returns the Gaia Pro folder exists in the project /// /// public static bool GetGaiaProDirectory() { bool isPro = false; string dataPath = Application.dataPath; if (Directory.Exists(dataPath + GAIA_PRO)) { isPro = true; } else { isPro = false; } return isPro; } /// /// Return the Gaia directory in the project /// /// String containing the Gaia directory public static string GetGaiaDirectory() { //Default Directory, will be returned if not in Editor string gaiaDirectory = "Assets/Procedural Worlds/Gaia/"; #if UNITY_EDITOR string[] assets = AssetDatabase.FindAssets("Gaia_ReadMe", null); for (int idx = 0; idx < assets.Length; idx++) { string path = AssetDatabase.GUIDToAssetPath(assets[idx]); if (Path.GetFileName(path) == "Gaia_ReadMe.txt") { gaiaDirectory = path.Replace("/Gaia_ReadMe.txt",""); } } #endif return gaiaDirectory; } /// /// Returns the Gaia Session Directory. Will create it if it does not exist. /// /// The path to the Gaia Session directory public static string GetSessionDirectory() { GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); Directory.CreateDirectory(gaiaSettings.m_sessionsDirectory); return gaiaSettings.m_sessionsDirectory; } /// /// Returns the Gaia Data Directory. Will create it if it does not exist. /// /// The path to the Gaia Data directory public static string GetSettingsDirectory() { return GetGaiaSubDirectory(SETTINGS_DIRECTORY); } /// /// Returns the path to store terrain scenes in, according to the session filename /// /// The session to get / create this path for /// public static string GetTerrainScenePath(GaiaSession gaiaSession=null) { if (gaiaSession == null) { gaiaSession = GaiaSessionManager.GetSessionManager().m_session; } return CreatePathIfDoesNotExist(GetScenePath(gaiaSession) + TERRAIN_SCENES_DIRECTORY); } /// /// Returns a path to store scriptable object data for the session operations. /// /// The session to create the directory for /// public static string GetSessionOperationPath(GaiaSession gaiaSession, bool create = true) { #if UNITY_EDITOR return CreatePathIfDoesNotExist(GetSessionSubFolderPath(gaiaSession, create) + SESSION_OPERATIONS_DIRECTORY); #else return ""; #endif } /// /// Returns a folder that is named as the session asset, to store session related data into. /// /// The session to create the directory for /// public static string GetSessionSubFolderPath(GaiaSession gaiaSession, bool create = true) { #if UNITY_EDITOR string masterScenePath = AssetDatabase.GetAssetPath(gaiaSession).Replace(".asset", ""); if (String.IsNullOrEmpty(masterScenePath)) { GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager(false); gsm.SaveSession(); masterScenePath = AssetDatabase.GetAssetPath(gsm.m_session).Replace(".asset", ""); } if (create) return CreatePathIfDoesNotExist(masterScenePath); else return masterScenePath; #else return ""; #endif } public static string GetSceneProfilesFolderPath(GaiaSession gaiaSession, bool create = true) { #if UNITY_EDITOR return CreatePathIfDoesNotExist(GetSessionSubFolderPath(gaiaSession, create) + SESSION_SCENE_PROFILE_DIRECTORY); #else return ""; #endif } /// /// Returns the path to store scene files in, according to the Gaia Session path /// /// The session to get / create the directory for /// public static string GetScenePath(GaiaSession gaiaSession = null) { if (gaiaSession == null) { gaiaSession = GaiaSessionManager.GetSessionManager().m_session; } return GetSessionSubFolderPath(gaiaSession); } /// /// Returns the path to store terrain scenes in, according to the session filename /// /// /// The current session to get / create this directory for /// public static string GetTerrainDataScenePath(GaiaSession gaiaSession = null) { if (gaiaSession == null) { gaiaSession = GaiaSessionManager.GetSessionManager().m_session; } return CreatePathIfDoesNotExist(GetScenePath(gaiaSession) + TERRAIN_DATA_DIRECTORY); } /// /// Returns a path for temporary exports (before they are copied to the final destination outside the "Assets" folder) /// /// public static string GetTempExportPath() { return TEMP_EXPORT_PATH; } /// /// Returns the path to store terrain layer files in /// /// The current session to get / create this directory for /// public static string GetTerrainLayerPath(GaiaSession gaiaSession = null) { if (gaiaSession == null) { gaiaSession = GaiaSessionManager.GetSessionManager().m_session; } return CreatePathIfDoesNotExist(GetScenePath(gaiaSession) + TERRAIN_LAYERS_DIRECTORY); } /// /// Returns the Gaia Stamps Directory. Will create it if it does not exist. /// /// The path to the Gaia Stamps directory public static string GetStampDirectory() { return GetGaiaSubDirectory(STAMP_DIRECTORY); } /// /// Returns the Gaia Mask Export Directory. Will create it if it does not exist. /// /// The path to the Gaia Stamps directory //public static string GetMaskDirectory() //{ // return GetGaiaSubDirectory(MASK_DIRECTORY); //} /// /// Returns the Gaia Mask Export Directory. Will create it if it does not exist. /// /// The path to the Gaia Stamps directory public static string GetExportDirectory(GaiaSession gaiaSession = null) { if (gaiaSession == null) { gaiaSession = GaiaSessionManager.GetSessionManager().m_session; } return CreatePathIfDoesNotExist(GetScenePath(gaiaSession) + EXPORT_DIRECTORY); } public static string GetUserBiomeDirectory(string biomeName ="") { GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); //If no biome name was passed in, return the path to the root biome user data folder if (biomeName != "") { return CreatePathIfDoesNotExist(gaiaSettings.m_biomesDirectory + "/" + biomeName.Replace(" Biome", "")); } else { return CreatePathIfDoesNotExist(gaiaSettings.m_biomesDirectory); } } public static string GetUserSettingsDirectory() { GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); return CreatePathIfDoesNotExist(gaiaSettings.m_userSettingsDirectory); } public static string GetMaskMapExportDirectory(GaiaSession gaiaSession =null) { if (gaiaSession == null) { gaiaSession = GaiaSessionManager.GetSessionManager().m_session; } return CreatePathIfDoesNotExist(GetExportDirectory(gaiaSession) + MASK_MAP_EXPORT_DIRECTORY); } /// /// Returns the Gaia User Stamp directory. Will create it if it does not exist. /// /// The path to the Gaia Stamps directory public static string GetUserStampDirectory() { GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); return CreatePathIfDoesNotExist(gaiaSettings.m_userStampsDirectory); } /// /// Returns the default stamper export directory within the user folder. Will create it if it does not exist. /// /// The path to the Gaia Stamps directory public static string GetStamperExportsDirectory() { return CreatePathIfDoesNotExist(GetUserStampDirectory() + STAMPER_EXPORT_DIRECTORY); } /// /// Returns the default stamper terrain export directory within the user folder. Will create it if it does not exist. /// /// The path to the Gaia Stamps directory public static string GetStamperTerrainExportsDirectory() { return CreatePathIfDoesNotExist(GetUserStampDirectory() + STAMPER_TERRAIN_EXPORT_DIRECTORY); } /// /// Returns the default scanner export directory within the user folder. Will create it if it does not exist. /// /// The path to the Gaia Stamps directory public static string GetScannerExportDirectory() { return CreatePathIfDoesNotExist(GetUserStampDirectory() + SCANNER_EXPORT_DIRECTORY); } /// /// Returns the Gaia Collision Data Directory. Will create it if it does not exist. /// /// The path to the Gaia Stamps directory public static string GetCollisionDataDirectory() { return GetGaiaSubDirectory(COLLISION_DATA_DIRECTORY, false); } public static string GetTerrainMeshExportDirectory(GaiaSession gaiaSession=null) { if (gaiaSession == null) { gaiaSession = GaiaSessionManager.GetSessionManager().m_session; } return CreatePathIfDoesNotExist(GetExportDirectory(gaiaSession) + TERRAIN_MESH_EXPORT_DIRECTORY); } /// /// Creates and returns the path to a certain stamp feature type. /// /// The feature type which we want to create / get the folder for. /// The path to the specific stamp feature insisde the stamps folder. public static string GetStampFeatureDirectory(GaiaConstants.FeatureType featureType) { return CreatePathIfDoesNotExist(GetStampDirectory() + "/" + featureType.ToString()); } /// /// Creates and returns the path to a certain terrain's baked collision data. /// /// The terrain for which we want to create / get the folder for. /// The path to the collision data folder for this terrain. public static string GetTerrainCollisionDirectory(Terrain terrain) { return GetCollisionDataDirectory() + "/" + terrain.name; } /// /// Gets the path for a specific stamp instance within the stamp / feature structure. /// /// The stamp feature type /// The stamp name /// The path to the specific stamp instance directory. public static string GetStampInstanceDirectory(GaiaConstants.FeatureType m_featureType, string m_featureName) { return CreatePathIfDoesNotExist(GetStampFeatureDirectory(m_featureType)) + "/" + m_featureName; } /// /// Gets the path to a specific stamp data directory. (The Data subfolder within the stamp instance folder) /// /// The stamp feature type /// The stamp name /// The path to the specific stamp instance data directory. //public static string GetStampInstanceDataDirectory(GaiaConstants.FeatureType m_featureType, string m_featureName) //{ // return CreatePathIfDoesNotExist(GetStampInstanceDirectory( m_featureType, m_featureName) + DATA_DIRECTORY); //} public static string GetShaderDirectory() { return Application.dataPath + GAIA_SHADER_DIRECTORY; } /// /// Returns a path to a Gaia subdirectory. The subdirectory can be optionally created if it does not exist already. /// /// The Subdir to create. /// Should the subdir be created if it does not exist? /// The complete path to the subdir. private static string GetGaiaSubDirectory(string subDir, bool create = true) { string path = GetGaiaDirectory() + subDir; if (create) { return CreatePathIfDoesNotExist(path); } else { return path; } } /// /// Checks if a path exists, if not it will be created. /// /// public static string CreatePathIfDoesNotExist(string path) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } return path; } /// /// Expects a full file system path starting at a drive letter, and will return a path starting at the projects / games asset folder /// /// Full file system path starting at a drive letter /// public static string GetPathStartingAtAssetsFolder(string inputPath) { return inputPath.Substring(Application.dataPath.Length - "Assets".Length); } } }