private AssetBundleManifest GetOldManifest() { var jsonSerializer = new JsonSerializer(new JsonSerializerSettings { Formatting = Formatting.Indented }, Encoding.UTF8); AssetBundleManifest manifest = null; var filePath = Path.Combine(_serverBundlesFolder, _manifestFileName + ".json"); Debug.Log(string.Format("Loading old manifest by path {0}", filePath)); if (File.Exists(filePath)) { var manifestContent = File.ReadAllText(filePath); manifest = jsonSerializer.DeserializeString <AssetBundleManifest>(manifestContent); Debug.Log("Old manifest loaded succesfully."); } else { Debug.Log("Old manifest loading failed."); } return(manifest); }
IEnumerator WorkProcess() { var manifestRequest = resourceStorage.LoadResource <string>(this, manifestURL); yield return(manifestRequest); var jsonSerializer = new JsonSerializer(new JsonSerializerSettings { Formatting = Formatting.Indented }, Encoding.UTF8); var manifestAsJson = jsonSerializer.DeserializeString <AssetBundleManifest>(manifestRequest.Resource); //Set loaded bundles manifest resourceStorage.GetResourceLoader <LocalFolderBundlesLoader>().Manifest.AddManifestPart(manifestAsJson); //For server bundle loader //resourceStorage.GetResourceLoader<WebRequestBundlesLoader>().Manifest.AddManifestPart(manifestAsJson); var sceneBundleRequest = resourceStorage.LoadResource <AssetBundle>(this, bundleName); yield return(sceneBundleRequest); if (sceneBundleRequest.Resource.isStreamedSceneAssetBundle) { string[] scenePaths = sceneBundleRequest.Resource.GetAllScenePaths(); string sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePaths[0]); SceneManager.LoadScene(sceneName); } }
private IEnumerator WorkProcess() { string manifestPath = String.Empty; string bundlesPath = String.Empty; #if UNITY_EDITOR foreach (var findAsset in AssetDatabase.FindAssets(manifestName)) { if (AssetDatabase.GUIDToAssetPath(findAsset).Contains(".json")) { manifestPath = AssetDatabase.GUIDToAssetPath(findAsset); break; } } foreach (var findAsset in AssetDatabase.FindAssets(bundlesFolderPath)) { if (AssetDatabase.GUIDToAssetPath(findAsset).Contains(".u3d")) { bundlesPath = AssetDatabase.GUIDToAssetPath(findAsset).Replace(bundlesFolderPath + ".u3d", ""); bundlesPath = Application.dataPath.Replace("/Assets", "/") + bundlesPath; break; } } resourceStorage = new ResourceStorage(100); UnityResourceFromBundleLoader resFromBundlesLoader = new UnityResourceFromBundleLoader(coroutineManager); LocalFolderBundlesLoader bundlesLoader = new LocalFolderBundlesLoader(bundlesPath, coroutineManager); resourceStorage.RegisterResourceLoader(resFromBundlesLoader); resourceStorage.RegisterResourceLoader(bundlesLoader); var manifest = AssetDatabase.LoadAssetAtPath <TextAsset>(manifestPath); var jsonSerializer = new JsonSerializer(new JsonSerializerSettings { Formatting = Formatting.Indented }, Encoding.UTF8); var manifestAsJson = jsonSerializer.DeserializeString <AssetBundleManifest>(manifest.text); bundlesLoader.Manifest.AddManifestPart(manifestAsJson); #endif var loadPrefab = resourceStorage.LoadResource <GameObject>(this, resourceName); yield return(loadPrefab); Instantiate(loadPrefab.Resource); //Del me resourceStorage.ReleaseFromCache(this, resourceName); loadPrefab = resourceStorage.LoadResource <GameObject>(this, resourceName); yield return(loadPrefab); Instantiate(loadPrefab.Resource); }
private void Awake() { discCacheFolderPath = Application.dataPath + discCacheFolderPath; GameObject timeProvidersGo = new GameObject("-TimeProvider"); SimpleTimeProvider mainCoroutineTimeProvider = timeProvidersGo.AddComponent <SimpleTimeProvider>(); coroutineManager = new CoroutineManager(); coroutineManager.TimeProvider = mainCoroutineTimeProvider; #if UNITY_EDITOR foreach (var findAsset in AssetDatabase.FindAssets(manifestName)) { if (AssetDatabase.GUIDToAssetPath(findAsset).Contains(".json") && AssetDatabase.GUIDToAssetPath(findAsset).Contains("/Sources/")) { serverUrl = Application.dataPath.Replace("/Assets", "/") + AssetDatabase.GUIDToAssetPath(findAsset).Replace(manifestName + ".json", ""); break; } } discCacheFolderPath = serverUrl.Replace("/Sources/", "/FileCacheForExample"); foreach (var findAsset in AssetDatabase.FindAssets(manifestName)) { if (AssetDatabase.GUIDToAssetPath(findAsset).Contains(".json")) { manifestPath = AssetDatabase.GUIDToAssetPath(findAsset); break; } } #endif resourceStorage = new ResourceStorage(100); var textureCreator = new TextureDataCreator(); var versionedResourceLoader = new VersionedDiskCachedResourceLoader(discCacheFolderPath, "file://" + serverUrl, coroutineManager); versionedResourceLoader.RegisterResourceCreator(textureCreator); resourceStorage.RegisterResourceLoader(versionedResourceLoader); loaderPrefix = versionedResourceLoader.SupportsMask; TextAsset manifest = null; #if UNITY_EDITOR manifest = AssetDatabase.LoadAssetAtPath <TextAsset>(manifestPath); #endif var jsonSerializer = new JsonSerializer(new JsonSerializerSettings { Formatting = Formatting.Indented }, Encoding.UTF8); var manifestAsJson = jsonSerializer.DeserializeString <AssetFilesManifest>(manifest.text); versionedResourceLoader.Manifest.AddManifestPart(manifestAsJson); _loadImageVersion1.onClick.AddListener(() => { coroutineManager.StartCoroutine(this, LoadImageVer1Process()); }); _loadImageVersion2.onClick.AddListener(() => { coroutineManager.StartCoroutine(this, LoadImageVer2Process()); }); }
private void CopyFiles(List <AssetReference> assetInfos) { var jsonSerializer = new JsonSerializer(new JsonSerializerSettings { Formatting = Formatting.Indented }, Encoding.UTF8); var customManifest = new CustomManifest(); foreach (var assetReference in assetInfos) { if (assetReference.extension == ".json") { var manifestContent = File.ReadAllText(assetReference.absolutePath); customManifest = jsonSerializer.DeserializeString <CustomManifest>(manifestContent); } } foreach (var assetReference in assetInfos) { var apendToName = ""; if (assetReference.extension != ".json") { var crc32 = ""; foreach (KeyValuePair <string, BundleInfo> bundleInfo in customManifest.BundleInfos) { if (bundleInfo.Value.Name == assetReference.fileName) { crc32 = bundleInfo.Value.CRC; } } apendToName = "_" + crc32; } var newPath = Path.Combine(_exportDirectory, assetReference.fileName + apendToName + assetReference.extension); if (!File.Exists(newPath)) { File.Copy(assetReference.absolutePath, newPath); } } }
private IEnumerator InitProcess() { Debug.Log("Start Init process"); resourceStorage = new ResourceStorage(100); var manifestLoader = new WebRequestLoader(coroutineManager); manifestLoader.RegisterResourceCreator(new StringDataCreator()); UnityResourceFromBundleLoader resFromBundlesLoader = new UnityResourceFromBundleLoader(coroutineManager); WebRequestBundlesLoader bundlesLoader = new WebRequestBundlesLoader(serverStaticPath, coroutineManager); resourceStorage.RegisterResourceLoader(manifestLoader); resourceStorage.RegisterResourceLoader(resFromBundlesLoader); resourceStorage.RegisterResourceLoader(bundlesLoader); //Load Manifest ManifestResourceHolder manifestHolder = new ManifestResourceHolder(); var manifestLoadingOperation = resourceStorage.LoadResource <string>(manifestHolder, Path.Combine(serverStaticPath, manifestName)); yield return(manifestLoadingOperation); Debug.Log("Manifest loaded: " + manifestLoadingOperation.Resource); var jsonSerializer = new JsonSerializer(new JsonSerializerSettings { Formatting = Formatting.Indented }, Encoding.UTF8); var manifestAsJson = jsonSerializer.DeserializeString <AssetBundleManifest>(manifestLoadingOperation.Resource); bundlesLoader.Manifest.AddManifestPart(manifestAsJson); resourceStorage.ReleaseAllOwnerResourcesFromCache(manifestHolder); _prefabsResourceHolder = new PrefabsResourceHolder(); Debug.Log("Init process pass"); }