예제 #1
0
        private AsyncAssetProxy LoadAssetProxy_discard <T>(AssetType assetType, string assetName
                                                           , Action <T> action, Action <float> progress) where T : Object
        {
            AsyncAssetProxy proxy = PoolMgr.Instance.GetCsharpObject <AsyncAssetProxy>();

            proxy.InitProxy(assetType, assetName);
            CoroutineMgr.Instance.RunCoroutine(LoadAssetAsync_discard <T>(assetType, assetName, proxy, action, progress));
            return(proxy);
        }
예제 #2
0
        /// <summary>
        /// 异步从AssetBundle加载资源;
        /// </summary>
        /// <param name="assetType">资源类型</param>
        /// <param name="assetName">资源名字</param>
        /// <param name="progress">加载进度</param>
        /// <param name="isUsePool">资源是否使用对象池</param>
        /// <returns>异步代理</returns>
        public AsyncAssetProxy LoadAssetProxy(AssetType assetType, string assetName, Action <float> progress, bool isUsePool)
        {
            AsyncAssetProxy     proxy    = PoolMgr.Instance.GetCsharpObject <AsyncAssetProxy>();
            AssetBundleLoadNode loadNode = AssetBundleMgr.Instance.GetAssetBundleLoadNode(assetType, assetName);

            loadNode.AddLoadProgressCallBack(progress);
            proxy.InitProxy(assetType, assetName, loadNode, isUsePool);
            _asyncProxyQueue.Enqueue(proxy);
            return(proxy);
        }
