/// Resource异步加载; private IEnumerator <float> LoadAsync(string path, ResourceAssetProxy proxy, Action <float> progress) { if (string.IsNullOrEmpty(path)) { yield break; } ResourceRequest request = Resources.LoadAsync(path); while (request.progress < 0.99f) { progress?.Invoke(request.progress); yield return(Timing.WaitForOneFrame); } while (!request.isDone) { yield return(Timing.WaitForOneFrame); } if (null == request.asset) { LogHelper.PrintError($"[ResourceMgr]LoadAsync load asset:{path} failure."); } //先等一帧; yield return(Timing.WaitForOneFrame); if (proxy != null) { proxy.OnFinish(request.asset); } else { LogHelper.PrintError($"[ResourceMgr]LoadAsync proxy is null:{path}."); } }
/// <summary> /// Resource异步加载; /// </summary> /// <param name="path"></param> /// <param name="progress"></param> /// <returns></returns> public ResourceAssetProxy LoadResourceAsync(string path, Action <float> progress) { if (string.IsNullOrEmpty(path)) { return(null); } ResourceAssetProxy proxy = PoolMgr.singleton.GetCsharpObject <ResourceAssetProxy>(); proxy.Initialize(path); CoroutineMgr.singleton.RunCoroutine(LoadAsync(path, proxy, progress)); return(proxy); }
/// <summary> /// Resource同步加载; /// </summary> /// <param name="path"></param> /// <returns></returns> public ResourceAssetProxy LoadResourceProxy(string path) { if (string.IsNullOrEmpty(path)) { return(null); } ResourceAssetProxy proxy = PoolMgr.singleton.GetCsharpObject <ResourceAssetProxy>(); proxy.Initialize(path); Object asset = Resources.Load(path); if (asset == null) { LogHelper.PrintError($"[ResourceMgr]LoadResourceProxy load asset:{path} failure."); } proxy.OnFinish(asset); return(proxy); }
static int LoadResourceProxy(IntPtr L) { #if UNITY_EDITOR ToluaProfiler.AddCallRecord("Framework.ResourceMgr.LoadResourceProxy"); #endif try { ToLua.CheckArgsCount(L, 2); Framework.ResourceMgr obj = (Framework.ResourceMgr)ToLua.CheckObject <Framework.ResourceMgr>(L, 1); string arg0 = ToLua.CheckString(L, 2); Framework.ResourceAssetProxy o = obj.LoadResourceProxy(arg0); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int LoadResourceAsync(IntPtr L) { #if UNITY_EDITOR ToluaProfiler.AddCallRecord("Framework.ResourceMgr.Register"); #endif try { int count = LuaDLL.lua_gettop(L); if (count == 2) { Framework.ResourceMgr obj = (Framework.ResourceMgr)ToLua.CheckObject <Framework.ResourceMgr>(L, 1); string arg0 = ToLua.CheckString(L, 2); Framework.ResourceAssetProxy o = obj.LoadResourceAsync(arg0); ToLua.PushObject(L, o); return(1); } else if (count == 3) { Framework.ResourceMgr obj = (Framework.ResourceMgr)ToLua.CheckObject <Framework.ResourceMgr>(L, 1); string arg0 = ToLua.CheckString(L, 2); System.Action <float> arg1 = (System.Action <float>)ToLua.CheckDelegate <System.Action <float> >(L, 3); Framework.ResourceAssetProxy o = obj.LoadResourceAsync(arg0, arg1); ToLua.PushObject(L, o); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: Framework.ResourceMgr.LoadResourceAsync")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }