コード例 #1
0
        public async ETVoid StartAsync()
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (_IsCountDown)
            {
                await timerComponent.WaitAsync(50);

                if (TargetValue >= 1)
                {
                    _IsCountDown = false;
                    return;
                }


                if (bundleDownloaderComponent == null)
                {
                    continue;
                }

                var temp = (bundleDownloaderComponent.Progress / 100f).ToString("f2");

                TargetValue = float.Parse(temp);

                if (UpNumText != null)
                {
                    updateSlider.value = TargetValue;
                    UpNumText.text     = $"正在下载({bundleDownloaderComponent.alreadyDownloadBytes.ConvertToHumanReadSize()}/{bundleDownloaderComponent.TotalSize.ConvertToHumanReadSize()}){bundleDownloaderComponent.Progress}%";
                }
            }
        }
コード例 #2
0
ファイル: MoveComponent.cs プロジェクト: yangtzehina/ET
        // 开启协程移动,每100毫秒移动一次,并且协程取消的时候会计算玩家真实移动
        // 比方说玩家移动了2500毫秒,玩家有新的目标,这时旧的移动协程结束,将计算250毫秒移动的位置,而不是300毫秒移动的位置
        public async Task StartMove(CancellationToken cancellationToken)
        {
            Unit unit = this.GetParent <Unit>();

            this.StartPos      = unit.Position;
            this.StartTime     = TimeHelper.Now();
            this.DirNormalized = (this.Target - unit.Position).normalized;

            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            // 协程如果取消,将算出玩家的真实位置,赋值给玩家
            cancellationToken.Register(() =>
            {
                // 算出当前玩家的位置
                long timeNow  = TimeHelper.Now();
                unit.Position = StartPos + this.DirNormalized * this.Speed * (timeNow - this.StartTime) / 1000f;
            });

            while (true)
            {
                Vector3 willPos = unit.Position + this.DirNormalized * this.Speed * 0.05f;
                if ((willPos - this.StartPos).magnitude > (this.Target - this.StartPos).magnitude - 0.1f)
                {
                    unit.Position = this.Target;
                    break;
                }

                await timerComponent.WaitAsync(50, cancellationToken);

                long timeNow = TimeHelper.Now();
                lastFrameTime = timeNow;
                unit.Position = StartPos + this.DirNormalized * this.Speed * (timeNow - this.StartTime) / 1000f;
            }
        }
コード例 #3
0
ファイル: PingComponent.cs プロジェクト: 510264505/ETCow
        public async void Awake()
        {
            TimerComponent timer = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                try
                {
                    Log.Debug($"在线人数:{_session.Count}");
                    await timer.WaitAsync(interval);

                    //检查所有session吗,如果有时间超过指定的间隔就执行action
                    for (int i = 0; i < _session.Count; i++)
                    {
                        if (TimeHelper.ClientNowSeconds() - _session.ElementAt(i).Value > interval)
                        {
                            long key = _session.ElementAt(i).Key;
                            action?.Invoke(key);
                            _session.Remove(key);
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                }
            }
        }
コード例 #4
0
        public async void UpdateAsync()
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                // 如果队列中消息多于4个,则加速跑帧
                this.waitTime = maxWaitTime;
                if (this.Queue.Count > 4)
                {
                    this.waitTime = maxWaitTime - (this.Queue.Count - 4) * 2;
                }
                // 最快加速一倍
                if (this.waitTime < 20)
                {
                    this.waitTime = 20;
                }

                await timerComponent.WaitAsync(waitTime);

                if (this.IsDisposed)
                {
                    return;
                }

                this.UpdateFrame();
            }
        }
