Example #1
0
/*#if UNITY_ANDROID
 *      private int scaleWidth = 0;
 *      private int scaleHeight = 0;
 *      public void setDesignContentScale()
 *      {
 *          if (scaleWidth == 0 && scaleHeight == 0)
 *          {
 *              int width = Screen.currentResolution.width;
 *              int height = Screen.currentResolution.height;
 *              int designWidth = 1136;
 *              int designHeight = 640;
 *              float s1 = (float)designWidth / (float)designHeight;
 *              float s2 = (float)width / (float)height;
 *              if (s1 < s2)
 *              {
 *                  designWidth = (int)Mathf.FloorToInt(designHeight * s2);
 *              }
 *              else if (s1 > s2)
 *              {
 *                  designHeight = (int)Mathf.FloorToInt(designWidth / s2);
 *              }
 *              float contentScale = (float)designWidth / (float)width;
 *              if (contentScale < 1.0f)
 *              {
 *                  scaleWidth = designWidth;
 *                  scaleHeight = designHeight;
 *              }
 *          }
 *          if (scaleWidth > 0 && scaleHeight > 0)
 *          {
 *              if (scaleWidth % 2 == 0)
 *              {
 *                  scaleWidth += 1;
 *              }
 *              else
 *              {
 *                  scaleWidth -= 1;
 *              }
 *              Screen.SetResolution(scaleWidth, scaleHeight, true);
 *          }
 *      }
 *
 *      void OnApplicationPause(bool paused)
 *      {
 *          if (paused)
 *          {
 *          }
 *          else
 *          {
 *              setDesignContentScale();
 *          }
 *      }
 #endif*/
        private async void Start()
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
            //禁用多点触控
            Input.multiTouchEnabled                    = false;
            Application.targetFrameRate                = TargetFrameRate;
            ETModel.Define.IsABNotFromServer           = isABNotFromServer;
            ETModel.Define.SelfResourceServerIpAndPort = selfResourceServerIpAndPort;
            ETModel.Define.isShowFPS                   = isShowFPS;
            ETModel.Define.versionGameCode             = versionGameCode;
            ETModel.Define.GameShowVersion             = GameShowVersion;
            ETModel.Define.isInnetNet                  = isInnetNet;
            try
            {
                //播放背景音乐
                GameSoundPlayer.Instance.PlayBgMusic("ExampleBgMusic");
                Define.isUseAssetBundle = isUseAssetBundle;
                DontDestroyOnLoad(gameObject);
                Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly);

                Game.Scene.AddComponent <GlobalConfigComponent>();
                Game.Scene.AddComponent <ResourcesComponent>();
                Game.Scene.AddComponent <UIComponent>();
                Game.Scene.AddComponent <BundleDownloaderComponent>();
                Game.EventSystem.Run(EventIdType.LoadingBegin);//打开进度条,最外层的
                var IsGameVersionCodeEqual = await BundleHelper.IsGameVersionCodeEqual();

                if (!IsGameVersionCodeEqual)
                {
                    return;
                }
                // 下载ab包
                await BundleHelper.DownloadBundle();

                //await TestWifiUi();
                Game.Scene.RemoveComponent <BundleDownloaderComponent>();
                //解析abmapping
                ABManager.Init();
                //下载好了,声音ab绑定到固定的地方
                await ResetSoundPlayers();

                await UniTask.DelayFrame(1);

                Game.Hotfix.LoadHotfixAssembly();
                // 加载配置
                await Game.Scene.GetComponent <ResourcesComponent>().LoadBundleAsync("config.unity3d");

                Game.Scene.AddComponent <ConfigComponent>();
                Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d");

                Game.Hotfix.GotoHotfix();
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }