Exemple #1
0
        /// <summary>
        /// name不带后缀,不带前缀
        /// </summary>
        /// <param name="name">name为2D场景对应的预制件名称</param>
        /// <returns></returns>
        public static GameObject Load(string name, ABType abType)
        {
            if (abType != ABType.Effect && abType != ABType.Window && abType != ABType.OtherPrefab)
            {
                Debug.LogError("ABPrefab do not support load " + abType.ToString());
            }

            GameObject  obj = null;
            AssetBundle ab  = LoadAB(name, abType);

            obj = ab.LoadAsset(name) as GameObject;
            ab.Unload(false);
            obj = GameObject.Instantiate(obj);//由于上面获得的 obj,实质是预制件,故这里需要Instantiate

            PrefabRes res = null;

            if (abType == ABType.Effect)
            {
                res = new EffectRes(name, obj);
            }
            else if (abType == ABType.Window)
            {
                res = new WindowRes(name, obj);
            }
            else if (abType == ABType.OtherPrefab)
            {
                res = new OtherPrefabRes(name, obj);
            }
            else
            {
                Debug.LogError("TODO:");
            }

            EventDispatcher.Instance.DispatchEvent(EventID.OnABResLoaded, res);
            return(obj);
        }
Exemple #2
0
        private void onABResLoaded(string evtId, object[] paras)
        {
            Res res = paras[0] as Res;


            if (res is WindowRes)
            {
                WindowRes wRes = res as WindowRes;
                ResCacheDic[ABType.Window][wRes.resName] = wRes;


                //----->可视化显示
                //var older = windowResList.Find(a => a.resName == wRes.resName);
                //if (older != null)
                //{
                //    older = wRes;
                //}
                //else
                //{
                //    windowResList.Add(wRes);
                //}
                //TODO:用上述方法,不知道是什么原因导致的inspector面板上ResObj没有显示出来

                var older = ABManagerMono.Instance.windowResList.Find(a => a.resName == wRes.resName);
                if (older != null)
                {
                    ABManagerMono.Instance.windowResList.Remove(older);
                }

                ABManagerMono.Instance.windowResList.Add(wRes);

                GameObject obj = wRes.resObj as GameObject;
                fillMatTexHolder(obj);
                this.addDestroyNotice(obj);
            }
            else if (res is EffectRes)
            {
                EffectRes effRes = res as EffectRes;
                ResCacheDic[ABType.Effect][effRes.resName] = effRes;

                //可视化处理
                var older = ABManagerMono.Instance.effectResList.Find(a => a.resName == effRes.resName);
                if (older != null)
                {
                    ABManagerMono.Instance.effectResList.Remove(older);
                }
                ABManagerMono.Instance.effectResList.Add(effRes);



                GameObject obj = effRes.resObj as GameObject;
                fillMatTexHolder(obj);
                this.addDestroyNotice(obj);
            }
            else if (res is OtherPrefabRes)
            {
                OtherPrefabRes opRes = res as OtherPrefabRes;
                ResCacheDic[ABType.OtherPrefab][opRes.resName] = opRes;

                //可视化处理
                var older = ABManagerMono.Instance.opResList.Find(a => a.resName == opRes.resName);
                if (older != null)
                {
                    ABManagerMono.Instance.opResList.Remove(older);
                }
                ABManagerMono.Instance.opResList.Add(opRes);



                GameObject obj = opRes.resObj as GameObject;
                fillMatTexHolder(obj);
                this.addDestroyNotice(obj);
            }
            else if (res is SpriteRes)
            {
                SpriteRes sRes = res as SpriteRes;
                ABManagerMono.Instance.spriteResList.Add(sRes);
                ResCacheDic[ABType.Sprite][sRes.resName] = sRes;
            }
            else if (res is TextureRes)
            {
                TextureRes tRes = res as TextureRes;
                ABManagerMono.Instance.texResList.Add(tRes);
                ResCacheDic[ABType.Texture][tRes.resName] = tRes;
            }
            else if (res is AudioRes)
            {
                AudioRes aRes = res as AudioRes;
                ABManagerMono.Instance.audioResList.Add(aRes);
                ResCacheDic[ABType.Audio][aRes.resName] = aRes;
            }
        }