コード例 #5
0
        public async void Refresh()
        {
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                TimerComponent iOSTimerComponent = Game.Scene.GetComponent <TimerComponent>();
                while (true)
                {
                    if (UnityEngine.Application.internetReachability != NetworkReachability.NotReachable)
                    {
                        break;
                    }
                    else
                    {
                        await iOSTimerComponent.WaitAsync(200);
                    }
                }
            }

            string switchUrl = GlobalConfigComponent.Instance.GlobalProto.NetLineSwitchUrl;

            if (!string.IsNullOrEmpty(switchUrl))
            {
                HTTPRequest httpRequest = new HTTPRequest(new Uri(switchUrl), HTTPMethods.Post, ResponseDelegate);
                httpRequest.UseAlternateSSL = true;
                httpRequest.AddHeader("Content-Type", "application/json");
                httpRequest.Send();
            }
        }
コード例 #6
0
        private async void Update()
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (!this.IsDisposed)
            {
                for (int i = this.ServerStates.Count - 1; i >= 0; i--)
                {
                    if (this.ServerStates[i].Frame <= this.ServerFrame)
                    {
                        UnitState stateA = this.ServerStates[i];
                        if (i == this.ServerStates.Count - 1)
                        {
                            this.State = stateA;
                        }
                        else
                        {
                            UnitState stateB = this.ServerStates[i + 1];
                            float     lerp   = (float)(this.ServerFrame - stateA.Frame) / (stateB.Frame - stateA.Frame);
                            this.State = stateA.Lerp(stateB, lerp, this.ServerFrame);
                        }
                        break;
                    }
                }

                AdjustUpdateSpeed();
                this.frame += updateSpeed;
                await timerComponent.WaitAsync(UpdateDelay);
            }
        }
コード例 #7
0
        //显示假进度条
        public async void ShowFakeProgress(string hitncontent)
        {
            ShowProgressbar();
            _FakeProg         = 0;
            _FakeProgressHint = hitncontent;

            if (IsShowFakeProgreeIn)
            {
                return;
            }
            IsShowFakeProgreeIn = true;
            //假进度条
            while (true)
            {
                if (_FakeProg <= 0.98f)
                {
                    _FakeProg += 0.01f;
                }
                await timerComponent.WaitAsync(100);

                if (IsDisposed)
                {
                    break;
                }
                _ProgressbarImage.fillAmount = _FakeProg;
                _ScheduleText.text           = $"{_FakeProgressHint}...   {(int)(_FakeProg * 100)}%";
            }
            IsShowFakeProgreeIn = false;
        }
コード例 #8
0
        private async void StartLoading()
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();
            long           instanceId     = this.InstanceId;

            while (true)
            {
                await timerComponent.WaitAsync(1000);

                if (this.InstanceId != instanceId)
                {
                    //Remove
                    break;
                }

                if (null == mBundleDownloaderComponent && null == mInstallPacketDownloaderComponent)
                {
                    //Hide
                    break;
                }


                if (null != mBundleDownloaderComponent)
                {
                    textContent.text = $"{mBundleDownloaderComponent.Progress}%";
                }
                if (null != mInstallPacketDownloaderComponent)
                {
                    textContent.text = $"{mInstallPacketDownloaderComponent.Progress}%";
                }
            }

            mBundleDownloaderComponent        = null;
            mInstallPacketDownloaderComponent = null;
        }
コード例 #9
0
        public async ETVoid Waiting()
        {
            TimerComponent timer = Game.Scene.GetComponent <TimerComponent>();

            room.waitCts = new CancellationTokenSource();

            await timer.WaitAsync(waitTime, room.waitCts.Token);

            Log.Info($"{room.GetType().ToString()}-执行完waiting");
            room.waitCts.Dispose();
            room.waitCts = null;
        }
コード例 #10
0
        private async void Simulate()
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (!this.IsDisposed)
            {
                OnSimulateBefore();
                OnSimulateInput();
                OnSimulateAfter();
                OnSimulateInertance();
                await timerComponent.WaitAsync(UnitStateComponent.UpdateDelay);
            }
        }
