コード例 #1
0
ファイル: BundleHelper.cs プロジェクト: gucongyi/FrameGarden
    public static async Task StartDownLoadResources()
    {
        if (StaticData.isUseAssetBundle)
        {
            BundleDownloaderComponent bundleDownloaderComponent = null;
            try
            {
                bundleDownloaderComponent = MonoBehaviourHelper.CreateTempComponent <BundleDownloaderComponent>();
                var t        = bundleDownloaderComponent.LoadInfo();
                var needDown = await t;
                StaticData.isNotWifiDownload = true;
                if (needDown)
                {
                    GameObject goUpdateProcess = ResourcesHelper.InstantiatePrefabFromResourceSetDefault("UISceneLoading", UIRoot.instance.GetUIRootCanvas().transform);
                    UITipABUpdateProgressComponent uiTipABUpdateProgressComponent = goUpdateProcess.GetComponent <UITipABUpdateProgressComponent>();
                    uiTipABUpdateProgressComponent.DownLoadInfo = bundleDownloaderComponent.DownloadInfo;
                    var x1 = bundleDownloaderComponent.DownloadInfo.TotalSize / 1024;
                    var x  = x1 / 1024f;
                    StaticData.isNotWifiDownloadClick = false;
                    //如果大于1m 不是wifi才弹提示
                    if (x > 1 && Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
                    {
                        GameObject goWifiConfirm = ResourcesHelper.InstantiatePrefabFromResourceSetDefault("UITipABUpdateNotWifi", UIRoot.instance.GetUIRootCanvas().transform);
                        UITipABUpdateNotWifiComponent uiTipABUpdateNotWifiComponent = goWifiConfirm.GetComponent <UITipABUpdateNotWifiComponent>();
                        //取两位小数
                        int j = (int)(x * 100);
                        x = j / 100f;
                        uiTipABUpdateNotWifiComponent.TextShow.text = $"当前不是wifi环境, 更新需要消耗{x}M流量,\n是否更新 ? (点击取消将退出游戏)";
                        await UniTask.WaitUntil(() => StaticData.isNotWifiDownloadClick == true);
                    }


                    if (!StaticData.isNotWifiDownload)
                    {
                        StaticData.QuitApplication();
                        //永远不返回
                        await UniTask.WaitUntil(() => StaticData.isNotWifiDownload == true);
                    }
                    await bundleDownloaderComponent.Down();

                    uiTipABUpdateProgressComponent.DownLoadInfo.IsEnd = true;
                    GameObject.DestroyImmediate(goUpdateProcess);
                }


                await ResourcesComponent.instance.LoadOneBundleAsync("StreamingAssets");

                ResourcesComponent.AssetBundleManifestObject = (AssetBundleManifest)ResourcesComponent.instance.GetAsset("StreamingAssets", "AssetBundleManifest");
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
            finally
            {
                GameObject.Destroy(bundleDownloaderComponent.gameObject);
            }
        }
    }
コード例 #2
0
        public override void Run()
        {
            BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>();

            if (null != bundleDownloaderComponent)
            {
                Game.Scene.GetComponent <UIComponent>().ShowNoAnimation(UIType.UILoading, bundleDownloaderComponent);
            }
        }
コード例 #3
0
    private async void Start()
    {
        //启动UniTask Player Loop 注册事件
        PlayerLoopHelper.Init();
        if (isShowDebugWindow)
        {
            goDebug.SetActive(true);
        }
        else
        {
            goDebug.SetActive(false);
        }

        if (isShowFPS)
        {
            ResourcesHelper.InstantiatePrefabFromResourceSetDefault("UIFrameShow", UIRoot.instance.GetUIRootCanvasTop().transform);
        }

        Screen.sleepTimeout                    = SleepTimeout.NeverSleep;
        Application.runInBackground            = true;
        Application.targetFrameRate            = TargetFrameRate;
        StaticData.IsABNotFromServer           = isABNotFromServer;
        StaticData.isABUsedYunSever            = isABUsedYunSever;
        StaticData.SelfResourceServerIpAndPort = selfResourceServerIpAndPort;
        StaticData.localVersionGameCode        = versionGameCode;
        StaticData.isOpenGuide                 = isOpenGuide;
#if UNITY_EDITOR
        StaticData.linguisticType = LanguageType;
#else
        switch (Application.systemLanguage)
        {
        case SystemLanguage.Chinese:
        case SystemLanguage.ChineseSimplified:
            StaticData.linguisticType = LinguisticType.Simplified;
            break;

        case SystemLanguage.ChineseTraditional:
            StaticData.linguisticType = LinguisticType.Complex;
            break;

        case SystemLanguage.English:
        case SystemLanguage.Unknown:
            StaticData.linguisticType = LinguisticType.English;
            break;

        default:
            StaticData.linguisticType = LinguisticType.English;
            break;
        }
#endif
        StaticData.GameShowVersion = GameShowVersion;
        StaticData.isShowSelfLog   = isShowSelfLog;
        try
        {
            //播放背景音乐
            GameSoundPlayer.Instance.PlayBgMusic(MusicHelper.BgMusicLogin);
            StaticData.isUseAssetBundle = isUseAssetBundle;
            DontDestroyOnLoad(gameObject);
            gameObject.AddComponentIfNull <GlobalConfigComponent>();
            gameObject.AddComponentIfNull <ResourcesComponent>();
            BundleDownloaderComponent bundleDownloaderComponent = gameObject.AddComponentIfNull <BundleDownloaderComponent>();
            var IsGameVersionCodeEqual = await BundleHelper.IsGameVersionCodeEqual();

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

            GameObject.Destroy(bundleDownloaderComponent);
            //初始化ABManager
            ABManager.Init();
            //数据表格解析
            ParseExcelData parseExcelData = new ParseExcelData();
            StaticData.configExcel = parseExcelData.Init();
            //用来拿取服务器
            StaticData.IsiosRelease     = StaticData.configExcel.GetVertical().IsiosRelease;
            StaticData.IsAndoridRelease = StaticData.configExcel.GetVertical().IsAndoridRelease;
            //Test Excel
            int WarehouseTotal = StaticData.configExcel.GetVertical().WarehouseTotal;
            Debug.Log($"WarehouseTotal:{WarehouseTotal}");
            ////下载好了,声音ab绑定到固定的地方
            //await ResetSoundPlayers();
            //GameSoundPlayer.Instance.PlayBgMusic("BGM");
            //GameSoundPlayer.Instance.PlaySoundEffect("PrintPhotos");
            //ResourcesHelper.CreateUI("UIWait");
            await UniTask.DelayFrame(1);

            //添加SceneManager
            GameObject goSceneManager = new GameObject("SceneManager");
            goSceneManager.transform.parent = transform;
            goSceneManager.AddComponent <SceneManagerComponent>();

            // 设置请求短链接参数
            StaticData.IsUsedLocalDataNotServer = IsUsedLocalDataNotServer;

            /*
             * //加载网关
             * TextAsset gatewayInfo = await ABManager.GetAssetAsync<TextAsset>("GateWayInfo");
             * switch (typeGate)
             * {
             *  case TypeGateWay.Stable:
             *      gatewayInfo = await ABManager.GetAssetAsync<TextAsset>("GateWayInfo");
             *      break;
             *  case TypeGateWay.MZQ:
             *      gatewayInfo = await ABManager.GetAssetAsync<TextAsset>("GateWayInfoMZQ");
             *      break;
             *  case TypeGateWay.YQX:
             *      gatewayInfo = await ABManager.GetAssetAsync<TextAsset>("GateWayInfoYQX");
             *      break;
             *  case TypeGateWay.JLF:
             *      gatewayInfo = await ABManager.GetAssetAsync<TextAsset>("GateWayInfoJLF");
             *      break;
             *  case TypeGateWay.Extranet:
             *      gatewayInfo = await ABManager.GetAssetAsync<TextAsset>("GateWayInfoExtranet");
             *      break;
             * }
             *
             * GateWayInfo gateWayInfo=LitJson.JsonMapper.ToObject<GateWayInfo>(gatewayInfo.text);
             * //StaticData.DebugGreen($"gateWayInfo ip:{gateWayInfo.ipGateWay} port:{gateWayInfo.portGateWay} timeout:{gateWayInfo.timeout}");
             * bool isGateWayReturn = false;
             * string urlGateWay = $"{gateWayInfo.ipGateWay}:{gateWayInfo.portGateWay}";
             * if (!StaticData.IsUsedLocalDataNotServer)
             * {
             *  CSLinkInfo csLinkInfo = new CSLinkInfo() { Sole = SystemInfo.deviceUniqueIdentifier };
             *  csLinkInfo.Sole = string.Empty;//授权使用的唯一id
             *  csLinkInfo.Platform = RegisterPlatform.None;//授权平台
             *
             *  //发起链接请求
             *  StartCoroutine(HttpGateWayManager.Post(urlGateWay, csLinkInfo, gateWayInfo.timeout, (ip, port, Uid) =>
             *  {
             *      StaticData.ipWebSocket = ip;
             *      StaticData.portWebSocket = port;
             *      StaticData.Uid = Uid;
             *      StaticData.DebugGreen($"玩家的uid:{Uid}");
             *      isGateWayReturn = true;
             *  }, (WebErrorCode webErrorCode) =>
             *  {
             *      StaticData.DebugGreen($"webErrorCode:{webErrorCode.ToString()}");
             *      isGateWayReturn = false;
             *  }));
             *
             *  await UniTask.WaitUntil(() => isGateWayReturn == true);
             *  //进行长连接 使用WebSocket
             *  WebSocketComponent._instance.Init();
             * }
             *
             * //获取用户信息
             * bool isGetUserInfo = false;
             * CSEmptyAccountInfo csEmptyAccountInfo = new CSEmptyAccountInfo();
             * OtherProtoHelper.GetUserInfo(csEmptyAccountInfo,(userInfo)=> {
             *  StaticData.playerInfoData.userInfo = userInfo;
             *  TimeHelper.LoginServerTime = StaticData.playerInfoData.userInfo.PresentTime;
             *  StaticData.DebugGreen($"ServerTime:{TimeHelper.ServerTime(TimeHelper.LoginServerTime)}");
             *  isGetUserInfo = true;
             * });
             * await UniTask.WaitUntil(() => isGetUserInfo == true);
             * //加载本地存储的私聊信息/文件
             * StaticData.LoadPrivateChatFile();
             */

            //登录界面
            await StaticData.OpenUILogin(typeGate, null);

            //关闭Init背景
            UIRoot.instance.GoBgInit.SetActive(false);
        }
        catch (Exception e)
        {
            Debug.LogError(e);
        }
    }