static bool saveResourcesToPath <DstType, SrcType, StorageType>( List <string> outObjectPaths, string baseDir, ResourceStorageWatcher <StorageType, SrcType> objects, IndexedObjectConverter <SrcType, DstType> converter, System.Func <DstType, string> nameFunc, string baseName, bool showGui, System.Action <DstType> dstProcessor = null) where DstType : IFastJsonValue { if (converter == null) { throw new System.ArgumentNullException("converter"); } bool result = false; try{ if (objects != null) { foreach (var curData in objects.getNewObjectsData()) { //lq begin var temp = saveResourceToPath( baseDir, curData.data, curData.index, curData.id, objects.numObjects, converter, nameFunc, baseName, showGui, dstProcessor ); if (string.IsNullOrEmpty(temp) == false) { outObjectPaths.Add(temp); result = true; } //end } objects.updateNumObjects(); //yup. I forgot that part. } return(result); } finally{ if (showGui) { ExportUtility.hideProgressBar(); } } }
void saveAssetFiles(ExternalAssetList externAssets, string baseFilename, bool showGui, Logger logger = null) { try{ Logger.makeValid(ref logger); logger.logFormat("Save resources entered"); string targetDir, projectPath; if (!checkResourceFolder(baseFilename, out targetDir, out projectPath, false)) { return; } var baseProjectName = System.IO.Path.GetFileNameWithoutExtension(baseFilename); var targetAssetPath = System.IO.Path.Combine(targetDir, baseProjectName); bool cancelled = false; if (!cancelled) { if (!saveTerrains(externAssets.terrains, baseFilename, targetAssetPath, projectPath, showGui, logger)) { cancelled = true; } } if (!cancelled) { if (!saveCubemaps(externAssets.cubemaps, baseFilename, targetAssetPath, projectPath, showGui, logger)) { cancelled = true; } } if (!cancelled) { if (!saveTextures(externAssets.textures, baseFilename, targetAssetPath, projectPath, showGui, logger)) { cancelled = true; } } } finally{ if (showGui) { ExportUtility.hideProgressBar(); } } }
public void saveToFile(string filename, bool showGui, bool saveResourceFiles, Logger logger = null) { try{ if (showGui) { ExportUtility.showProgressBar( string.Format("Saving file {0}", System.IO.Path.GetFileName(filename)), "Writing json data", 0, 1); } string targetDir; string projectPath; checkResourceFolder(filename, out targetDir, out projectPath, true); string baseName = System.IO.Path.GetFileNameWithoutExtension(filename); string filesDir = System.IO.Path.Combine(targetDir, baseName); // + "_data"); if (showGui) { confirmAndEraseExistingDirectory(filesDir); } System.IO.Directory.CreateDirectory(filesDir); externResourceList = resourceMapper.saveResourceToFolder(filesDir, showGui, scenes, logger, saveResourceFiles); Utility.saveStringToFile(filename, toJsonString()); if (!saveResourceFiles) { return; } saveAssetFiles(externResourceList.externalAssets, filename, showGui, logger); } finally{ //Otherwise progress bar can get stuck, blocking entirety of editor if (showGui) { ExportUtility.hideProgressBar(); } } }
public static JsonScene fromObjects(GameObject[] args, ResourceMapper resMap, bool showGui) { try{ var result = new JsonScene(); var objMap = new GameObjectMapper(); foreach (var curObj in args) { objMap.gatherObjectIds(curObj); } foreach (var curObj in objMap.objectList) { resMap.gatherPrefabData(curObj); } for (int i = 0; i < objMap.objectList.Count; i++) { /*TODO: The constructor CAN add more data, but most of it would've been added prior to this point. * Contempalting whether to enforce it strictly or not.*/ if (showGui) { ExportUtility.showProgressBar("Collecting scene data", string.Format("Adding scene object {0}/{1}", i, objMap.numObjects), i, objMap.objectList.Count); } var newObj = new JsonGameObject(objMap.objectList[i], objMap, resMap); result.objects.Add(newObj); } return(result); } finally{ if (showGui) { ExportUtility.hideProgressBar(); } } }
bool processDataList <Data>(List <Data> assets, bool showGui, string titleMsgStart, string assetMsgStart, DataProcessingDelegate <Data> callback, Logger logger) { var title = string.Format("{0} \"{1}\"", titleMsgStart, getProjectName()); for (int i = 0; i < assets.Count; i++) { if (showGui) { if (ExportUtility.showCancellableProgressBar(title, string.Format("{2} {0}/{1}", i, assets.Count, assetMsgStart), i, assets.Count)) { logger.logErrorFormat("Export was cancelled by the user"); ExportUtility.hideProgressBar(); return(false); } } if (callback != null) { callback(assets[i], showGui, logger); } } return(true); }
bool collectProjectResources(bool showGui, Logger logger) { try{ var projectName = Application.productName; var title = string.Format("Processing proejct \"{0}\"", projectName); if (showGui) { ExportUtility.showProgressBar(title, "Gathering all assets", 0, 1); } var allAssets = AssetDatabase.FindAssets("t:object").ToList(); logger.logFormat("{0} assets found", allAssets.Count); title = string.Format("Enumerating assets for \"{0}\"", projectName); var numAssets = allAssets.Count; var assetList = new ProjectAssetList(); if (!processDataList(allAssets, showGui, "Enumerating assets for", "Processing asset", (data_, gui_, log_) => { assetList.addAssetFromGuid(data_, log_); return(true); }, logger)) { return(false); } logger.logFormat("Asset information: textures: {0}; materials: {1}; gameObjects: {2}; " + "terrains: {3}; scenes: {4}; defaultAssets: {5}; unsupported: {6};", assetList.textures.Count, assetList.materials.Count, assetList.gameObjects.Count, assetList.terrains.Count, assetList.scenes.Count, assetList.defaultAssets.Count, assetList.unsupportedAssets.Count); if (!processDataList(assetList.terrains, showGui, "Registering terrains for", "Processing terrain", addTerrainAsset, logger)) { return(false); } if (!processDataList(assetList.textures, showGui, "Registering textures for", "Processing texture", addTextureAsset, logger)) { return(false); } if (!processDataList(assetList.materials, showGui, "Registering materials for", "Processing material", addMaterialAsset, logger)) { return(false); } if (!processDataList(assetList.gameObjects, showGui, "Registering prefabs for", "Processing prefab", addGameObjectAsset, logger)) { return(false); } var sceneSetup = UnityEditor.SceneManagement.EditorSceneManager.GetSceneManagerSetup(); var processResult = processDataList(assetList.scenes, showGui, "Registering scenes for", "Processing scene", addSceneAsset, logger); UnityEditor.SceneManagement.EditorSceneManager.RestoreSceneManagerSetup(sceneSetup); if (!processResult) { return(false); } } finally{ if (showGui) { ExportUtility.hideProgressBar(); } } return(true); }