コード例 #11
0
        // 开启协程移动,每100毫秒移动一次,并且协程取消的时候会计算玩家真实移动
        // 比方说玩家移动了2500毫秒,玩家有新的目标,这时旧的移动协程结束,将计算250毫秒移动的位置,而不是300毫秒移动的位置
        public async ETTask StartMove(ETCancellationToken cancellationToken)
        {
            Log.Debug("StartMove");
            var transform = Parent.GetComponent <TransformComponent>();

            this.StartPos  = transform.position;
            this.StartTime = TimeHelper.Now();
            float distance = (this.Target - this.StartPos).magnitude;

            if (Math.Abs(distance) < 0.1f)
            {
                return;
            }

            this.needTime = (long)(distance / this.Speed * 1000);

            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            // 协程如果取消,将算出玩家的真实位置,赋值给玩家
            cancellationToken.Register(() =>
            {
                long timeNow = TimeHelper.Now();
                if (timeNow - this.StartTime >= this.needTime)
                {
                    transform.position = this.Target;
                }
                else
                {
                    float amount       = (timeNow - this.StartTime) * 1f / this.needTime;
                    transform.position = Vector3.Lerp(this.StartPos, this.Target, amount);
                }
            });

            while (true)
            {
                await timerComponent.WaitAsync(50, cancellationToken);

                long timeNow = TimeHelper.Now();

                if (timeNow - this.StartTime >= this.needTime)
                {
                    transform.position = this.Target;
                    break;
                }

                float amount = (timeNow - this.StartTime) * 1f / this.needTime;
                transform.position = Vector3.Lerp(this.StartPos, this.Target, amount);
                //Log.Debug($"{Parent.Id} position={transform.position}");
            }
        }
コード例 #12
0
        // 开启协程移动,每100毫秒移动一次,并且协程取消的时候会计算玩家真实移动
        // 比方说玩家移动了2500毫秒,玩家有新的目标,这时旧的移动协程结束,将计算250毫秒移动的位置,而不是300毫秒移动的位置
        public async ETTask StartMove(CancellationToken cancellationToken)
        {
            Gamer gamer = this.GetParent <Gamer>();

            this.StartPos  = gamer.Position;
            this.StartTime = TimeHelper.Now();
            float distance = (this.Target - this.StartPos).magnitude; //单次计算都是走的直线

            if (Math.Abs(distance) < 0.1f)                            //返回绝对值
            {
                return;
            }

            this.needTime = (long)(distance / this.Speed * 1000); //双目运算 从左到右

            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            // 协程如果取消,将算出玩家的真实位置,赋值给玩家
            cancellationToken.Register(() =>
            {
                long timeNow = TimeHelper.Now();
                if (timeNow - this.StartTime >= this.needTime)
                {
                    gamer.Position = this.Target;
                }
                else
                {
                    float amount   = (timeNow - this.StartTime) * 1f / this.needTime;
                    gamer.Position = Vector3.Lerp(this.StartPos, this.Target, amount);
                }
            });

            while (true)
            {
                //每50毫秒保存一次玩家位置 直到触发取消 取消时再保存一次
                await timerComponent.WaitAsync(50, cancellationToken);

                long timeNow = TimeHelper.Now();

                if (timeNow - this.StartTime >= this.needTime)
                {
                    gamer.Position = this.Target;
                    break;
                }

                float amount = (timeNow - this.StartTime) * 1f / this.needTime;
                gamer.Position = Vector3.Lerp(this.StartPos, this.Target, amount);
            }
        }
コード例 #13
0
        private async ETVoid UpdateAsync()
        {
            Log.Info($"===>frame{count}");

            //调用UpdateAsync时修改interval状态,计数+1
            interval = true;
            count++;

            //可每秒执行一次
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();
            await timerComponent.WaitAsync(waitTime);

            //间隔后修改interval状态
            interval = false;
        }
