Ejemplo n.º 1
0
        public static IRes Create(ResSearchRule resSearchRule, short assetType)
        {
            switch (assetType)
            {
            case ResType.AssetBundle:
                return(AssetBundleRes.Allocate(resSearchRule.AssetName));

            case ResType.ABAsset:
                return(AssetRes.Allocate(resSearchRule.AssetName, resSearchRule.OwnerBundle));

            case ResType.ABScene:
                return(SceneRes.Allocate(resSearchRule.AssetName));

            case ResType.Internal:
                return(ResourcesRes.Allocate(resSearchRule.AssetName,
                                             resSearchRule.AssetName.StartsWith("resources://")
                            ? InternalResNamePrefixType.Url
                            : InternalResNamePrefixType.Folder));

            case ResType.NetImageRes:
                return(NetImageRes.Allocate(resSearchRule.AssetName));

            case ResType.LocalImageRes:
                return(LocalImageRes.Allocate(resSearchRule.AssetName));

            default:
                Log.E("Invalid assetType :" + assetType);
                return(null);
            }
        }
Ejemplo n.º 2
0
        public static AssetBundleRes Allocate(string name)
        {
            AssetBundleRes res = SafeObjectPool <AssetBundleRes> .Instance.Allocate();

            if (res != null)
            {
                res.AssetName = name;
                res.InitAssetBundleName();
            }
            return(res);
        }
Ejemplo n.º 3
0
        public override bool LoadSync()
        {
            if (!CheckLoadAble())
            {
                return(false);
            }

            if (string.IsNullOrEmpty(assetBundleName))
            {
                return(false);
            }

            AssetBundleRes abR = ResMgr.Instance.GetRes <AssetBundleRes>(assetBundleName);

            if (abR == null || abR.assetBundle == null)
            {
                Log.e("Failed to Load Asset, Not Find AssetBundleImage:" + abR);
                return(false);
            }

            resState = eResState.kLoading;

            //TimeDebugger timer = ResMgr.S.timeDebugger;

            //timer.Begin("LoadSync Asset:" + m_Name);

            HoldDependRes();

            UnityEngine.Object obj = abR.assetBundle.LoadAsset(m_Name);
            //timer.End();

            UnHoldDependRes();

            if (obj == null)
            {
                Log.e("Failed Load Asset:" + m_Name);
                OnResLoadFaild();
                return(false);
            }

            m_Asset = obj;

            resState = eResState.kReady;
            //Log.i(string.Format("Load AssetBundle Success.ID:{0}, Name:{1}", m_Asset.GetInstanceID(), m_Name));

            //timer.Dump(-1);
            return(true);
        }
Ejemplo n.º 4
0
        public override IEnumerator StartIEnumeratorTask(Action finishCallback)
        {
            if (refCount <= 0)
            {
                OnResLoadFaild();
                finishCallback();
                yield break;
            }

            AssetBundleRes abR = ResMgr.Instance.GetRes <AssetBundleRes>(assetBundleName);

            if (abR == null || abR.assetBundle == null)
            {
                Log.e("Failed to Load Asset, Not Find AssetBundleImage:" + assetBundleName);
                OnResLoadFaild();
                finishCallback();
                yield break;
            }

            //确保加载过程中依赖资源不被释放:目前只有AssetRes需要处理该情况
            HoldDependRes();

            AssetBundleRequest abQ = abR.assetBundle.LoadAssetAsync(m_Name);

            m_AssetBundleRequest = abQ;

            yield return(abQ);

            m_AssetBundleRequest = null;

            UnHoldDependRes();

            if (!abQ.isDone)
            {
                Log.e("Failed Load Asset:" + m_Name);
                OnResLoadFaild();
                finishCallback();
                yield break;
            }

            m_Asset = abQ.asset;

            resState = eResState.kReady;

            finishCallback();
        }
Ejemplo n.º 5
0
        public void OnSyncLoadFinish(IResLoader loader, AssetBundleRes res)
        {
            //Log.w("OnSyncLoadFinish:AssetBundleRes:" + res.name);
            if (res.assetBundle == null)
            {
                return;
            }

            string[] assetNames = res.assetBundle.GetAllAssetNames();

            if (assetNames == null)
            {
                return;
            }

            for (int i = assetNames.Length - 1; i >= 0; --i)
            {
                loader.Add2Load(PathHelper.FullAssetPath2Name(assetNames[i]), null, false);
            }
        }
Ejemplo n.º 6
0
        public static IRes Create(string name, short assetType)
        {
            switch (assetType)
            {
            case eResType.kAssetBundle:
                return(AssetBundleRes.Allocate(name));

            case eResType.kABAsset:
                return(AssetRes.Allocate(name));

            case eResType.kABScene:
                return(SceneRes.Allocate(name));

            case eResType.kInternal:
                return(InternalRes.Allocate(name));

            case eResType.kNetImageRes:
                return(NetImageRes.Allocate(name));

            default:
                Log.e("Invalid assetType :" + assetType);
                return(null);
            }
        }
