예제 #1
0
        /// <summary>
        /// 检查更新
        /// </summary>
        private void CheckVersionChange()
        {
            GameEntry.Log(LogCategory.Resource, "CheckVersionChange");

            if (LocalAssetsManager.GetVersionFileExists())
            {
                //判断只读区资源版本号和CDN资源版本号是否一致
                if (!string.IsNullOrEmpty(m_LocalAssetsVersion) && m_LocalAssetsVersion.Equals(m_CDNVersion))
                {
                    GameEntry.Log(LogCategory.Resource, "可写区资源版本号和CDN资源版本号一致");
                    //一致 进入预加载流程
                    GameEntry.Procedure.ChangeState(ProcedureState.Preload);
                }
                else
                {
                    GameEntry.Log(LogCategory.Resource, "可写区资源版本号和CDN资源版本号不一致");
                    BeginCheckVersionChange();
                }
            }
            else
            {
                GameEntry.Log(LogCategory.Resource, "下载初始资源");
                //下载初始资源
                DownloadInitResources();
            }
        }
예제 #2
0
        public void OnUpdate()
        {
            if (Time.time > m_ReleaseClassObjectNextRunTime + ReleaseClassObjectInterval)
            {
                m_ReleaseClassObjectNextRunTime = Time.time;
                PoolManager.ReleaseClassObjectPool();
                GameEntry.Log(LogCategory.Normal, "释放类对象池");
            }

            if (Time.time > m_ReleaseAssetBundleNextRunTime + ReleaseAssetBundleInterval)
            {
                m_ReleaseAssetBundleNextRunTime = Time.time;
#if !DISABLE_ASSETBUNDLE
                PoolManager.ReleaseAssetBundlePool();
                GameEntry.Log(LogCategory.Normal, "释放AssetBundle池");
#endif
            }

            if (Time.time > m_ReleaseAssetNextRunTime + ReleaseAssetInterval)
            {
                m_ReleaseAssetNextRunTime = Time.time;
#if !DISABLE_ASSETBUNDLE
                PoolManager.ReleaseAssetPool();
                GameEntry.Log(LogCategory.Normal, "释放Asset池");
#endif
                LuaManager.luaEnv.FullGc();
                Resources.UnloadUnusedAssets();
            }
        }
예제 #3
0
        /// <summary>
        /// 将只读区版本文件初始化到可写区
        /// </summary>
        private void InitVersionFileFormStreamingAssetsToLocal()
        {
            GameEntry.Log(LogCategory.Resource, "InitVersionFileFormStreamingAssetsToLocal");

            m_LocalAssetsVersionDic = new Dictionary <string, AssetBundleInfoEntity>();

            var enumerator = m_StreamingAssetsVersionDic.GetEnumerator();

            while (enumerator.MoveNext())
            {
                AssetBundleInfoEntity entity = enumerator.Current.Value;
                m_LocalAssetsVersionDic[enumerator.Current.Key] = new AssetBundleInfoEntity()
                {
                    AssetBundleName = entity.AssetBundleName,
                    MD5             = entity.MD5,
                    Size            = entity.Size,
                    IsFirstData     = entity.IsFirstData,
                    IsEncrypt       = entity.IsEncrypt
                };
            }

            //保存版本文件
            LocalAssetsManager.SaveVersionFile(m_LocalAssetsVersionDic);

            //保存版本号
            m_LocalAssetsVersion = m_StreamingAssetsVersion;
            LocalAssetsManager.SetResourceVersion(m_LocalAssetsVersion);
        }
예제 #4
0
        /// <summary>
        /// 初始化CDN资源包信息
        /// </summary>
        private void InitCDNAssetBundleInfo()
        {
            string url = string.Format("{0}{1}", GameEntry.Data.SysDataManager.CurrChannelConfig.RealSourceUrl, ConstDefine.VersionFileName);

            GameEntry.Log(LogCategory.Resource, url);
            GameEntry.Http.SendData(url, OnInitCDNAssetBundleInfo, isGetData: true);
        }
예제 #5
0
        /// <summary>
        ///初始化可写区资源包信息
        /// </summary>
        private void InitLocalAssetsBundleInfo()
        {
            GameEntry.Log(LogCategory.Resource, "InitLocalAssetsBundleInfo");

            m_LocalAssetsVersionDic = LocalAssetsManager.GetAssetBundleVersionList(ref m_LocalAssetsVersion);

            //CheckVersionChange();
        }
예제 #6
0
        public override void OnLeave()
        {
            base.OnLeave();
            GameEntry.Log(LogCategory.Procedure, "OnLeave ProcedurePreload");

            GameEntry.Event.CommonEvent.RemoveEventListener(SysEventId.LoadOneDataTableComplete, OnLoadOneDataTableComplete);
            GameEntry.Event.CommonEvent.RemoveEventListener(SysEventId.LoadDataTableComplete, OnLoadDataTableComplete);
            GameEntry.Event.CommonEvent.RemoveEventListener(SysEventId.LoadLuaDataTableComplete, OnLoadLuaDataTableComplete);
        }
예제 #7
0
        public override void OnEnter()
        {
            base.OnEnter();
            GameEntry.Log(LogCategory.Procedure, "OnEnter ProcedureCheckVersion");
#if DISABLE_ASSETBUNDLE
            GameEntry.Procedure.ChangeState(ProcedureState.Preload);
#else
            GameEntry.Resource.InitStreamingAssetsBundleInfo();
#endif
        }
예제 #8
0
        public override void OnEnter()
        {
            base.OnEnter();
            GameEntry.Log(LogCategory.Procedure, "OnEnter ProcedureLogOn");

            GameEntry.Scene.LoadScene(1, onComplete: () =>
            {
                GameEntry.Event.CommonEvent.Dispatch(SysEventId.CloseCheckVersionUI);
            });
        }
예제 #9
0
 /// <summary>
 /// 从CDN加载资源信息
 /// </summary>
 /// <param name="args"></param>
 private void OnLoadAssetInfoFromCDN(HttpCallBackArgs args)
 {
     if (!args.HasError)
     {
         InitAssetInfo(args.Data);
     }
     else
     {
         GameEntry.Log(LogCategory.Resource, args.Value);
     }
 }
예제 #10
0
        /// <summary>
        /// 初始化CDN资源包信息回调
        /// </summary>
        /// <param name="args"></param>
        private void OnInitCDNAssetBundleInfo(HttpCallBackArgs args)
        {
            if (!args.HasError)
            {
                m_CNDVersionDic = GetAssetBundleVersionList(args.Data, ref m_CDNVersion);
                GameEntry.Log(LogCategory.Resource, "OnInitCDNAssetBundleInfo");

                CheckVersionFileExistsInLocal();
            }
            else
            {
                GameEntry.Log(LogCategory.Resource, args.Value);
            }
        }
예제 #11
0
        /// <summary>
        /// 发送web数据
        /// </summary>
        /// <param name="url"></param>
        /// <param name="callBack"></param>
        /// <param name="isPost"></param>
        /// <param name="isGetData">是否获取字节数据</param>
        /// <param name="dic"></param>
        public void SendData(string url, HttpSendDataCallBack callBack, bool isPost = false, bool isGetData = false, Dictionary <string, object> dic = null)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy      = true;
            m_CallBack  = callBack;
            m_IsGetData = isGetData;

            if (!isPost)
            {
                GetUrl(url);
            }
            else
            {
                //web加密
                if (dic != null)
                {
                    //客户端标识符
                    dic["deviceIdentifier"] = DeviceUtil.DeviceIdentifier;

                    //设备型号
                    dic["deviceModel"] = DeviceUtil.DeviceModel;

                    long t = GameEntry.Data.SysDataManager.CurrServerTime;
                    //签名
                    dic["sign"] = EncryptUtil.Md5(string.Format("{0}:{1}", t, DeviceUtil.DeviceIdentifier));

                    //时间戳
                    dic["t"] = t;
                }

                string json = string.Empty;
                if (dic != null)
                {
                    json = JsonMapper.ToJson(dic);
                    if (!m_IsGetData)
                    {
                        GameEntry.Log(LogCategory.Proto, "<color=#ffa200>发送消息:</color><color=#FFFB80>" + url + "</color>");
                        GameEntry.Log(LogCategory.Proto, "<color=#ffdeb3>==>>" + json + "</color>");
                    }
                    GameEntry.Pool.EnqueueClassObject(dic);
                }

                PostUrl(url, json);
            }
        }
예제 #12
0
        private void LoadShader()
        {
#if DISABLE_ASSETBUNDLE
            m_TargetProgress = 100;
            return;
#endif

            GameEntry.Resource.ResourceLoaderManager.LoadAssetBundle(ConstDefine.CusShadersAssetBundlePath, onComplete: (AssetBundle bundle) =>
            {
                bundle.LoadAllAssets();
                Shader.WarmupAllShaders();
                GameEntry.Log(LogCategory.Normal, "加载资源包中的自定义Shader完毕");
                m_TargetProgress = 100;
            });
        }
예제 #13
0
        /// <summary>
        /// 初始化只读区资源包信息
        /// </summary>
        public void InitStreamingAssetsBundleInfo()
        {
            GameEntry.Log(LogCategory.Resource, "InitStreamingAssetsBundleInfo");

            ReadStreamingAssetsBundle(ConstDefine.VersionFileName, (byte[] buffer) =>
            {
                if (buffer == null)
                {
                    InitCDNAssetBundleInfo();
                }
                else
                {
                    m_IsExistsStreamingAssetsBundleInfo = true;
                    m_StreamingAssetsVersionDic         = GetAssetBundleVersionList(buffer, ref m_StreamingAssetsVersion);
                    InitCDNAssetBundleInfo();
                }
            });
        }
예제 #14
0
        private void OnWebAccountInit(HttpCallBackArgs args)
        {
            if (!args.HasError)
            {
                LitJson.JsonData data   = LitJson.JsonMapper.ToObject(args.Value);
                LitJson.JsonData config = LitJson.JsonMapper.ToObject(data["Value"].ToString());

                GameEntry.Data.SysDataManager.CurrChannelConfig.ServerTime    = long.Parse(config["ServerTime"].ToString());
                GameEntry.Data.SysDataManager.CurrChannelConfig.SourceVersion = config["SourceVersion"].ToString();
                GameEntry.Data.SysDataManager.CurrChannelConfig.SourceUrl     = config["SourceUrl"].ToString();
                GameEntry.Data.SysDataManager.CurrChannelConfig.RechargeUrl   = config["RechargeUrl"].ToString();
                GameEntry.Data.SysDataManager.CurrChannelConfig.TDAppId       = config["TDAppId"].ToString();
                GameEntry.Data.SysDataManager.CurrChannelConfig.IsOpenTD      = int.Parse(config["IsOpenTD"].ToString()) == 1;

                GameEntry.Log(LogCategory.Resource, "RealSourceUrl=>" + GameEntry.Data.SysDataManager.CurrChannelConfig.RealSourceUrl);
                GameEntry.Procedure.ChangeState(ProcedureState.CheckVersion);
            }
        }
예제 #15
0
        /// <summary>
        /// 更新
        /// </summary>
        public void OnUpdate()
        {
            if (m_CurrSceneIsLoading)
            {
                var curr = m_SceneLoaderList.First;
                while (curr != null)
                {
                    curr.Value.OnUpdate();
                    curr = curr.Next;
                }

                float currTarget  = GetCurrTotalProgress();
                float finalTarget = 0.9f * m_NeedLoadOrUnloadSceneDetailCount;
                if (currTarget >= finalTarget)
                {
                    currTarget = m_NeedLoadOrUnloadSceneDetailCount;
                }

                if (m_CurrProgress < m_NeedLoadOrUnloadSceneDetailCount && m_CurrProgress <= currTarget)
                {
                    m_CurrProgress = m_CurrProgress + Time.deltaTime * m_NeedLoadOrUnloadSceneDetailCount * 1;
                    m_CurrLoadingParam.IntParam1   = (int)LoadingType.ChangeScene;
                    m_CurrLoadingParam.FloatParam1 = (m_CurrProgress / m_NeedLoadOrUnloadSceneDetailCount);
                    GameEntry.Event.CommonEvent.Dispatch(SysEventId.LoadingProgressChange, m_CurrLoadingParam);
                }
                else if (m_CurrProgress >= m_NeedLoadOrUnloadSceneDetailCount)
                {
                    GameEntry.Log(LogCategory.Normal, "场景加载完毕");
                    m_NeedLoadOrUnloadSceneDetailCount = 0;
                    m_CurrLoadOrUnloadSceneDetailCount = 0;
                    m_CurrSceneIsLoading = false;
                    GameEntry.UI.CloseUIForm(UIFormId.Loading);

                    m_CurrLoadingParam.Reset();
                    GameEntry.Pool.EnqueueClassObject(m_CurrLoadingParam);

                    if (m_OnComplete != null)
                    {
                        m_OnComplete();
                    }
                }
            }
        }