コード例 #14
0
        // 开启协程移动,每100毫秒移动一次,并且协程取消的时候会计算玩家真实移动
        // 比方说玩家移动了250毫秒,玩家有新的目标,这时旧的移动协程结束,将计算250毫秒移动的位置,而不是300毫秒移动的位置
        public async ETTask StartMove(CancellationToken cancellationToken)
        {
            Unit unit = this.GetParent <Unit>();

            this.StartPos  = unit.Position;
            this.StartTime = TimeHelper.Now();
            float distance = (this.Target - this.StartPos).magnitude;

            if (Math.Abs(distance) < 0.1f)
            {
                return;
            }

            this.needTime = (long)(distance / this.Speed * 1000);

            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            // 协程如果取消,将算出玩家的真实位置,赋值给玩家
            cancellationToken.Register(() =>
            {
                long timeNow = TimeHelper.Now();
                if (timeNow - this.StartTime >= this.needTime)
                {
                    unit.Position = this.Target;
                }
                else
                {
                    float amount  = (timeNow - this.StartTime) * 1f / this.needTime;
                    unit.Position = Vector3.Lerp(this.StartPos, this.Target, amount);
                }
            });

            while (true)
            {
                await timerComponent.WaitAsync(10, cancellationToken);

                long timeNow = TimeHelper.Now();

                if (timeNow - this.StartTime >= this.needTime)
                {
                    unit.Position = this.Target;
                    break;
                }

                float amount = (timeNow - this.StartTime) * 1f / this.needTime;
                unit.Position = Vector3.Lerp(this.StartPos, this.Target, amount);
            }
        }
コード例 #15
0
        public async void UpdateAsync()
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                await timerComponent.WaitAsync(waitTime);

                if (this.IsDisposed)
                {
                    return;
                }

                this.UpdateFrame();
            }
        }
コード例 #16
0
        /// <summary>
        /// 开启下载界面
        /// </summary>
        /// <returns></returns>
        public async ETTask StartAsync()
        {
            this.LoadSlider.SetActive(true);

            this.UpdateFlag.gameObject.SetActive(false);

            this.sliderFg.fillAmount = 0;

            this.sliderValue.text = "0%";

            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                await timerComponent.WaitAsync(50);

                //Debug.Log("this.Progress:" + this.Progress);

                //根据Progress 进行相关表现
                var temp = (this.Progress / 100f).ToString("f2");

                float value = float.Parse(temp);

                this.sliderValue.text = this.Progress + "%";

                this.sliderFg.fillAmount = value;

                if (this.Progress >= 100)
                {
                    sliderValue.text = "100%";

                    sliderFg.fillAmount = 1;

                    await Task.Delay(500);

                    this.LoadSlider.SetActive(false);

                    break;

                    //结束回调方法
                }
            }
        }
コード例 #17
0
ファイル: LocalTankComponent.cs プロジェクト: spadd/ET_Tank
        private async ETVoid HeartBeat30ms()
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                await timerComponent.WaitAsync(30, CancellationTokenSource.Token);

                if (m_tank.Died)
                {
                    continue;
                }


                C2B_TankFrameInfo tankInfo = new C2B_TankFrameInfo();

                tankInfo.TankFrameInfo = new TankFrameInfo();


                tankInfo.TankFrameInfo.TankId = m_tank.Id;

                int m_coefficient = Tank.m_coefficient;

                tankInfo.TankFrameInfo.PX = Convert.ToInt32(m_tank.Position.x * m_coefficient);
                tankInfo.TankFrameInfo.PY = Convert.ToInt32(this.m_tank.Position.y * m_coefficient);
                tankInfo.TankFrameInfo.PZ = Convert.ToInt32(m_tank.Position.z * m_coefficient);

                tankInfo.TankFrameInfo.RX = Convert.ToInt32(m_tank.GameObject.transform.eulerAngles.x * m_coefficient);
                tankInfo.TankFrameInfo.RY = Convert.ToInt32(m_tank.GameObject.transform.eulerAngles.y * m_coefficient);
                tankInfo.TankFrameInfo.RZ = Convert.ToInt32(m_tank.GameObject.transform.eulerAngles.z * m_coefficient);

                TurretComponent turretComponent = m_tank.GetComponent <TurretComponent>();


                tankInfo.TankFrameInfo.TurretRY = Convert.ToInt32(turretComponent.RotTarget * m_coefficient);
                tankInfo.TankFrameInfo.GunRX    = Convert.ToInt32(turretComponent.RollTarget * m_coefficient);

                //Log.Warning("发送成功");

                SessionComponent.Instance.Session.Send(tankInfo);
            }
        }
