IEnumerator IE_Load() { string terrainPath = Application.streamingAssetsPath + "/BuildScenes_Scene.assetbundle"; if (System.IO.File.Exists(terrainPath)) { byte[] buffer; using (FileStream stream = new FileStream(terrainPath, FileMode.Open, FileAccess.Read)) { buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); } AssetBundleCreateRequest assetRequest = AssetBundle.CreateFromMemory(buffer); yield return(assetRequest); AssetBundle assetBundle = assetRequest.assetBundle; Application.LoadLevel("BuildScenes"); //if (assetRequest.isDone) //{ // terrainGO = Instantiate(assetBundle.mainAsset) as GameObject; // terrainGO.transform.parent = transform; //} } }
public CAssetBundleParser(string relativePath, byte[] bytes, Action <AssetBundle> callback = null) { if (Debug.isDebugBuild) { _startTime = Time.realtimeSinceStartup; } Callback = callback; RelativePath = relativePath; var func = BundleBytesFilter ?? DefaultParseAb; var abBytes = func(relativePath, bytes); switch (Mode) { case CAssetBundleParserMode.Async: CreateRequest = AssetBundle.CreateFromMemory(abBytes); CreateRequest.priority = _autoPriority++; // 后进先出, 一个一个来 CResourceModule.Instance.StartCoroutine(WaitCreateAssetBundle(CreateRequest)); break; case CAssetBundleParserMode.Sync: OnFinish(AssetBundle.CreateFromMemoryImmediate(abBytes)); break; default: throw new Exception("Error CAssetBundleParserMode: " + Mode); } }
private IEnumerator InitRes(string resUrl) { if (!isResourcesPath) { if (!m_Resource_Requests.ContainsKey(resUrl)) { string filePath = FileWriteBaseUrl + resUrl; filePath += ".unity3d"; // Debug.Log(filePath); byte[] datas = null; datas = FileHelper.ReadFile(filePath); if (datas == null) { filePath = AssetbundleBaseURL + resUrl; filePath += ".unity3d"; Debug.Log(filePath); datas = FileHelper.ReadFile(filePath); } AssetBundleCreateRequest request = null; if (datas != null) { request = AssetBundle.CreateFromMemory(datas); m_Resource_Requests[resUrl] = request; } else { m_Resource_Requests[resUrl] = null; } yield return(request); } } }
IEnumerator LoadProgressShow() { // WWW download =new WWW(Application.persistentDataPath+"/" + SceneManager.PreSceneStr + ".unity3d"); if (!GameObject.FindGameObjectWithTag("GameController").GetComponent <SceneManager>().IsInAvailableScene(SceneManager.curSceneStr)) { byte[] bs = File.ReadAllBytes(Application.persistentDataPath + "/" + SceneManager.curSceneStr + ".unity3d"); AssetBundleCreateRequest abq = AssetBundle.CreateFromMemory(bs); while (!abq.isDone) { yield return(null); Debug.Log(abq.progress); } yield return(abq); var bundle = abq.assetBundle; yield return(StartCoroutine(Load())); bundle.Unload(false); } else { yield return(StartCoroutine(Load())); } }
public static IEnumerator DownloadAssets() { if (Loaded) { yield break; } if (File.Exists(CachePath)) { var req = AssetBundle.CreateFromMemory(File.ReadAllBytes(CachePath)); yield return(req); if (req == null || req.assetBundle == null) { } else { Asset = req.assetBundle; Loaded = true; yield break; } } WWW www = new WWW(DownloadPath); yield return(www); if (www.assetBundle != null) { Asset = www.assetBundle; File.WriteAllBytes(CachePath, www.bytes); Loaded = true; } }
AssetBundleCreateRequest LoadFromMemoryAsync(byte[] bytes) { #if UNITY_5_2 return(AssetBundle.CreateFromMemory(bytes)); #else return(AssetBundle.LoadFromMemoryAsync(bytes)); #endif }
private static int CreateFromMemory(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); AssetBundleCreateRequest o = AssetBundle.CreateFromMemory(LuaScriptMgr.GetArrayNumber <byte>(L, 1)); LuaScriptMgr.PushObject(L, o); return(1); }
public static IEnumerator _CreateFromMemory(string path, Handle_CreateFromMemory handle) { int size = 0; AssetBundleCreateRequest bundleRequest = AssetBundle.CreateFromMemory(ResourceCommon.getAssetBundleFileBytes(path, ref size)); yield return(bundleRequest); handle(bundleRequest, size); }
/// <summary> /// 创建 /// </summary> /// <param name="decryptedData"></param> /// <returns></returns> IEnumerator LoadBundle(byte[] decryptedData) { AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(decryptedData); yield return(acr); assetBundel = acr.assetBundle; Instantiate(assetBundel.Load("Cube")); }
private IEnumerator LoadCustomAssets() { AssetBundleCreateRequest abcr = AssetBundle.CreateFromMemory(File.ReadAllBytes(Application.dataPath + "/RCAssets.unity3d")); yield return(abcr); FengGameManagerMKII.RCAssets = abcr.assetBundle; FengGameManagerMKII.IsAssetLoaded = true; }
IEnumerator DowningEternalBundle(string name, HandleFinishDownLoad finishFun) { StringBuilder localPath = new StringBuilder(); localPath.Append(WWW_LOCAL_PATH); localPath.Append(name); WWW www = new WWW(localPath.ToString()); while (www.isDone == false) { yield return(www); } if (www.error != null) { LogManager.Log("error = " + www.error); LogManager.Log("error when downloading: " + name); } byte[] decryptedData = AssetManager.Inst.ExecuteDecrypt(name, www.bytes); AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(decryptedData); yield return(acr); AssetBundle bundle = acr.assetBundle; object[] ListSprite = bundle.LoadAll(typeof(UnityEngine.Sprite)); Sprite sprite = null; int size = ListSprite.Length; for (int i = 0; i < size; i++) { sprite = ListSprite[i] as Sprite; if (sprite != null && m_AssetEternalSprite.ContainsKey(sprite.name) == false) { m_AssetEternalSprite.Add(sprite.name, sprite); if (m_AssetEternalSprite.Count == m_NeedDownEternalBundle.Count) { isEternalBundleReady = true; GameEventDispatcher.Inst.dispatchEvent(GameEventID.U_EternalSpriteLoaded); } } } bundle.Unload(false); www.Dispose(); if (finishFun != null) { LogManager.LogToFile("下载完成!!!!!!!!Path:" + localPath.ToString()); finishFun(www); } LogManager.LogToFile("下载完成!!!!!!!!Path:" + localPath.ToString()); }
public void SetAsset(string path) { FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); byte[] array = new byte[fileStream.Length]; fileStream.Read(array, 0, (int)fileStream.Length); this._currAsset = AssetBundle.CreateFromMemory(array); this.assets.Add(this._currAsset); fileStream.Dispose(); fileStream.Close(); }
public static System.Collections.IEnumerator LoadAssetBundle() { AssetBundleCreateRequest bundle = AssetBundle.CreateFromMemory(File.ReadAllBytes(BundlePath)); yield return(bundle); if (bundle == null) { Debug.LogError($"Error while loading AnarchyAssets. Make sure that file \"{BundlePath}\" exists."); } Bundle = bundle.assetBundle; }
public IEnumerator LoadBundleFromMemory(byte[] buffer) { AssetBundleCreateRequest bundleRequest = AssetBundle.CreateFromMemory(buffer); yield return(bundleRequest); if (bundleRequest.isDone) { bundle = bundleRequest.assetBundle; CheckBundle(bundle); } }
public static IEnumerator LoadFonts() { if (GUI.Styles.Fonts != null) { yield break; } var bundle = AssetBundle.CreateFromMemory(System.IO.File.ReadAllBytes(Application.dataPath + "/Resources/ggmfonts.unity3d")); yield return(bundle); GUI.Styles.Fonts = new[] { (Font)bundle.assetBundle.Load("chemistry"), (Font)bundle.assetBundle.Load("tahoma"), (Font)bundle.assetBundle.Load("rabelo"), (Font)bundle.assetBundle.Load("bienetresocial"), (Font)bundle.assetBundle.Load("mandatory") }; FontsLoaded = true; }
static public System.Collections.IEnumerator ProcessAB(byte[] bytes, omnitymono.DLLExports.ABHold abhold) { #if AB_CREATEFROMMEMORY AssetBundleCreateRequest abr = AssetBundle.CreateFromMemory(bytes); #else AssetBundleCreateRequest abr = AssetBundle.LoadFromMemoryAsync(bytes); #endif while (!abr.isDone) { yield return(null); } abhold.ab = abr.assetBundle; }
IEnumerator DowningEditorBundle(string name, HandleFinishDownLoad finishFun) { StringBuilder localPath = new StringBuilder(); localPath.Append(WWW_LOCAL_PATH); localPath.Append(name); WWW www = new WWW(localPath.ToString()); while (www.isDone == false) { yield return(www); } if (www.error != null) { LogManager.Log("error = " + www.error); LogManager.Log("error when downloading: " + name); } byte[] decryptedData = AssetManager.Inst.ExecuteDecrypt(name, www.bytes); AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(decryptedData); yield return(acr); AssetBundle bundle = acr.assetBundle; if (bundle == null) { Debug.LogError("!!!Error: DowningEditorBundle() bundle is null:" + name); yield return(1); } object[] EditorList = bundle.LoadAll(typeof(UnityEngine.Object)); UnityEngine.Object go = null; for (int i = 0; i < EditorList.Length; i++) { go = EditorList[i] as UnityEngine.Object; if (go != null && m_EditorAssetDynamicBundle.ContainsKey(go.name) == false) { m_EditorAssetDynamicBundle.Add(go.name, go); } } bundle.Unload(false); www.Dispose(); if (finishFun != null) { LogManager.LogToFile("下载完成!!!!!!!!Path:" + localPath.ToString()); finishFun(www); } }
//start binary load private IEnumerator StartBinary() { this.m_cABRequest = AssetBundle.CreateFromMemory(this.m_cData); for (; !this.m_cABRequest.isDone;) { this.m_fProgess = this.m_cABRequest.progress; yield return(new WaitForEndOfFrame()); } if (this.m_cFinishCallBack != null) { this.m_cFinishCallBack("", this.m_cABRequest.assetBundle); } GameObject.Destroy(this.gameObject); }
/// <summary> /// 载入对象 /// </summary> /// <returns></returns> IEnumerator OnLoadObject(string name, string text = null) { string uri = AssetPath + name.ToLower() + ".assetbundle"; byte[] stream = File.ReadAllBytes(uri); AssetBundleCreateRequest request = AssetBundle.CreateFromMemory(stream); //关联数据的素材绑定 yield return(request); io.panelManager.OnRequestResource(name, request.assetBundle); //回传给面板管理器 if (Debug.isDebugBuild) { Debug.LogWarning("LoadFile::>> " + uri + " " + request.assetBundle); } }
public override void OnStart(PartModule.StartState state) { if (!enabled) { return; } if ((state & PartModule.StartState.PreLaunch) != 0) { newFlight = true; doLightningJoke = rand.Next(10) == 0; if (doLightningJoke) { tutorial = (MissionControlTutorial)ScenarioRunner.fetch.AddModule("MissionControlTutorial"); } doRotationJoke = rand.Next(10) == 0; if (doRotationJoke) { double[] rotationPeriods = { 1600, 1554, 1500, 1400, 1300, 1200, 1100, 1000, 750, 500, 250, 100, 50, 25, 10, 5, 1 }; vessel.mainBody.rotationPeriod = rotationPeriods[rand.Next(rotationPeriods.Length)]; } if (lightningBundle == null) { lightningBundle = AssetBundle.CreateFromMemory(Properties.Resources.lightning); } } if (state != PartModule.StartState.Editor) { Material munmat = GameObject.Find("scaledSpace").transform.Find("Mun").gameObject.renderer.material; if (munmat.mainTexture.name != "muntroll") { Texture2D troll = new Texture2D(1024, 512, TextureFormat.ARGB32, true); troll.LoadImage(Properties.Resources.troll); troll.name = "muntroll"; munmat.mainTexture = troll; } } UnlockControls(); //in case the lock somehow remains in place }
IEnumerator DownloadShopAssedBundle(string name) { StringBuilder localPath = new StringBuilder(); localPath.Append(WWW_LOCAL_PATH); localPath.Append(name); WWW www = new WWW(localPath.ToString()); while (www.isDone == false) { yield return(www); } if (www.error != null) { LogManager.Log("error = " + www.error); LogManager.Log("error when downloading: " + name); } byte[] decryptedData = AssetManager.Inst.ExecuteDecrypt(name, www.bytes); AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(decryptedData); yield return(acr); m_ShopAssetList = new List <Sprite>(); AssetBundle bundle = acr.assetBundle; object[] ListSprite = bundle.LoadAll(typeof(UnityEngine.Sprite)); Sprite sprite = null; int size = ListSprite.Length; for (int i = 0; i < size; i++) { sprite = ListSprite[i] as Sprite; if (sprite != null && !m_ShopAssetList.Contains(sprite)) { m_ShopAssetList.Add(sprite); } } bundle.Unload(false); www.Dispose(); GameEventDispatcher.Inst.dispatchEvent(GameEventID.UI_ShopAdAssetDownload); }
private static IEnumerator DoLoadCreateRequestAssets(List <Resource> list, Action loaded) { var createCounter = 0; var yieldCount = 0; while (createCounter < list.Count) { var createRequests = new List <Resource>(); //Profiler.BeginSample("RecordCreateRequests"); for (int i = 0; i < SystemConfig.Instance.SynCreateRequestCount && createCounter < list.Count; i++) { var res = list[createCounter]; createCounter++; var cr = AssetBundle.CreateFromMemory(res.fileData); if (cr == null) { LoggerHelper.Error("Create failure: " + res.RelativePath); continue; } res.createRequest = cr; createRequests.Add(res); res.fileData = null; } //Profiler.EndSample(); int index = 0; while (index < createRequests.Count) { var res = list[yieldCount]; yieldCount++; index++; yield return(res.createRequest); //Profiler.BeginSample("RecordLoadAll"); if (res.createRequest != null && res.createRequest.assetBundle != null) { res.createRequest.assetBundle.LoadAll(); res.IsDone = true; res.m_object = res.createRequest.assetBundle.mainAsset; } //Profiler.EndSample(); } } if (loaded != null) { loaded(); } }
private IEnumerator LoadCustomAssets() { AssetBundleCreateRequest abcr = AssetBundle.CreateFromMemory(File.ReadAllBytes(Application.dataPath + "/RCAssets.unity3d")); yield return(abcr); FengGameManagerMKII.RCAssets = abcr.assetBundle; using (WWW www = new WWW("file:///" + Application.dataPath + "/Resources/AoTTG_2_LOGO.PNG")) { yield return(www); AOT_2_LOGO = www.texture; } FengGameManagerMKII.IsAssetLoaded = true; }
public IEnumerator LoadRes(string fileName) { if (!debug) { string path = #if UNITY_EDITOR "file:///" + UnityEngine.Application.persistentDataPath; #elif UNITY_IPHONE "file:///" + Application.persistentDataPath; #elif UNITY_ANDROID "file:///" + Application.persistentDataPath; #endif path += "/Data/"; path += fileName; WWW www = new WWW(path + ".assetbundle"); // UnityEngine.Application.persistentDataPath yield return(www); TextAsset txt = www.assetBundle.Load(fileName, typeof(TextAsset)) as TextAsset; byte[] data = txt.bytes; byte[] newdata = AES.AESDecrypt(data); // StartCoroutine(LoadBundle(newdata)); //创建资源 AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(newdata); yield return(acr); AssetBundle assetBundle = acr.assetBundle; assetBundle.name = fileName; ABS.assetBundleList.Add(assetBundle); //www.assetBundle.Unload(false); //加载完成事件 lock (o)//加锁 { tempNum++; } if (tempNum == total) { if (OnLoaded != null) { OnLoaded(fileName, true, "加载成功了"); } } } }
public KAssetBundleParser(string relativePath, byte[] bytes, Action <AssetBundle> callback = null) { if (EngineConfig.instance.IsDebugMode) { _startTime = Time.realtimeSinceStartup; } Callback = callback; RelativePath = relativePath; var func = BundleBytesFilter; if (func == null) { func = DefaultParseAb; } var abBytes = func(relativePath, bytes); switch (Mode) { case CAssetBundleParserMode.Async: #if UNITY_5 CreateRequest = AssetBundle.LoadFromMemoryAsync(abBytes); #else CreateRequest = AssetBundle.CreateFromMemory(abBytes); #endif CreateRequest.priority = _autoPriority++; // 后进先出, 一个一个来 var rManager = AppFacade.Instance.GetManager <KResourceManager>(); if (rManager != null) { rManager.StartCoroutine(WaitCreateAssetBundle(CreateRequest)); } break; case CAssetBundleParserMode.Sync: #if UNITY_5 OnFinish(AssetBundle.LoadFromMemory(abBytes)); #else OnFinish(AssetBundle.CreateFromMemoryImmediate(abBytes)); #endif break; default: throw new Exception("Error CAssetBundleParserMode: " + Mode); } }
public override FrameState Update() { if (request == null) { byte[] bs = ResmgrNative.Instance.LoadFromCacheDirect(path); request = AssetBundle.CreateFromMemory(bs); return(FrameState.Slow); } if (request.isDone) { onload(request.assetBundle, tag); return(FrameState.Finish); } else { return(FrameState.Nothing); } }
public static int CreateFromMemory_s(IntPtr l) { int result; try { byte[] binary; LuaObject.checkArray <byte>(l, 1, out binary); AssetBundleCreateRequest o = AssetBundle.CreateFromMemory(binary); LuaObject.pushValue(l, true); LuaObject.pushValue(l, o); result = 2; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
/// <summary> /// lua bundle /// </summary> /// <returns></returns> private IEnumerator DecryptLuaBundle(string luaPath, bool isStreaming, LuaFunction onLoadedFn) { luaPath = CUtils.CheckWWWUrl(luaPath); Debug.Log("loadluabundle:" + luaPath); WWW luaLoader = new WWW(luaPath); yield return(luaLoader); if (luaLoader.error == null) { byte[] byts = CryptographHelper.Decrypt(luaLoader.bytes, DESHelper.instance.Key, DESHelper.instance.IV); AssetBundleCreateRequest abcreq = null; #if UNITY_5_0 || UNITY_5_1 || UNITY_5_2 abcreq = AssetBundle.CreateFromMemory(byts); #else abcreq = AssetBundle.LoadFromMemoryAsync(byts); #endif yield return(abcreq); var item = abcreq.assetBundle; TextAsset[] all = item.LoadAllAssets <TextAsset>(); foreach (var ass in all) { SetRequire(ass.name, ass); } item.Unload(false); luaLoader.Dispose(); } else { Debug.LogWarning(luaLoader.error); } if (onLoadedFn != null) { onLoadedFn.call(); } else { DoMain(); } }
IEnumerator LogAsset() { //StreamWriter stream = File.CreateText("D:/test/apkpure/filelist.txt"); //string[] files = Directory.GetFiles("D:/test/apkpure/out/"); StreamWriter stream = File.CreateText("D:/test/filelist2.txt"); string[] files = Directory.GetFiles("D:/test/lib/base.apk/assets/bin/Data"); Debug.Log(files.Length); for (int i = 0; i < files.Length; i++) { try { stream.WriteLine(files[i].Substring(files[i].LastIndexOf('/') + 1)); } catch (System.Exception ex) { Debug.Log(ex); break; } byte[] src = File.ReadAllBytes(files[i]); AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.CreateFromMemory(src); yield return(assetBundleCreateRequest); AssetBundle b = assetBundleCreateRequest.assetBundle; string[] assetNames = b.GetAllAssetNames(); for (int j = 0; j < assetNames.Length; j++) { stream.WriteLine(assetNames[j]); } b.Unload(true); stream.WriteLine(); } stream.Close(); Debug.Log("ok"); }
override protected IEnumerator initAssetByCoroutine() { AssetBundleCreateRequest createReq = AssetBundle.CreateFromMemory(m_bytes); yield return(createReq); m_bundle = createReq.assetBundle; if (m_bundle != null) { refCountResLoadResultNotify.resLoadState.setSuccessLoaded(); } else { refCountResLoadResultNotify.resLoadState.setFailed(); } refCountResLoadResultNotify.loadResEventDispatch.dispatchEvent(this); clearInstanceListener(); }