예제 #16
0
        /// <summary>
        /// 请求服务器
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private IEnumerator Request(UnityWebRequest data)
        {
            yield return(data.SendWebRequest());

            IsBusy = false;
            if (data.isNetworkError || data.isHttpError)
            {
                if (m_CallBack != null)
                {
                    m_CallBackArgs.HasError = true;
                    m_CallBackArgs.Value    = data.error;

                    if (!m_IsGetData)
                    {
                        GameEntry.Log(LogCategory.Proto, "<color=#00eaff>接收消息:</color><color=#00ff9c>" + data.url + "</color>");
                        GameEntry.Log(LogCategory.Proto, "<color=#c5e1dc>==>>" + JsonUtility.ToJson(m_CallBackArgs) + "</color>");
                    }
                    m_CallBack(m_CallBackArgs);
                }
            }
            else
            {
                if (m_CallBack != null)
                {
                    m_CallBackArgs.HasError = false;
                    m_CallBackArgs.Value    = data.downloadHandler.text;

                    if (!m_IsGetData)
                    {
                        GameEntry.Log(LogCategory.Proto, "<color=#00eaff>接收消息:</color><color=#00ff9c>" + data.url + "</color>");
                        GameEntry.Log(LogCategory.Proto, "<color=#c5e1dc>==>>" + JsonUtility.ToJson(m_CallBackArgs) + "</color>");
                    }
                    m_CallBackArgs.Data = data.downloadHandler.data;
                    m_CallBack(m_CallBackArgs);
                }
            }
            data.Dispose();
            data = null;

            //Debug.Log("把http访问器回池");
            GameEntry.Pool.EnqueueClassObject(this);
        }
예제 #17
0
        public override void OnEnter()
        {
            base.OnEnter();
            GameEntry.Log(LogCategory.Procedure, "OnEnter ProcedurePreload");

            GameEntry.Event.CommonEvent.AddEventListener(SysEventId.LoadOneDataTableComplete, OnLoadOneDataTableComplete);
            GameEntry.Event.CommonEvent.AddEventListener(SysEventId.LoadDataTableComplete, OnLoadDataTableComplete);
            GameEntry.Event.CommonEvent.AddEventListener(SysEventId.LoadLuaDataTableComplete, OnLoadLuaDataTableComplete);

            GameEntry.Log(LogCategory.Normal, "预加载开始");
            m_PreloadParams = GameEntry.Pool.DequeueClassObject <BaseParams>();
            m_PreloadParams.Reset();
            GameEntry.Event.CommonEvent.Dispatch(SysEventId.PreloadBegin);

            m_TargetProgress = 99;
#if !DISABLE_ASSETBUNDLE
            GameEntry.Resource.InitAssetInfo();
#endif
            GameEntry.DataTable.LoadDataTableAsync();
        }
예제 #18
0
        public override void OnEnter()
        {
            base.OnEnter();
            GameEntry.Log(LogCategory.Procedure, "OnEnter ProcedureLaunch");

            //访问账号服务器
            string url = GameEntry.Http.RealWebAccountUrl + "/api/init";

            Dictionary <string, object> dic = GameEntry.Pool.DequeueClassObject <Dictionary <string, object> >();

            dic.Clear();

            GameEntry.Data.SysDataManager.CurrChannelConfig.ChannelId    = 0;
            GameEntry.Data.SysDataManager.CurrChannelConfig.InnerVersion = 1001;

            dic["ChannelId"]    = GameEntry.Data.SysDataManager.CurrChannelConfig.ChannelId;
            dic["InnerVersion"] = GameEntry.Data.SysDataManager.CurrChannelConfig.InnerVersion;
            OnWebAccountInit();
            //GameEntry.Http.SendData(url, OnWebAccountInit, true, false, dic);

            //GameEntry.Procedure.ChangeState(ProcedureState.Preload);
        }
예제 #19
0
        /// <summary>
        /// 更新资源包请求
        /// </summary>
        private void UpdateAssetBundleCreateRequest()
        {
            if (m_CurrAssetBundleCreateRequest != null)
            {
                if (m_CurrAssetBundleCreateRequest.isDone)
                {
                    AssetBundle assetBundle = m_CurrAssetBundleCreateRequest.assetBundle;
                    if (assetBundle != null)
                    {
                        GameEntry.Log(LogCategory.Resource, "资源包=>{0} 加载完毕", m_CurrAssetBundleInfo.AssetBundleName);
                        Reset(); //一定要早点Reset

                        if (OnLoadAssetBundleComplete != null)
                        {
                            OnLoadAssetBundleComplete(assetBundle);
                        }
                    }
                    else
                    {
                        GameEntry.LogError("资源包=>{0} 加载失败", m_CurrAssetBundleInfo.AssetBundleName);
                        Reset();

                        if (OnLoadAssetBundleComplete != null)
                        {
                            OnLoadAssetBundleComplete(null);
                        }
                    }
                }
                else
                {
                    // 加载进度
                    if (OnAssetBundleCreateUpdate != null)
                    {
                        OnAssetBundleCreateUpdate(m_CurrAssetBundleCreateRequest.progress);
                    }
                }
            }
        }