コード例 #18
0
        /// <summary>
        /// 下载超时检测
        /// </summary>
        /// <returns></returns>
        public async ETTask CheckDownLoadTimeOut()
        {
            if (this.tokenSource != null)
            {
                this.tokenSource.Cancel();
            }

            this.tokenSource = new CancellationTokenSource();

            this.cancelToken = this.tokenSource.Token;

            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                await timerComponent.WaitAsync(this.downLoadTimeOut * 1000, this.cancelToken);

                if (this.Progress < 100)
                {
                    if (this.webRequest != null)
                    {
                        this.webRequest.isCancel = true;

                        this.webRequest = null;
                    }

                    if (this.LoadSlider != null)
                    {
                        this.LoadSlider.SetActive(false);
                    }

                    if (this.UpdateFlag != null)
                    {
                        this.UpdateFlag.gameObject.SetActive(true);
                    }

                    Game.EventSystem.Run("SubGameDownLoadFail", this.downloadingBundle);

                    break;
                }
            }
        }
        private async ETVoid StartAsync(FUICheckForResUpdateComponent self)
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();
            long           instanceId     = self.InstanceId;

            while (true)
            {
                await timerComponent.WaitAsync(1);

                if (self.InstanceId != instanceId)
                {
                    return;
                }

                BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>();
                if (bundleDownloaderComponent == null)
                {
                    continue;
                }

                if (bundleDownloaderComponent.Updater.Step == Step.Versions)
                {
                    self.FUICheackForResUpdate.updateInfo.text = "正在为您检查资源更新...";
                }

                if (bundleDownloaderComponent.Updater.Step == Step.Prepared)
                {
                    self.FUICheackForResUpdate.updateInfo.text = "检查更新完毕";
                }

                if (bundleDownloaderComponent.Updater.Step == Step.Download)
                {
                    self.FUICheackForResUpdate.updateInfo.text = "正在为您更新资源:" + $"{bundleDownloaderComponent.Updater.UpdateProgress}%";
                    if (bundleDownloaderComponent.Updater.UpdateProgress >= 100)
                    {
                        self.FUICheackForResUpdate.updateInfo.text = "资源更新完成,祝您游戏愉快。";
                    }
                }
                self.FUICheackForResUpdate.processbar.TweenValue(bundleDownloaderComponent.Updater.UpdateProgress, 0.1f);
            }
        }
コード例 #20
0
ファイル: UILoadingComponent.cs プロジェクト: zijuan0810/ET
        public override async void Start(UILoadingComponent self)
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                await timerComponent.WaitAsync(1000);

                if (self.IsDisposed)
                {
                    return;
                }

                BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>();
                if (bundleDownloaderComponent == null)
                {
                    continue;
                }
                self.text.text = $"{bundleDownloaderComponent.Progress}%";
            }
        }
コード例 #21
0
        public async ETVoid StartAsync(UILoadingComponent self)
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();
            long           instanceId     = self.InstanceId;

            while (true)
            {
                await timerComponent.WaitAsync(1000);

                if (self.InstanceId != instanceId)
                {
                    return;
                }

                BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>();
                if (bundleDownloaderComponent == null)
                {
                    continue;
                }
                self.text.text = $"{bundleDownloaderComponent.Progress}%";
            }
        }
