/// <summary> /// 在文件夹里查找模型文件(只支持.zip/.fbx/.gltf/.glb/.unity3d) /// </summary> /// <param name="folder">文件夹Path</param> /// <returns></returns> public static string FindModelFileFullName(string folder, out string format) { folder = ZipUtility.PathRespace(folder); Debug.Log("文件夹路径 " + folder); DirectoryInfo theFolder = new DirectoryInfo(folder); //当前层检测是否找到 FileInfo[] fileInfos = theFolder.GetFiles(); for (int i = 0; i < fileInfos.Length; i++) { string fileName = fileInfos[i].Name.ToLower(); if (fileName.EndsWith(".fbx")) { format = ".fbx"; return(PathRespace(fileInfos[i].FullName)); } if (fileName.EndsWith(".gltf")) { format = ".gltf"; return(PathRespace(fileInfos[i].FullName)); } if (fileName.EndsWith(".glb")) { format = ".glb"; return(PathRespace(fileInfos[i].FullName)); } if (fileName.EndsWith(".unity3d")) { format = ".unity3d"; return(PathRespace(fileInfos[i].FullName)); } if (fileName.EndsWith(".zip")) { format = ".zip"; return(PathRespace(fileInfos[i].FullName)); } } //递归子文件夹查找 DirectoryInfo[] childFolders = theFolder.GetDirectories(); for (int i = 0; i < childFolders.Length; i++) { string found = FindModelFileFullName(childFolders[i].FullName, out string outEndFile); if (!string.IsNullOrEmpty(found)) { format = outEndFile; return(found); } } Debug.Log("资源没找到 " + folder); format = ""; return(""); }
void MiniLoadModel(string _filePath) { string strCheckFile = _filePath.ToLower(); _filePath = ZipUtility.PathRespace(_filePath); Debug.Log("---开始加载:" + _filePath); strModelResPath = strCheckFile; if (strCheckFile.EndsWith(".fbx")) { Debug.Log("---fbx"); //ps:使用TriLib插件加载 modelLoader = new TriLibLoader(OnLoadFinish); } if (modelLoader != null) { modelLoader.LoadResSync(_filePath); } else { Debug.LogError("---ResLoader is null! FilePath:" + _filePath); } }
void PathSet() { //解压路径 pauseZipPath = Path.Combine(Application.persistentDataPath, "AVRViewrChache"); pauseZipPath = ZipUtility.PathRespace(pauseZipPath); if (!Directory.Exists(pauseZipPath))//模型解压路径 { Directory.CreateDirectory(pauseZipPath); } Debug.Log("解压路径: " + pauseZipPath); //streaming 路径 sourcePath = Path.Combine(Application.streamingAssetsPath, "FBX"); sourcePath = Path.Combine(sourcePath, "ttjkz.zip"); sourcePath = ZipUtility.PathRespace(sourcePath); //模型压缩包放置路径 resPath = Application.persistentDataPath; resPath = ZipUtility.PathRespace(resPath); Debug.Log("模型压缩包放置路径: " + resPath); }
void OnMaterialsLoad(AssetLoaderContext assetLoaderContext) { string matPath = System.IO.Path.GetDirectoryName(modelPath); string result = String.Empty; matPath = ZipUtility.PathRespace(matPath); int _index = matPath.LastIndexOf(@"/"); Debug.Log(_index + " " + matPath); result = matPath.Substring(matPath.LastIndexOf(@"/")); Debug.Log(result); string matFloderPath = matPath.TrimEnd(result.ToCharArray()); foreach (Material mat in assetLoaderContext.LoadedMaterials.Values) { LoadSprite(mat, matFloderPath); } loadObj = assetLoaderContext.RootGameObject; OnLoadFinish(); }
IEnumerator Copy() { #if UNITY_IOS src = "file://" + src; #endif UnityWebRequest www = UnityWebRequest.Get(sourcePath); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.LogError(www.error); } else { Debug.Log(www.downloadHandler.data.Length); byte[] bytes = www.downloadHandler.data; string _path = Path.Combine(resPath, "1.zip"); _path = ZipUtility.PathRespace(_path); File.WriteAllBytes(_path, bytes); yield return(null); } www.Dispose(); }