Beispiel #1
0
        IEnumerator LoadGameBaseModule()
        {
            bool succeed = true;

            if (AssetLoaderManager.Instance().HasSmallUpdate)
            {
                yield return(AssetBundleManager.Instance().LoadAssetBundleFromPkg(mBundleName, null,
                                                                                  () =>
                {
                    succeed = false;
                }));

                if (!succeed)
                {
                    mError = GMError.GME_LoadBaseModuleFailed;
                    LoggerManager.Instance().LogErrorFormat("Load BaseBundle {0} From Pkg Failed ...", mBundleName);
                    yield break;
                }
            }
            else
            {
                yield return(AssetBundleManager.Instance().LoadAssetBundle(mBundleName, null,
                                                                           () =>
                {
                    succeed = false;
                }, true));


                if (!succeed)
                {
                    mError = GMError.GME_LoadBaseModuleFailed;
                    LoggerManager.Instance().LogErrorFormat("Load BaseBundle {0} From StreamingAssets Failed ...", mBundleName);
                    yield break;
                }
            }

            TableManager.Instance().LoadTableFromAssetBundle <ProtoTable.ModuleTable>(AssetBundleManager.Instance().getAssetBundle(mBundleName));
            var moduleTable = TableManager.Instance().GetTable <ProtoTable.ModuleTable>();

            if (null == moduleTable)
            {
                mError = GMError.GME_LoadBaseModuleFailed;
                LoggerManager.Instance().LogErrorFormat("load ModuleTable Failed ...");
                yield break;
            }
            LoggerManager.Instance().LogProcessFormat("Load ModuleTable Succeed !");

            yield return(AssetBundleManager.Instance().LoadAssetBundleFromModule(1, null, () =>
            {
                succeed = false;
            }));

            if (!succeed)
            {
                mError = GMError.GME_LoadBaseModuleFailed;
                LoggerManager.Instance().LogErrorFormat("load baseModule Failed ...");
                yield break;
            }

            TableManager.Instance().LoadTableFromAssetBundle <ProtoTable.ResourceInfoTable>(AssetBundleManager.Instance().getAssetBundle(mBundleName));
            var localResourcesInfoTable = TableManager.Instance().GetTable <ProtoTable.ResourceInfoTable>();

            if (null == localResourcesInfoTable)
            {
                mError = GMError.GME_LoadBaseModuleFailed;
                LoggerManager.Instance().LogErrorFormat("加载游戏资源表失败...");
                yield break;
            }

            TableManager.Instance().LoadTableFromAssetBundle <ProtoTable.FrameTypeTable>(AssetBundleManager.Instance().getAssetBundle(mBundleName));
            var frameTypeTable = TableManager.Instance().GetTable <ProtoTable.FrameTypeTable>();

            if (null == frameTypeTable)
            {
                mError = GMError.GME_LoadBaseModuleFailed;
                LoggerManager.Instance().LogErrorFormat("加载界面表失败...");
                yield break;
            }

            var resourceInfoTable = AssetLoaderManager.Instance().Initialize(new AssetLoaderData
            {
                frameHandle             = this,
                localResourcesInfoTable = localResourcesInfoTable,
            });
        }
Beispiel #2
0
        public void Open(int typeId, int frameId, int moduleId = -1, int layer = 1, GameObject root = null)
        {
            if (this.mState == (int)FrameStatus.FS_OPEN)
            {
                Debug.LogErrorFormat("this frame has opened ...");
                return;
            }

            this.mLayer    = layer;
            this.mTypeId   = typeId;
            this.mFrameId  = frameId;
            this.mModuleId = moduleId;
            this.mState    = (int)FrameStatus.FS_INVALID;

            var path = GetPrefabPath();

            if (!string.IsNullOrEmpty(path))
            {
                gameObject = AssetLoaderManager.Instance().LoadResources <GameObject>(path, AssetType.AT_PREFAB);
                if (null == gameObject && MayLoadFromResourcesFile())
                {
                    var objRef = Resources.Load <GameObject>(path);
                    if (null != objRef)
                    {
                        gameObject = Object.Instantiate(objRef) as GameObject;
                    }
                }
            }
            else
            {
                frameItem = TableManager.Instance().GetTableItem <ProtoTable.FrameTypeTable>(mTypeId);
                if (null == frameItem)
                {
                    Debug.LogErrorFormat("query frameItem failed for id = {0}, class = {1}", mTypeId, GetType().Name);
                    return;
                }

                gameObject = AssetLoaderManager.Instance().LoadResources <GameObject>(frameItem.Prefab, AssetType.AT_PREFAB);
            }

            if (null == gameObject)
            {
                Debug.LogErrorFormat("load frame prefab failed for moduleId = {0} path = {1}", moduleId, path);
                return;
            }

            GameObject parent = root;

            if (parent == null)
            {
                var uiLayer = UIManager.Instance().GetLayer(mLayer);
                if (null != uiLayer)
                {
                    parent = uiLayer.goLayer;
                }
            }

            if (null == parent)
            {
                Debug.LogErrorFormat("parent is null , create frame failed , typeId = {0}", mTypeId);
                return;
            }

            mScriptBinder = gameObject.GetComponent <ComScriptBinder>();
            if (null != mScriptBinder)
            {
                _InitScriptBinder();
            }

            gameObject.transform.SetParent(parent.transform, false);


            this.mState = (int)FrameStatus.FS_OPEN;

            OnOpenFrame();
        }
