/// <summary> /// Returns the final directory for our asset, creating subfolders where necessary in the 'Assets' directory. /// </summary> string ConstructPath(JObject objectList) { /// Make sure path is "Assets/...." not "D:/Unity Projects/My Project/Assets/...." otherwise the AssetDatabase cannot write files to it. /// Lastly I also match the path with the Application DataPath in order to make sure this is the right path selected from the Bridge. AssetDatabase.Refresh(); string defPath = ""; bool addNextPathPart = false; if ((string)objectList["exportPath"] != "") { path = (string)objectList["exportPath"]; } else { defPath = "Assets"; addNextPathPart = true; } string[] pathParts = MegascansUtilities.FixSlashes(path).Split('/'); List <string> finalPathParts = new List <string> (); foreach (string part in pathParts) { if (part == "Assets" && !addNextPathPart) { addNextPathPart = true; } if (addNextPathPart) { finalPathParts.Add(part); } } if (!addNextPathPart) { return(null); } //First, create the user specified path from the importer settings. if (finalPathParts.Count > 0) { for (int i = 0; i < finalPathParts.Count; i++) { defPath = MegascansUtilities.ValidateFolderCreate(defPath, finalPathParts[i]); //FixSlashes(Path.Combine(defPath, finalPathParts[i]));//ValidateFolderCreate(defPath, finalPathParts[i]); } } if (!AssetDatabase.IsValidFolder(defPath)) { return(null); } //then create check to see if the asset type subfolder exists, create it if it doesn't. defPath = MegascansUtilities.ValidateFolderCreate(defPath, MegascansUtilities.GetAssetType((string)objectList["path"])); defPath = MegascansUtilities.ValidateFolderCreate(defPath, folderNamingConvention); return(defPath); }
/// <summary> /// Returns the final directory for our asset, creating subfolders where necessary in the 'Assets' directory. /// </summary> /// <param name="jsonPath"></param> /// <returns></returns> string ConstructPath(JObject objectList) { /// /// Unity doesn't allow you to create objects in directories which don't exist. /// So in this function, we create any and all necessary subdirectories that are required. /// We return the final subdirectory, which is used later in the asset creation too. /// A ton of project path validation /// Make sure path is "Assets/...." not "D:/Unity Projects/My Project/Assets/...." otherwise the AssetDatabase cannot write files to it. /// Lastly I also match the path with the Application DataPath in order to make sure this is the right path selected from the Bridge. /// AssetDatabase.Refresh(); string defPath = ""; bool addNextPathPart = false; if ((string)objectList["exportPath"] != "") { path = (string)objectList["exportPath"]; } else { defPath = "Assets"; addNextPathPart = true; } string[] pathParts = MegascansUtilities.FixSlashes(path).Split('/'); List <string> finalPathParts = new List <string> (); foreach (string part in pathParts) { if (part == "Assets" && !addNextPathPart) { addNextPathPart = true; } if (addNextPathPart) { finalPathParts.Add(part); } } if (!addNextPathPart) { return(null); } //First, create the user specified path from the importer settings. if (finalPathParts.Count > 0) { for (int i = 0; i < finalPathParts.Count; i++) { defPath = MegascansUtilities.ValidateFolderCreate(defPath, finalPathParts[i]); //FixSlashes(Path.Combine(defPath, finalPathParts[i]));//ValidateFolderCreate(defPath, finalPathParts[i]); } } if (!AssetDatabase.IsValidFolder(defPath)) { return(null); } //then create check to see if the asset type subfolder exists, create it if it doesn't. defPath = MegascansUtilities.ValidateFolderCreate(defPath, MegascansUtilities.GetAssetType((string)objectList["path"])); GetAssetFolderName(objectList); string finalFolderName = finalName.Replace("$mapName", "").Replace("$resolution", "").Replace("$lod", "").Replace("$variation", ""); defPath = MegascansUtilities.ValidateFolderCreate(defPath, finalFolderName); return(defPath); }