public IEnumerator MonoLoadByResourcesAsync(string path, Type resType, LoadCallBack callback) { ResourceRequest status = null; try { if (resType == null) { status = Resources.LoadAsync(path); } else { status = Resources.LoadAsync(path, resType); } } catch (Exception e) { Debug.LogError(e); m_loadState.isDone = true; m_loadState.progress = 1; callback(m_loadState, null); yield break; } while (!status.isDone) { m_loadState.UpdateProgress(status); callback(m_loadState, null); yield return(0); } m_loadState.UpdateProgress(status); callback(m_loadState, status.asset); }
static int LoadAsync(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); string arg0 = ToLua.CheckString(L, 1); LoadCallBack arg1 = null; LuaTypes funcType2 = LuaDLL.lua_type(L, 2); if (funcType2 != LuaTypes.LUA_TFUNCTION) { arg1 = (LoadCallBack)ToLua.CheckObject(L, 2, typeof(LoadCallBack)); } else { LuaFunction func = ToLua.ToLuaFunction(L, 2); arg1 = DelegateFactory.CreateDelegate(typeof(LoadCallBack), func) as LoadCallBack; } ResourceManager.LoadAsync(arg0, arg1); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private void GetSharedResourceCb(LoadCallBack loadCb, AssetBundleInfo info = null) { UnityEngine.Object assetInPool = XSingleton <XResourceLoaderMgr> .singleton.GetAssetInPool(this.hash); XSingleton <XResourceLoaderMgr> .singleton.AssetsRefRetain(this.hash); loadCb(assetInPool, this.location, true); }
IEnumerator _LoadNormalScene(GameSceneData data, LoadCallBack loadHandler, int loadingType = 1, params object[] args) { float startPercent = 0; yield return(new WaitForSeconds(0.1f)); //GameObject[] sceneObject = GameObject.FindGameObjectsWithTag("scene"); //for (int i = 0; i < sceneObject.Length; i++) //{ // sceneObject[i].SetActive(false); //} yield return(new WaitForSeconds(0.1f)); int startProgress = (int)(startPercent * 100); int displayProgress = startProgress; int toProgress = startProgress; AsyncOperation op = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(data.levelName); op.allowSceneActivation = false; while (op.progress < 0.9f) { toProgress = startProgress + (int)(op.progress * (1.0f - startPercent) * 100); while (displayProgress < toProgress) { ++displayProgress; SetProgress(displayProgress); yield return(null); } yield return(null); } toProgress = 100; while (displayProgress < toProgress) { ++displayProgress; SetProgress(displayProgress); yield return(null); } op.allowSceneActivation = true; yield return(new WaitForSeconds(0.1f)); if (data.ResRefreshPointsPath.Length > 1) { GameObject point = Res.ResourceManager.Instance.Instantiate <GameObject>(data.ResRefreshPointsPath); point.transform.parent = null; point.transform.Reset(); } yield return(new WaitForSeconds(1f)); if (loadHandler != null) { loadHandler(args); } }
// //====================================================================================== /// <summary> /// 加载普通的场景 /// </summary> /// <param name="sceneName"></param> /// <param name="startPercent"></param> /// <returns></returns> public void LoadNormalScene(int sceneId, LoadCallBack loadHandler, int loadingType = 1, params object[] args) { GameSceneData data = GameSceneData.GetByID(sceneId); if (data == null) { Debuger.LogError("场景ID错误-" + sceneId); } LoadNormalScene(data, loadHandler, loadingType, args); }
IEnumerator SceneLoadIE(string sceneName, LoadCallBack loadCallBack = null) { async = SceneManager.LoadSceneAsync(sceneName); yield return(async); if (loadCallBack != null) { loadCallBack(); } }
public IEnumerator DelayToInvokeDo(float delaySeconds, LoadCallBack callBack = null) { yield return(new WaitForSeconds(delaySeconds)); if (callBack != null) { callBack(); } }
public void CancelLoad(LoadCallBack cb) { for (int i = this.loadCbList.Count - 1; i >= 0; i--) { if (this.loadCbList[i].loadCb == cb) { this.loadCbList.RemoveAt(i); } } }
public void LoadAsyn <T>(string name, LoadCallBack <T> callBack) where T : UnityEngine.Object { string abName = GetAbName(name); GetAssetBundleAsyn(abName, assetBundle => { SingleAssetLoader <T> assetLoader = new SingleAssetLoader <T>(assetBundle, name, callBack); assetLoader.Load(); }); }
private void CreateFromPrefabCb(LoadCallBack loadCb, AssetBundleInfo info = null) { UnityEngine.Object assetInPool = XSingleton <XResourceLoaderMgr> .singleton.GetAssetInPool(this.hash); GameObject gameObject = UnityEngine.Object.Instantiate(assetInPool) as GameObject; XSingleton <XResourceLoaderMgr> .singleton.AssetsRefRetain(this.hash); XSingleton <XResourceLoaderMgr> .singleton.LogReverseID(gameObject, this.hash); loadCb(gameObject, this.location, false); }
public static void LoadAsync(string name, LoadCallBack callBack) { string path = ResourcesConfigManager.GetResourcePath(name); if (m_gameLoadType == ResLoadLocation.Resource) { ResourceIOTool.ResourceLoadAsync(path, callBack); } else { AssetsBundleManager.LoadAsync(path, callBack); } }
/// <summary> /// 加载图集 /// </summary> /// <param name="url">图集路径</param> /// <param name="name">图集的名称</param> /// <param name="loadCallBack">图集加载完成回调</param> /// <param name="isCache">是否缓存,默认不缓存</param> public void LoadAtlas(string url, string name, LoadCallBack loadCallBack, bool isCache = false) { this.loadCallBack = loadCallBack; this.isCache = isCache; if (atlasDic.ContainsKey(name)) { loadCallBack(atlasDic[name]); } else { AssetManager.Instance.LoadAsset <GameObject>(url, LoadAtlasCallBack1, name); } }
private IEnumerator LoadSceneBundle(string name, LoadCallBack loadHandler, params object[] args) { AsyncOperation async = SceneManager.LoadSceneAsync(name); yield return(async); Resources.UnloadUnusedAssets(); GC.Collect(); if (loadHandler != null) { loadHandler(args); } }
public void LoadAtlasHold(string holdUrl, string normalName, LoadCallBack loadCallBack, bool isCache = false) { this.loadCallBack = loadCallBack; this.isCache = isCache; if (atlasDic.ContainsKey(normalName)) { loadCallBack(atlasDic[normalName]); } else { AssetManager.Instance.LoadAsset <GameObject>(holdUrl, LoadAtlasHoldCallBack); } }
private IEnumerator LoadSceneBundle(string name, LoadCallBack loadHandle, params object[] args) { async = SceneManager.LoadSceneAsync(name); yield return(async); Resources.UnloadUnusedAssets(); GC.Collect(); Debug.Log(name + " Scene is loaded"); if (loadHandle != null) { loadHandle(args); } async = null; }
private IEnumerator LoadSceneBundleAsync(string name, LoadCallBack loadhandler, params object[] args) //开一个协程去异步加载场景 { AsyncOperation async = Application.LoadLevelAsync(name); yield return(async); Resources.UnloadUnusedAssets(); GC.Collect(); //卸载场景的时候手动调用GC回收 if (loadhandler != null) { loadhandler(args); } }
public IEnumerator MonoLoadByResourcesAsync(string path, LoadCallBack callback) { ResourceRequest status = Resources.LoadAsync(path); while (!status.isDone) { m_loadState.UpdateProgress(status); callback(m_loadState, null); yield return(0); } m_loadState.UpdateProgress(status); callback(m_loadState, status.asset); }
/// <summary> /// 异步读取一个资源 /// </summary> /// <param name="name">>资源Key,必须在资源表中</param> /// <param name="callBack">回调,返回加载进度和目标资源</param> public static void LoadAsync(string name, LoadCallBack callBack) { try { if (s_bundles.ContainsKey(name)) { //如果加载完了就直接回调 //如果没有加载完,就缓存起来,等到加载完了一起回调 if (s_bundles[name] != null) { callBack(LoadState.CompleteState, s_bundles[name].mainAsset); } else { //等待加载完毕再一起回调,这里先缓存起来 if (LoadAsyncDict.ContainsKey(name)) { LoadAsyncDict[name] += callBack; } else { LoadAsyncDict.Add(name, callBack); } } } else { //先占位,避免重复加载 s_bundles.Add(name, null); LoadBundleAsync(name, (LoadState state, Bundle bundlle) => { if (state.isDone) { callBack(state, bundlle.mainAsset); } else { callBack(state, null); } }); } } catch (Exception e) { Debug.LogError("LoadAsync: " + e.ToString()); } }
public static void LoadAsync(string name, LoadCallBack callBack) { if (name == null) { throw new Exception("ResourceManager LoadAsync -> name is null !"); } string path = ResourcesConfigManager.GetResourcePath(name); if (m_gameLoadType == ResLoadLocation.Resource) { ResourceIOTool.ResourceLoadAsync(path, null, callBack); } else { AssetsBundleManager.LoadAsync(path, null, callBack); } }
public static void LoadAsync(string name, LoadCallBack callBack) { ResourcesConfig packData = ResourcesConfigManager.GetBundleConfig(name); if (packData == null) { return; } if (m_gameLoadType == ResLoadLocation.Resource) { ResourceIOTool.ResourceLoadAsync(packData.path, callBack); } else { AssetsBundleManager.LoadAsync(name, callBack); } }
/** * 通过assetbundle名字取到assetbundle * 异步加载assetbundle * */ public void GetAssetBundleAsyn(string name, LoadCallBack <AssetBundle> callBack) { string abPath = this.GetAbsolutePath(name); AssetBundle bundle = null; if (abLoadDic.TryGetValue(abPath, out bundle)) { if (callBack != null) { callBack(bundle); } return; } LoadCallBack <AssetBundle> addMapCallBack = (assetBundle => { abLoadDic.Add(abPath, assetBundle); if (callBack != null) { callBack(assetBundle); } }); SingleAssetBundleLoader loaderData = new SingleAssetBundleLoader(name, abPath, addMapCallBack); string[] dependencies = mainfest.GetAllDependencies(name); int number = 0; LoadCallBack <AssetBundle> loadEndCallback = (assetbundle => { number += 1; if (number == dependencies.Length) { loaderData.Load(); } }); if (dependencies.Length > 0) { foreach (string dependency in dependencies) { GetAssetBundleAsyn(dependency, loadEndCallback); } } else { loaderData.Load(); } }
public static void LoadAsync(string name, LoadCallBack callBack) { BundleConfig packData = BundleConfigManager.GetBundleConfig(name); if (packData == null) { return; } ResLoadType loadTypeTmp = GetLoadType(packData.loadType); if (loadTypeTmp == ResLoadType.Resource) { ResourceIOTool.ResourceLoadAsync(packData.path, callBack); } else { AssetsBundleManager.LoadAsync(name, callBack); } }
/// <summary> /// 基础加载 /// </summary> /// <param name="type">1.本地 0.网络</param> /// <param name="imagePath"></param> /// <param name="image"></param> /// <returns></returns> public static IEnumerator LoadAsyncBaseTexture(int type, string imagePath, LoadCallBack <Texture2D> callBack) { string filePath = "file://" + imagePath; if (type == 1) { filePath = "file://" + imagePath; } else { filePath = imagePath; } WWW www = new WWW(filePath); yield return(www); if (callBack != null) { callBack.loadSuccess(www.texture); } }
public static Delegate LoadCallBack(LuaFunction func, LuaTable self, bool flag) { if (func == null) { LoadCallBack fn = delegate(LoadState param0, object param1) { }; return(fn); } if (!flag) { LoadCallBack_Event target = new LoadCallBack_Event(func); LoadCallBack d = target.Call; target.method = d.Method; return(d); } else { LoadCallBack_Event target = new LoadCallBack_Event(func, self); LoadCallBack d = target.CallWithSelf; target.method = d.Method; return(d); } }
public SingleAssetBundleLoader(string assetName, string assetPath, LoadCallBack <AssetBundle> callBack) : base(callBack) { this.AssetName = assetName; this.AssetPath = assetPath; }
public void MonoLoadMethod(string path, LoadCallBack callback) { StartCoroutine(MonoLoadByResourcesAsync(path, callback)); }
public static void ResourceLoadAsync(string path, LoadCallBack callback) { GetInstance().MonoLoadMethod(path, callback); }
public static void ResourceLoadAsync(string path,LoadCallBack callback) { GetInstance().MonoLoadMethod(path, callback); }
public IEnumerator MonoLoadByResourcesAsync(string path, LoadCallBack callback) { ResourceRequest status = Resources.LoadAsync(path); LoadState loadState = new LoadState(); while (!status.isDone) { loadState.UpdateProgress(status); callback(loadState,null); yield return 0; } loadState.UpdateProgress(status); callback(loadState, status.asset); }
public static IEnumerator LoadAsyncAssetBundlesImageForBytes(string assetPath, string objName, Image image, LoadCallBack <Sprite> callBack) { assetPath = assetPath.ToLower(); AssetBundleCreateRequest assetRequest = AssetBundle.LoadFromFileAsync(Application.dataPath + "/AssetBundles/" + assetPath); yield return(assetRequest); AsyncListAssetBundle.Add(assetRequest.assetBundle); AssetBundleRequest objRequest = assetRequest.assetBundle.LoadAssetAsync <TextAsset>(objName); yield return(objRequest); AsyncListAssetBundle.Remove(assetRequest.assetBundle); assetRequest.assetBundle.Unload(false); TextAsset textAsset = objRequest.asset as TextAsset; Texture2D texture = new Texture2D(1, 1); texture.LoadImage(textAsset.bytes); image.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); if (callBack != null) { callBack.loadSuccess(image.sprite); } }
public static IEnumerator LoadAsyncAssetBundlesTexture2DForBytes(string assetPath, string objName, LoadCallBack <Texture2D> callBack) { assetPath = assetPath.ToLower(); AssetBundleCreateRequest assetRequest = AssetBundle.LoadFromFileAsync(Application.dataPath + "/AssetBundles/" + assetPath); yield return(assetRequest); AsyncListAssetBundle.Add(assetRequest.assetBundle); AssetBundleRequest objRequest = assetRequest.assetBundle.LoadAssetAsync <TextAsset>(objName); yield return(objRequest); AsyncListAssetBundle.Remove(assetRequest.assetBundle); assetRequest.assetBundle.Unload(false); TextAsset textAsset = objRequest.asset as TextAsset; Texture2D texture = new Texture2D(1, 1); texture.LoadImage(textAsset.bytes); if (callBack != null) { callBack.loadSuccess(texture); } }
public void LoadScene(string name, LoadCallBack loadHandler, params object[] args) { StartCoroutine(LoadSceneBundle(name, loadHandler, args)); }