Beispiel #3
0
        IEnumerator DownLoadBaseModule()
        {
            bool succeed = true;

            var baseBundleUrl = string.Format("{0}{1}/{2}/", mBaseConfigUrl, CommonFunction.getPlatformString(),
                                              AssetLoaderManager.Instance().RemoteVersion);

            yield return(AssetBundleManager.Instance().DownLoadAssetBundles(baseBundleUrl, new List <string>()
            {
                mBundleName
            }, null, () =>
            {
                succeed = false;
            }));

            if (!succeed)
            {
                mError = GMError.GME_DownLoadBaseModuleFailed;
                LoggerManager.Instance().LogErrorFormat("从远程加载[{0}] Bundle 失败 !!!", mBundleName);
                yield break;
            }

            yield return(AssetBundleManager.Instance().LoadAssetBundle(mBundleName, null, () =>
            {
                succeed = false;
            }, false));

            if (!succeed)
            {
                mError = GMError.GME_DownLoadBaseModuleFailed;
                LoggerManager.Instance().LogErrorFormat("从本地加载 刚下载的[{0}] Bundle 失败 !!!", mBundleName);
                yield break;
            }

            var baseBundle = AssetBundleManager.Instance().getAssetBundle(mBundleName);

            if (null == baseBundle)
            {
                mError = GMError.GME_DownLoadBaseModuleFailed;
                LoggerManager.Instance().LogFormat("加载[{0}] Bundle 失败 !!!", mBundleName);
                yield break;
            }

            //加载模块表
            TableManager.Instance().LoadTableFromAssetBundle <ProtoTable.ModuleTable>(baseBundle);
            var moduleTable = TableManager.Instance().GetTable <ModuleTable>();

            if (null == moduleTable)
            {
                mError = GMError.GME_DownLoadBaseModuleFailed;
                LoggerManager.Instance().LogErrorFormat("加载模块表 ModuleTable 失败 !!!");
                yield break;
            }

            //加载
            int baseModuleId = 1;
            var moduleItem   = TableManager.Instance().GetTableItem <ModuleTable>(baseModuleId);

            if (null == moduleTable)
            {
                mError = GMError.GME_DownLoadBaseModuleFailed;
                LoggerManager.Instance().LogErrorFormat("加载模块表项 ModuleTable 失败 ID={0}!!!", baseModuleId);
                yield break;
            }

            List <string> needDownLoadBundles = new List <string>(32);

            AssetLoaderManager.Instance().GetNeedDownLoadModule(moduleItem.RequiredBundles.ToArray(), needDownLoadBundles);
            AssetLoaderManager.Instance().GetNeedDownLoadModule(new string[]
            {
                CommonFunction.getPlatformString()
            }, needDownLoadBundles);

            AssetBundleManager.Instance().UnLoadAssetBundle(mBundleName);

            if (needDownLoadBundles.Count > 0)
            {
                for (int i = 0; i < needDownLoadBundles.Count; ++i)
                {
                    LoggerManager.Instance().LogProcessFormat("Bundle [{0}] 需要下载 ...", needDownLoadBundles[i]);
                }

                var bundleUrl = string.Format("{0}{1}/{2}/", mBaseConfigUrl, CommonFunction.getPlatformString(),
                                              AssetLoaderManager.Instance().RemoteVersion);

                yield return(AssetBundleManager.Instance().DownLoadAssetBundles(bundleUrl, needDownLoadBundles, null, () =>
                {
                    succeed = false;
                    LoggerManager.Instance().LogErrorFormat("DownLoadAssetBundles Failed ...");
                }));

                if (!succeed)
                {
                    mError = GMError.GME_DownLoadBaseModuleFailed;
                    yield break;
                }
                LoggerManager.Instance().LogFormat("DownLoadBaseModule Succeed !");
            }
            else
            {
                LoggerManager.Instance().LogProcessFormat("No Bundle Need Download ...");
            }
        }