コード例 #22
0
        public async void UpdateAsync()
        {
            try
            {
                TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();
                while (true)
                {
                    await timerComponent.WaitAsync(waitTime);

                    if (this.IsDisposed)
                    {
                        return;
                    }

                    this.UpdateFrame();
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #23
0
        /// <summary>
        /// 检测玩家是否在线
        /// </summary>
        public async ETVoid playerOnlineTest(long time)
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                await timerComponent.WaitAsync(time);

                foreach (Player player in AccountToPlayer.Values)
                {
                    try
                    {
                        player.session.Send(new G2C_PlayerPlaying());
                    }
                    catch (Exception e)
                    {
                        //给其它玩家广播这个玩家掉线的信息
                        removeOnePlayerLink(player.Account).Coroutine();
                        Log.Error("一名玩家无应答离线了: " + player.Account);
                    }
                }
            }
        }
コード例 #24
0
        public override async void Start(UILoadingComponent self)
        {
            Log.Debug("UiLoadingComponentStartSystem : Start");
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();
            long           instanceId     = self.InstanceId;

            while (true)
            {
                await timerComponent.WaitAsync(1000);

                if (self.InstanceId != instanceId)
                {
                    return;
                }

                BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>();
                if (bundleDownloaderComponent == null)
                {
                    continue;
                }
                self.text.text = $"{bundleDownloaderComponent.Progress}%";
            }
        }
コード例 #25
0
        private async ETVoid StartAsync()
        {
            try
            {
                Application.runInBackground = true;
#if UNITY_IOS || UNITY_ANDROID
                // Application.runInBackground = true;
                // Application.targetFrameRate = 60;
                Screen.sleepTimeout = SleepTimeout.NeverSleep;
#endif

#if LOG_ZSX
                var nodes = GameObject.Find("LoginCanvas");
                if (nodes != null)
                {
                    var node = nodes.GetComponentsInChildren <RectTransform>();
                    for (int i = 0; i < node.Length; i++)
                    {
                        node[i].gameObject.SetActive(false);
                    }
                    nodes.SetActive(true);
                }
#endif

                SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance);

                DontDestroyOnLoad(gameObject);
                Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly);

                Game.Scene.AddComponent <TimerComponent>();
                Game.Scene.AddComponent <GlobalConfigComponent>();
                Game.Scene.AddComponent <NetOuterComponent>();
                Game.Scene.AddComponent <ResourcesComponent>();
                Game.Scene.AddComponent <LocalResourcesComponent>();
                // Game.Scene.AddComponent<PlayerComponent>();
                // Game.Scene.AddComponent<UnitComponent>();

                Game.Scene.AddComponent <NetHttpComponent>();

                Game.Scene.AddComponent <UIComponent>();
                Game.Scene.AddComponent <NetLineSwitchComponent>();

#if UNITY_IOS
                TimerComponent iOSTimerComponent = Game.Scene.GetComponent <TimerComponent>();
                while (true)
                {
                    await iOSTimerComponent.WaitAsync(200);

                    if (UnityEngine.Application.internetReachability != NetworkReachability.NotReachable)
                    {
                        break;
                    }
                }
#endif

                // 安装包更新
                await InstallPacketHelper.CheckInstallPacket();

                if (InstallPacketHelper.NeedInstallPacket())
                {
                    InstallPacketDownloaderComponent mInstallPacketDownloaderComponent = Game.Scene.GetComponent <InstallPacketDownloaderComponent>();

                    if (null != mInstallPacketDownloaderComponent)
                    {
                        bool mWaitting = true;

                        string[] mArr         = mInstallPacketDownloaderComponent.remoteInstallPacketConfig.Msg.Split(new string[] { "@%" }, StringSplitOptions.None);
                        int      mTmpLanguage = PlayerPrefsMgr.mInstance.GetInt(PlayerPrefsKeys.KEY_LANGUAGE, 2);
                        if (mTmpLanguage < 0)
                        {
                            mTmpLanguage = 0;
                        }
                        int mGroup = mArr.Length / 3;
                        if (mTmpLanguage < mGroup)
                        {
                            UIComponent.Instance.ShowNoAnimation(UIType.UIDialog,
                                                                 new UIDialogComponent.DialogData()
                            {
                                type          = UIDialogComponent.DialogData.DialogType.Commit,
                                title         = mArr[mTmpLanguage],
                                content       = mArr[mTmpLanguage + mGroup],
                                contentCommit = mArr[mTmpLanguage + 2 * mGroup],
                                contentCancel = string.Empty,
                                actionCommit  = () => { mWaitting = false; },
                                actionCancel  = null
                            });

                            TimerComponent mUpdateTimerComponent = Game.Scene.GetComponent <TimerComponent>();
                            while (mWaitting)
                            {
                                await mUpdateTimerComponent.WaitAsync(200);
                            }
                            UIComponent.Instance.Remove(UIType.UIDialog);
                        }
                    }

#if UNITY_ANDROID
                    switch (UnityEngine.Application.internetReachability)
                    {
                    case NetworkReachability.ReachableViaCarrierDataNetwork:
                        // "当前为运行商网络(2g、3g、4g)"
                        string mTmpMsg      = string.Empty;
                        int    mTmpLanguage = PlayerPrefsMgr.mInstance.GetInt(PlayerPrefsKeys.KEY_LANGUAGE, 2);
                        switch (mTmpLanguage)
                        {
                        case 0:
                            mTmpMsg = $"当前使用移动数据,需要消耗{mInstallPacketDownloaderComponent.remoteInstallPacketConfig.ApkSize / (1024 * 1024)}M流量,是否继续下载?";
                            break;

                        case 1:
                            mTmpMsg = $"The current use of mobile data, need to consume {mInstallPacketDownloaderComponent.remoteInstallPacketConfig.ApkSize / (1024 * 1024)} M, whether to download?";
                            break;

                        case 2:
                            mTmpMsg = $"當前使用移動數據,需要消耗{mInstallPacketDownloaderComponent.remoteInstallPacketConfig.ApkSize / (1024 * 1024)}M流量,是否繼續下載?";
                            break;
                        }
                        Game.Scene.GetComponent <UIComponent>().Show(UIType.UICarrierDataNetwork, new UICarrierDataNetworkComponent.UICarrierDataNetworkData()
                        {
                            Msg      = mTmpMsg,
                            Callback = async() =>
                            {
                                await InstallPacketHelper.DownloadInstallPacket();
                                // Log.Debug($"下载完啦!");
                                // todo 调起安装
                                NativeManager.OpenApk(InstallPacketHelper.InstallPacketPath());
                            }
                        }, null, 0);
                        break;

                    case NetworkReachability.ReachableViaLocalAreaNetwork:
                        // wifi网络
                        await InstallPacketHelper.DownloadInstallPacket();

                        // todo 调起安装
                        NativeManager.OpenApk(InstallPacketHelper.InstallPacketPath());
                        return;
                    }
#elif UNITY_IOS
                    UnityEngine.Application.OpenURL(mInstallPacketDownloaderComponent.remoteInstallPacketConfig.IOSUrl);
                    Application.Quit();
#endif
                    return;
                }



                // 下载ab包
                await BundleHelper.CheckDownloadBundle();

                BundleHelper.IsDownloadBundleFinish = false;
                if (BundleHelper.NeedDownloadBundle())
                {
#if UNITY_IOS
                    bool AppStorePack = false;
#if APPStore
                    AppStorePack = true;
#endif
                    InstallPacketDownloaderComponent mInstallPacketDownloaderComponent = Game.Scene.GetComponent <InstallPacketDownloaderComponent>();
                    if (!mInstallPacketDownloaderComponent.remoteInstallPacketConfig.CheckRes && AppStorePack)
                    {
                        BundleHelper.DownloadBundleFinish();
                    }
                    else
#endif
                    {
                        BundleDownloaderComponent mBundleDownloaderComponent = Game.Scene.GetComponent <BundleDownloaderComponent>();
                        switch (UnityEngine.Application.internetReachability)
                        {
                        case NetworkReachability.ReachableViaCarrierDataNetwork:
                            // "当前为运行商网络(2g、3g、4g)"
                            string mTmpMsg      = string.Empty;
                            int    mTmpLanguage = PlayerPrefsMgr.mInstance.GetInt(PlayerPrefsKeys.KEY_LANGUAGE, 2);
                            switch (mTmpLanguage)
                            {
                            case 0:
                                mTmpMsg = $"当前使用移动数据,需要消耗{mBundleDownloaderComponent.TotalSize / (1024 * 1024)}M流量,是否继续下载?";
                                break;

                            case 1:
                                mTmpMsg = $"The current use of mobile data, need to consume {mBundleDownloaderComponent.TotalSize / (1024 * 1024)} M, whether to download?";
                                break;

                            case 2:
                                mTmpMsg = $"當前使用移動數據,需要消耗{mBundleDownloaderComponent.TotalSize / (1024 * 1024)}M流量,是否繼續下載?";
                                break;
                            }
                            Game.Scene.GetComponent <UIComponent>().ShowNoAnimation(UIType.UICarrierDataNetwork, new UICarrierDataNetworkComponent.UICarrierDataNetworkData()
                            {
                                Msg      = mTmpMsg,
                                Callback = async() =>
                                {
                                    await BundleHelper.DownloadBundle();
                                    BundleHelper.IsDownloadBundleFinish = true;
                                },
                            });
                            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();
                            while (true)
                            {
                                await timerComponent.WaitAsync(1000);

                                if (BundleHelper.IsDownloadBundleFinish)
                                {
                                    break;
                                }
                            }
                            Game.Scene.GetComponent <UIComponent>().Remove(UIType.UICarrierDataNetwork);
                            break;

                        case NetworkReachability.ReachableViaLocalAreaNetwork:
                            // wifi网络
                            await BundleHelper.DownloadBundle();

                            break;
                        }
                    }
                }
                else
                {
                    BundleHelper.DownloadBundleFinish();
                }

                Game.Hotfix.LoadHotfixAssembly();

                // 加载配置
                Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d");
                Game.Scene.AddComponent <ConfigComponent>();
                Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d");
                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <MessageDispatcherComponent>();

                Game.Hotfix.GotoHotfix();

                // Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent");
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #26
0
        // 开启协程移动,每100毫秒移动一次,并且协程取消的时候会计算玩家真实移动
        // 比方说玩家移动了250毫秒,玩家有新的目标,这时旧的移动协程结束,将计算250毫秒移动的位置,而不是300毫秒移动的位置
        public async ETTask StartMove(CancellationToken cancellationToken)
        {
            Unit unit = this.GetParent <Unit>();

            this.StartPos  = unit.Position;
            this.StartTime = TimeHelper.Now();
            float distance = (this.Target - this.StartPos).magnitude;

            if (Math.Abs(distance) < 0.1f)
            {
                return;
            }


            this.needTime = (long)(distance / this.moveSpeed * 1000);

            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            // 协程如果取消,将算出玩家的真实位置,赋值给玩家
            cancellationToken.Register(() =>
            {
                long timeNow = TimeHelper.Now();
                if (timeNow - this.StartTime >= this.needTime)
                {
                    unit.Position = this.Target;

                    if (this.GetParent <Unit>().UnitType == UnitType.Player)
                    {
                        Console.WriteLine(" MoveComponent-77-unitPos: " + unit.UnitType + "  " + unit.Position.ToString());
                    }
                }
                else
                {
                    float amount  = (timeNow - this.StartTime) * 1f / this.needTime;
                    unit.Position = Vector3.Lerp(this.StartPos, this.Target, amount);

                    if (this.GetParent <Unit>().UnitType == UnitType.Player)
                    {
                        Console.WriteLine(" MoveComponent-87-unitPos: " + unit.UnitType + "  " + unit.Position.ToString());
                    }
                }
            });

            while (true)
            {
                await timerComponent.WaitAsync(50, cancellationToken); ///20190728 把50改为150 又改回为50

                long timeNow = TimeHelper.Now();

                if (timeNow - this.StartTime >= this.needTime)
                {
                    unit.Position = this.Target;

                    if (this.GetParent <Unit>().UnitType == UnitType.Player)
                    {
                        Console.WriteLine(" MoveComponent-104-unitPos: " + unit.UnitType + "  " + unit.Position.ToString());
                    }

                    break;
                }

                float amount = (timeNow - this.StartTime) * 1f / this.needTime;
                unit.Position = Vector3.Lerp(this.StartPos, this.Target, amount);
            }
        }