Ejemplo n.º 7
0
        public override bool LoadSync()
        {
            if (!CheckLoadAble())
            {
                return(false);
            }

            if (string.IsNullOrEmpty(assetBundleName))
            {
                return(false);
            }

            AssetBundleRes abR = ResMgr.Instance.GetRes <AssetBundleRes>(assetBundleName);

            if (abR == null || abR.assetBundle == null)
            {
                Log.e("Failed to Load Asset, Not Find AssetBundleImage:" + abR);
                return(false);
            }


            resState = eResState.kReady;
            return(true);
        }
Ejemplo n.º 8
0
 public void OnSyncLoadFinish(IResLoader loader, AssetBundleRes res)
 {
 }
Ejemplo n.º 9
0
        public override bool LoadSync()
        {
            if (!CheckLoadAble())
            {
                return(false);
            }

            if (string.IsNullOrEmpty(assetBundleName))
            {
                return(false);
            }

            AssetBundleRes abR = ResMgr.Instance.GetRes <AssetBundleRes>(assetBundleName);

            if (abR == null || abR.assetBundle == null)
            {
                Log.e("Failed to Load Asset, Not Find AssetBundleImage:" + abR);
                return(false);
            }

            resState = eResState.kLoading;

            //TimeDebugger timer = ResMgr.S.timeDebugger;

            //timer.Begin("LoadSync Asset:" + m_Name);


            HoldDependRes();


            UnityEngine.Object obj = null;

                        #if UNITY_EDITOR
            if (ABUtility.SimulateAssetBundleInEditor && !string.Equals(m_Name, "assetbundlemanifest"))
            {
                string[] assetPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(abR.name, m_Name);
                if (assetPaths.Length == 0)
                {
                    Log.e("Failed Load Asset:" + m_Name);
                    OnResLoadFaild();
                    return(false);
                }
                obj = UnityEditor.AssetDatabase.LoadAssetAtPath <UnityEngine.Object> (assetPaths [0]);
            }
            else
                        #endif
            {
                obj = abR.assetBundle.LoadAsset(m_Name);
            }
            //timer.End();

            UnHoldDependRes();

            if (obj == null)
            {
                Log.e("Failed Load Asset:" + m_Name);
                OnResLoadFaild();
                return(false);
            }

            m_Asset = obj;

            resState = eResState.kReady;
            //Log.i(string.Format("Load AssetBundle Success.ID:{0}, Name:{1}", m_Asset.GetInstanceID(), m_Name));

            //timer.Dump(-1);
            return(true);
        }
Ejemplo n.º 10
0
        public override IEnumerator StartIEnumeratorTask(Action finishCallback)
        {
            if (refCount <= 0)
            {
                OnResLoadFaild();
                finishCallback();
                yield break;
            }

            AssetBundleRes abR = ResMgr.Instance.GetRes <AssetBundleRes>(assetBundleName);

            if (abR == null || abR.assetBundle == null)
            {
                Log.e("Failed to Load Asset, Not Find AssetBundleImage:" + assetBundleName);
                OnResLoadFaild();
                finishCallback();
                yield break;
            }

            //确保加载过程中依赖资源不被释放:目前只有AssetRes需要处理该情况
            HoldDependRes();


                        #if UNITY_EDITOR
            if (ABUtility.SimulateAssetBundleInEditor && !string.Equals(m_Name, "assetbundlemanifest"))
            {
                string[] assetPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(abR.name, m_Name);
                if (assetPaths.Length == 0)
                {
                    Log.e("Failed Load Asset:" + m_Name);
                    OnResLoadFaild();
                    finishCallback();
                    yield break;
                }
                m_Asset = UnityEditor.AssetDatabase.LoadAssetAtPath <UnityEngine.Object> (assetPaths [0]);
            }
            else
                        #endif
            {
                AssetBundleRequest abQ = abR.assetBundle.LoadAssetAsync(m_Name);
                m_AssetBundleRequest = abQ;

                yield return(abQ);

                m_AssetBundleRequest = null;

                UnHoldDependRes();

                if (!abQ.isDone)
                {
                    Log.e("Failed Load Asset:" + m_Name);
                    OnResLoadFaild();
                    finishCallback();
                    yield break;
                }

                m_Asset = abQ.asset;
            }

            resState = eResState.kReady;

            finishCallback();
        }
Ejemplo n.º 11
0
 public virtual void OnAsyncLoadFinish(IResLoader loader, AssetBundleRes res)
 {
 }
Ejemplo n.º 12
0
 public IRes Create(ResSearchKeys resSearchKeys)
 {
     return(AssetBundleRes.Allocate(resSearchKeys.AssetName));
 }