コード例 #1
0
        /// <summary>
        /// 同步从AssetBundle加载资源;
        /// </summary>
        /// <param name="path"></param>
        /// <param name="isUsePool"></param>
        /// <returns></returns>
        private AssetBundleAssetProxy LoadAssetSync(string path, bool isUsePool)
        {
            AssetBundleAssetProxy proxy = PoolMgr.Instance.GetCsharpObject <AssetBundleAssetProxy>();

            proxy.Initialize(path, isUsePool);

            Object      asset       = null;
            AssetBundle assetBundle = AssetBundleMgr.Instance.LoadFromFile(path);

            if (assetBundle != null)
            {
                var name = Path.GetFileNameWithoutExtension(path);
                asset = assetBundle.LoadAsset(name);
            }
            if (asset == null)
            {
                AssetBundleMgr.Instance.UnloadAsset(path, null);
                LogHelper.PrintError(string.Format("[ResourceMgr]LoadSyncAssetProxy load asset:{0} failure.", path));
            }
            else
            {
                AssetBundleMgr.Instance.AddAssetRef(path, asset);
            }
            proxy.OnFinish(asset);
            return(proxy);
        }
コード例 #2
0
        /// Asset async load from AssetBundle;
        private IEnumerator <float> LoadFromFileAsync(string path, AssetBundleAssetProxy proxy
                                                      , Action <float> progress)
        {
            AssetBundle assetBundle = null;

            //此处加载占0.8;
            IEnumerator itor = AssetBundleMgr.Instance.LoadFromFileAsync(path,
                                                                         bundle => { assetBundle = bundle; }, progress);

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

            //此处加载占0.2;
            while (request.progress < 0.99f)
            {
                if (progress != null)
                {
                    progress(LOAD_BUNDLE_PRECENT + LOAD_ASSET_PRECENT * request.progress);
                }
                yield return(Timing.WaitForOneFrame);
            }
            while (!request.isDone)
            {
                yield return(Timing.WaitForOneFrame);
            }
            if (null == request.asset)
            {
                AssetBundleMgr.Instance.UnloadAsset(path, null);
                LogHelper.PrintError(string.Format("[ResourceMgr]LoadFromFileAsync load asset:{0} failure.", path));
            }
            else
            {
                AssetBundleMgr.Instance.AddAssetRef(path, request.asset);
            }

            //先等一帧;
            yield return(Timing.WaitForOneFrame);

            if (proxy != null)
            {
                proxy.OnFinish(request.asset);
            }
            else
            {
                LogHelper.PrintError(string.Format("[ResourceMgr]LoadFromFileAsync proxy is null:{0}.", path));
            }
        }
コード例 #3
0
            public IEnumerator <float> LoadAssetAsync(string path, AssetBundleAssetProxy proxy, Action <float> progress)
            {
                UnityObject asset = null;

#if UNITY_EDITOR
                asset = UnityEditor.AssetDatabase.LoadAssetAtPath <UnityObject>(path);
#endif
                //先等一帧;
                yield return(Timing.WaitForOneFrame);

                if (proxy != null)
                {
                    proxy.OnFinish(asset);
                }
                else
                {
                    LogHelper.PrintError($"[ResourceMgr]LoadFromFileAsync proxy is null:{path}.");
                }
            }