예제 #20
0
        /// <summary>
        /// 更新加载资源请求
        /// </summary>
        private void UpdateAssetBundleRequest()
        {
            if (m_CurrAssetBundleRequest != null)
            {
                if (m_CurrAssetBundleRequest.isDone)
                {
                    UnityEngine.Object obj = m_CurrAssetBundleRequest.asset;
                    if (obj != null)
                    {
                        GameEntry.Log(LogCategory.Resource, "资源=>{0} 加载完毕", obj.name);
                        Reset(); //一定要早点Reset

                        if (OnLoadAssetComplete != null)
                        {
                            OnLoadAssetComplete(obj);
                        }
                    }
                    else
                    {
                        GameEntry.LogError("资源=>{0} 加载失败", m_CurrAssetName);
                        Reset(); //一定要早点Reset

                        if (OnLoadAssetComplete != null)
                        {
                            OnLoadAssetComplete(obj);
                        }
                    }
                }
                else
                {
                    // 加载进度
                    if (OnAssetUpdate != null)
                    {
                        OnAssetUpdate(m_CurrAssetBundleRequest.progress);
                    }
                }
            }
        }
예제 #21
0
        public override void OnUpdate()
        {
            base.OnUpdate();

            if (m_CurrProgress < m_TargetProgress)
            {
                m_CurrProgress = m_CurrProgress + Time.deltaTime * 200; //根据实际情况调节速度
                m_PreloadParams.FloatParam1 = m_CurrProgress;
                GameEntry.Event.CommonEvent.Dispatch(SysEventId.PreloadUpdate, m_PreloadParams);
            }
            else if (m_CurrProgress >= 100)
            {
                m_CurrProgress = 100;
                m_PreloadParams.FloatParam1 = m_CurrProgress;
                GameEntry.Event.CommonEvent.Dispatch(SysEventId.PreloadUpdate, m_PreloadParams);

                GameEntry.Log(LogCategory.Normal, "预加载完毕");
                GameEntry.Event.CommonEvent.Dispatch(SysEventId.PreloadComplete);
                GameEntry.Pool.EnqueueClassObject(m_PreloadParams);

                GameEntry.Procedure.ChangeState(ProcedureState.LogOn);
            }
        }
예제 #22
0
        /// <summary>
        /// 检查可写区版本文件是否存在
        /// </summary>
        private void CheckVersionFileExistsInLocal()
        {
            GameEntry.Log(LogCategory.Resource, "CheckVersionFileExistsInLocal");

            if (LocalAssetsManager.GetVersionFileExists())
            {
                //可写区版本文件存在
                //加载可写区资源包信息
                InitLocalAssetsBundleInfo();
            }
            else
            {
                //可写区版本文件不存在

                //判断只读区版本文件是否存在
                if (m_IsExistsStreamingAssetsBundleInfo)
                {
                    //只读区版本文件存在
                    //将只读区版本文件初始化到可写区
                    InitVersionFileFormStreamingAssetsToLocal();
                }
            }
            CheckVersionChange();
        }
예제 #23
0
 public override void OnLeave()
 {
     base.OnLeave();
     GameEntry.Log(LogCategory.Procedure, "OnLeave ProcedureCheckVersion");
 }
예제 #24
0
 public override void OnLeave()
 {
     base.OnLeave();
     GameEntry.Log(LogCategory.Procedure, "OnLeave ProcedureLaunch");
 }
예제 #25
0
 /// <summary>
 /// 加载所有表完毕
 /// </summary>
 /// <param name="userData"></param>
 private void OnLoadDataTableComplete(object userData)
 {
     GameEntry.Log(LogCategory.Normal, "加载所有c#表格完毕");
     //执行Lua初始化
     GameEntry.Lua.Init();
 }
예제 #26
0
 private void OnLoadLuaDataTableComplete(object userData)
 {
     GameEntry.Log(LogCategory.Normal, "加载所有lua表格完毕");
     LoadShader();
 }