//async read file public static CFile AsyncReadFile(string path, FINISH_CALLBACK finish_callback, ERROR_CALLBACK error_callback = null) { CFile cfile = new CFile(); file.AsyncBeginReadFile(path, finish_callback, error_callback); return(cfile); }
//async read file public static FileLoader AsyncReadFile(string path, FINISH_CALLBACK finish_callback, ERROR_CALLBACK error_callback = null) { FileLoader cfile = new FileLoader(); cfile.AsyncBeginReadFile(path, finish_callback, error_callback); return(cfile); }
//init binary private void Init( byte[] binary, FINISH_CALLBACK finish_callback = null, ERROR_CALLBACK error_callback = null ) { this.m_cData = binary; Init(finish_callback, error_callback); }
//init path private void Init( string path, FINISH_CALLBACK finish_callback = null, ERROR_CALLBACK error_callback = null ) { this.m_strPath = path; Init(finish_callback, error_callback); }
//Start async load the assetbundle public static AsyncLoader StartLoad(AssetBundle asset, string resName , FINISH_CALLBACK finish_callback) { if(sGoInstance == null) { sGoInstance = new GameObject("AsyncLoader"); } AsyncLoader loader = sGoInstance.AddComponent<AsyncLoader>(); loader.StartCoroutine(loader.GoLoader(asset, resName,finish_callback)); return loader; }
private AssetBundleRequest m_cRequest; //The load request //Start async load the assetbundle public static AsyncLoader StartLoad(AssetBundle asset, string resName, FINISH_CALLBACK finish_callback) { if (sGoInstance == null) { sGoInstance = new GameObject("AsyncLoader"); } AsyncLoader loader = sGoInstance.AddComponent <AsyncLoader>(); loader.StartCoroutine(loader.GoLoader(asset, resName, finish_callback)); return(loader); }
//init private void Init( FINISH_CALLBACK finish_callback = null, ERROR_CALLBACK error_callback = null ) { this.m_bComplete = false; this.m_cWww = null; this.m_cABRequest = null; this.m_cFinishCallBack = finish_callback; this.m_cErrorCallBack = error_callback; this.m_fProgess = 0; }
//load async by binary public static AssetBundleLoader LoadBinary(byte[] binary,FINISH_CALLBACK finish_callback = null ,ERROR_CALLBACK error_callback = null) { if(sGoInstance == null) { sGoInstance = new GameObject("AssetBundleLoader"); } AssetBundleLoader loader = sGoInstance.AddComponent<AssetBundleLoader>(); loader.Init(binary , finish_callback , error_callback); loader.StartCoroutine(loader.StartBinary()); return loader; }
//create request public static AbRequest Create(FINISH_CALLBACK finish_callback = null , ERROR_CALLBACK error_callback = null) { GameObject go = new GameObject("AbRequest"); AbRequest req = go.AddComponent<AbRequest>(); req.m_delFinishCallback = finish_callback; req.m_delErrorCallback = error_callback; req.m_iLoadIndex = 0; req.m_iCompleteNum = 0; req.m_lstPath.Clear(); req.m_lstLoader.Clear(); req.m_mapRes.Clear(); return req; }
//load async by binary public static AssetBundleLoader LoadBinary(byte[] binary, FINISH_CALLBACK finish_callback = null, ERROR_CALLBACK error_callback = null) { if (sGoInstance == null) { sGoInstance = new GameObject("AssetBundleLoader"); } AssetBundleLoader loader = sGoInstance.AddComponent <AssetBundleLoader>(); loader.Init(binary, finish_callback, error_callback); loader.StartCoroutine(loader.StartBinary()); return(loader); }
private Dictionary <string, AssetBundle> m_mapRes = new Dictionary <string, AssetBundle>(); //the resource map //create request public static AbRequest Create(FINISH_CALLBACK finish_callback = null, ERROR_CALLBACK error_callback = null) { GameObject go = new GameObject("AbRequest"); AbRequest req = go.AddComponent <AbRequest>(); req.m_delFinishCallback = finish_callback; req.m_delErrorCallback = error_callback; req.m_iLoadIndex = 0; req.m_iCompleteNum = 0; req.m_lstPath.Clear(); req.m_lstLoader.Clear(); req.m_mapRes.Clear(); return(req); }
//Begin to load private IEnumerator GoLoader(AssetBundle asset, string resName, FINISH_CALLBACK finish_callback) { this.m_delFinishCallback = finish_callback; this.m_fProgress = 0; this.m_cRequest = asset.LoadAsync(resName, typeof(UnityEngine.Object)); for (; !this.m_cRequest.isDone;) { this.m_fProgress = this.m_cRequest.progress; yield return(new WaitForEndOfFrame()); } this.m_fProgress = 1; GameObject.Destroy(this); }
//request public void Request(List <string> paths, FINISH_CALLBACK finish_callback = null, ERROR_CALLBACK error_callback = null) { this.m_FinishCallback = finish_callback; this.m_ErrorCallback = error_callback; this.m_AbRequest = AbRequest.Create(RequestFinishCallback); for (int i = 0; i < paths.Count; i++) { string path = paths[i]; if (!this.m_mapRes.ContainKey(path)) { this.m_mapRes.Add(path, null); this.m_AbRequest.Request(path); } } }
//load async by www public static AssetBundleLoader LoadWww( string path , FINISH_CALLBACK finish_callback = null, ERROR_CALLBACK error_callback = null ) { if(sGoInstance == null) { sGoInstance = new GameObject("AssetBundleLoader"); } AssetBundleLoader loader = sGoInstance.AddComponent<AssetBundleLoader>(); loader.Init(path , finish_callback , error_callback); loader.StartCoroutine(loader.StartWWW()); return loader; }
//request public void Request(List<string> paths ,FINISH_CALLBACK finish_callback = null , ERROR_CALLBACK error_callback = null) { this.m_FinishCallback = finish_callback; this.m_ErrorCallback = error_callback; this.m_AbRequest = AbRequest.Create(RequestFinishCallback); for(int i = 0 ; i < paths.Count ; i++) { string path = paths[i]; if(!this.m_mapRes.ContainKey(path)) { this.m_mapRes.Add(path,null); this.m_AbRequest.Request(path); } } }
//load async by www public static AssetBundleLoader LoadWww( string path, FINISH_CALLBACK finish_callback = null, ERROR_CALLBACK error_callback = null ) { if (sGoInstance == null) { sGoInstance = new GameObject("AssetBundleLoader"); } AssetBundleLoader loader = sGoInstance.AddComponent <AssetBundleLoader>(); loader.Init(path, finish_callback, error_callback); loader.StartCoroutine(loader.StartWWW()); return(loader); }
//Begin to load private IEnumerator GoLoader(AssetBundle asset, string resName , FINISH_CALLBACK finish_callback) { this.m_delFinishCallback = finish_callback; this.m_fProgress = 0; this.m_cRequest = asset.LoadAsync(resName, typeof(UnityEngine.Object)); for (; !this.m_cRequest.isDone; ) { this.m_fProgress = this.m_cRequest.progress; yield return new WaitForEndOfFrame(); } this.m_fProgress = 1; if(this.m_delFinishCallback != null) { this.m_delFinishCallback(resName , this.m_cRequest.asset); } GameObject.Destroy(this.gameObject); }
//async read file private void AsyncBeginReadFile(string path, FINISH_CALLBACK finish_callback, ERROR_CALLBACK error_callback) { this.m_Path = path; this.m_FinishCallback = finish_callback; this.m_ErrorCallback = error_callback; try { this.m_InputStream = new FileStream(path, FileMode.Open); this.m_Buffer = new byte[this.m_InputStream.Length]; this.m_BufferSize = 0; this.m_InputStream.BeginRead(this.m_Buffer, this.m_BufferSize, this.m_Buffer.Length, AsyncReadCallback, null); } catch (Exception e) { Debug.LogError("Error: " + e.StackTrace); if (this.m_ErrorCallback != null) { this.m_ErrorCallback(this.m_Path, e.StackTrace); } } }
//async read file private void AsyncBeginReadFile(string path , FINISH_CALLBACK finish_callback , ERROR_CALLBACK error_callback ) { this.m_Path = path; this.m_FinishCallback = finish_callback; this.m_ErrorCallback = error_callback; try { this.m_InputStream = new FileStream(path, FileMode.Open); this.m_Buffer = new byte[this.m_InputStream.Length]; this.m_BufferSize = 0; this.m_InputStream.BeginRead(this.m_Buffer, this.m_BufferSize, this.m_Buffer.Length, AsyncReadCallback, null); } catch(Exception e) { Debug.LogError("Error: " + e.StackTrace); if(this.m_ErrorCallback != null) { this.m_ErrorCallback(this.m_Path , e.StackTrace); } } }
//init binary private void Init( byte[] binary , FINISH_CALLBACK finish_callback = null , ERROR_CALLBACK error_callback = null ) { this.m_cData = binary; Init(finish_callback,error_callback); }
//init path private void Init( string path , FINISH_CALLBACK finish_callback = null, ERROR_CALLBACK error_callback = null ) { this.m_strPath = path; Init(finish_callback,error_callback); }
//async read file public static FileLoader AsyncReadFile(string path , FINISH_CALLBACK finish_callback , ERROR_CALLBACK error_callback = null) { FileLoader cfile = new FileLoader(); cfile.AsyncBeginReadFile(path , finish_callback , error_callback); return cfile; }