Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 异步从AssetBundle加载资源;
        /// </summary>
        /// <param name="path"></param>
        /// <param name="progress"></param>
        /// <param name="isUsePool"></param>
        /// <returns></returns>
        public AssetBundleAssetProxy LoadAssetAsync(string path, Action <float> progress, bool isUsePool)
        {
            AssetBundleAssetProxy proxy = PoolMgr.Instance.GetCsharpObject <AssetBundleAssetProxy>();

            proxy.Initialize(path, isUsePool);
            CoroutineMgr.Instance.RunCoroutine(LoadFromFileAsync(path, proxy, progress));
            return(proxy);
        }
        /// <summary>
        /// 异步从AssetBundle加载资源;
        /// </summary>
        /// <param name="path"></param>
        /// <param name="progress"></param>
        /// <param name="isUsePool"></param>
        /// <returns></returns>
        public AssetBundleAssetProxy LoadAssetAsync(string path, Action <float> progress, bool isUsePool)
        {
            path = $"Assets/Bundles/{path}";

            AssetBundleAssetProxy proxy = PoolMgr.singleton.GetCsharpObject <AssetBundleAssetProxy>();

            proxy.Initialize(path, isUsePool);
            CoroutineMgr.singleton.RunCoroutine(AssetLoader.LoadAssetAsync(path, proxy, progress));
            return(proxy);
        }