예제 #3
0
    static int LoadAssetProxy(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("Framework.ResourceMgr.Register");
#endif
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3)
            {
                Framework.ResourceMgr obj  = (Framework.ResourceMgr)ToLua.CheckObject <Framework.ResourceMgr>(L, 1);
                Framework.AssetType   arg0 = (Framework.AssetType)ToLua.CheckObject(L, 2, typeof(Framework.AssetType));
                string arg1 = ToLua.CheckString(L, 3);
                Framework.AsyncAssetProxy o = obj.LoadAssetProxy(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 4)
            {
                Framework.ResourceMgr obj  = (Framework.ResourceMgr)ToLua.CheckObject <Framework.ResourceMgr>(L, 1);
                Framework.AssetType   arg0 = (Framework.AssetType)ToLua.CheckObject(L, 2, typeof(Framework.AssetType));
                string arg1 = ToLua.CheckString(L, 3);
                bool   arg2 = LuaDLL.luaL_checkboolean(L, 4);
                Framework.AsyncAssetProxy o = obj.LoadAssetProxy(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 5)
            {
                Framework.ResourceMgr obj  = (Framework.ResourceMgr)ToLua.CheckObject <Framework.ResourceMgr>(L, 1);
                Framework.AssetType   arg0 = (Framework.AssetType)ToLua.CheckObject(L, 2, typeof(Framework.AssetType));
                string arg1 = ToLua.CheckString(L, 3);
                System.Action <float> arg2 = (System.Action <float>)ToLua.CheckDelegate <System.Action <float> >(L, 4);
                bool arg3 = LuaDLL.luaL_checkboolean(L, 5);
                Framework.AsyncAssetProxy o = obj.LoadAssetProxy(arg0, arg1, arg2, arg3);
                ToLua.PushObject(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: Framework.ResourceMgr.LoadAssetProxy"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
예제 #4
0
 public void Init(Animator animator, string path)
 {
     _animator             = animator;
     _runtimeAnimatorProxy = ResourceMgr.Instance.LoadAssetProxy(AssetType.AnimeCtrl, path);
     _runtimeAnimatorProxy.AddLoadFinishCallBack(() =>
     {
         RuntimeAnimatorController ctrl = _runtimeAnimatorProxy.LoadUnitySharedAsset <RuntimeAnimatorController>();
         if (ctrl)
         {
             _animator.runtimeAnimatorController = ctrl;
             _animatorOverrideController         = ctrl as AnimatorOverrideController;
             _animator.Rebind();
         }
     });
 }
예제 #5
0
        private void LoadObjectFromAssetBundleLoadNode(AsyncAssetProxy proxy)
        {
            Object      target      = null;
            AssetBundle assetBundle = proxy.LoadNode.assetBundle;

            target = PoolMgr.Instance.GetUnityAsset(proxy.assetType, proxy.assetName);
            if (null == target)
            {
                var name = Path.GetFileNameWithoutExtension(proxy.assetName);
                target = assetBundle.LoadAsset(name);
            }
            if (target != null)
            {
                PoolMgr.Instance.ReleaseUnityAsset(proxy.assetType, proxy.assetName, target);
                target = PoolMgr.Instance.GetUnityAsset(proxy.assetType, proxy.assetName);
            }
            proxy.OnFinish(target);
        }
예제 #6
0
        public void Init(AbsEntity entity, string path, bool isAsync = true)
        {
            _entity      = entity;
            _resPath     = path;
            IsLoadFinish = false;
            AsyncAssetProxy proxy = ResourceMgr.Instance.LoadAssetProxy(AssetType.Prefab, _resPath);

            proxy.AddLoadFinishCallBack(() =>
            {
                gameObject      = proxy.LoadUnityObject <GameObject>();
                gameObject.name = entity.UID.ToString();
                IsLoadFinish    = true;
                Trans           = gameObject.transform;
                if (_loadFinishHandler != null)
                {
                    _loadFinishHandler(this);
                }
            });
        }
예제 #7
0
 public void OverrideAnimationClip(string name, string path, bool autoPlay = true)
 {
     _animationClipProxy = ResourceMgr.Instance.LoadAssetProxy(AssetType.AnimeClip, path);
     _animationClipProxy.AddLoadFinishCallBack(() =>
     {
         AnimationClip clip = _animationClipProxy.LoadUnitySharedAsset <AnimationClip>();
         if (_animatorOverrideController && clip)
         {
             _animatorOverrideController[name]   = clip;
             _animator.runtimeAnimatorController = _animatorOverrideController;
             _AnimationInfo.Data[name]           = clip;
             _animator.Rebind();
             if (autoPlay)
             {
                 _animator.Play(name);
             }
         }
     });
 }
예제 #8
0
 private void UpdateLoadAssetAsync()
 {
     if (_asyncProxyQueue.Count > 0 || null != _curProxy)
     {
         _stopwatch.Reset();
         _stopwatch.Start();
         while (true)
         {
             if (_asyncProxyQueue.Count < 1 && null == _curProxy)
             {
                 _stopwatch.Stop();
                 break;
             }
             if (_asyncProxyQueue.Count > 0)
             {
                 if (null == _curProxy)
                 {
                     _curProxy = _asyncProxyQueue.Dequeue();
                 }
             }
             if (_curProxy.LoadNode.NodeState == AssetBundleLoadNode.AssetBundleNodeState.Finish)
             {
                 LoadObjectFromAssetBundleLoadNode(_curProxy);
                 _curProxy = null;
             }
             else
             {
                 _curProxy.LoadNode.Update();//结束了就等下一帧执行回调;
             }
             if (_stopwatch.Elapsed.Milliseconds >= MAX_LOAD_TIME)
             {
                 _stopwatch.Stop();
                 break;
             }
         }
     }
 }
예제 #9
0
        /// <summary>
        /// Asset async load from AssetBundle;
        /// </summary>
        /// <typeparam name="T">ctrl</typeparam>
        /// <param name="assetType">资源类型</param>
        /// <param name="assetName">资源名字</param>
        /// <param name="proxy">代理</param>
        /// <param name="action">资源回调</param>
        /// <param name="progress">progress回调</param>
        /// <returns></returns>
        private IEnumerator <float> LoadAssetAsync_discard <T>(AssetType assetType, string assetName, AsyncAssetProxy proxy
                                                               , Action <T> action, Action <float> progress)
            where T : Object
        {
            T           ctrl        = null;
            AssetBundle assetBundle = null;

            IEnumerator itor = AssetBundleMgr.Instance.LoadAssetBundleAsync(assetType, assetName,
                                                                            ab => { assetBundle = ab; }, progress);//此处加载占90%;

            while (itor.MoveNext())
            {
                yield return(Timing.WaitForOneFrame);
            }
            var name = Path.GetFileNameWithoutExtension(assetName);
            AssetBundleRequest request = assetBundle.LoadAssetAsync <T>(name);

            //此处加载占10%;
            while (request.progress < 0.99)
            {
                if (progress != null)
                {
                    progress(0.9f + 0.1f * request.progress);
                }
                yield return(Timing.WaitForOneFrame);
            }
            while (!request.isDone)
            {
                yield return(Timing.WaitForOneFrame);
            }
            ctrl = request.asset as T;
            if (null == ctrl)
            {
                LogHelper.PrintError(string.Format("[ResourceMgr]LoadAssetAsync Load Asset failure," +
                                                   ",type:{0},name:{1}!", assetType, assetName));
            }
            //--------------------------------------------------------------------------------------
            //先等一帧;
            yield return(Timing.WaitForOneFrame);

            if (!proxy.IsCancel && action != null)
            {
                action(ctrl);
            }
            if (proxy != null)
            {
                proxy.OnFinish(ctrl);
            }
        }