public void NetForecastInfo(Vector3 nPos, Vector3 nRot) { this.m_nPos = nPos; this.m_nRot = nRot; try { // 预测的位置 this.m_fPos = this.m_lPos + (this.m_nPos - this.m_lPos) * 2; this.m_fRot = this.m_lRot + (this.m_nRot - this.m_lRot) * 2; if (TimeHelper.NowMilliSecond() - this.m_lastRecvInfoTime > 300f) { this.m_fPos = this.m_nPos; this.m_fRot = this.m_nRot; } // 时间间隔 //this.m_delta = (TimeHelper.NowMilliSecond() - this.m_lastRecvInfoTime) / 1000f; //Log.Info($"{this.m_delta}"); // 更新 this.m_lPos = this.m_nPos; this.m_lRot = this.m_nRot; this.m_lastRecvInfoTime = TimeHelper.NowMilliSecond(); } catch (Exception e) { Log.Error("NetForecastInfo" + e); } //UpdatePos(); }
public ETTask MoveToAsync(Vector3 target, float speedValue, CancellationToken cancellationToken) { Unit unit = this.GetParent <Unit>(); if ((target - this.Target).magnitude < 0.1f) { return(ETTask.CompletedTask); } this.Target = target; this.StartPos = unit.Position; this.StartTime = TimeHelper.NowMilliSecond(); float distance = (this.Target - this.StartPos).magnitude; if (Math.Abs(distance) < 0.1f) { return(ETTask.CompletedTask); } this.needTime = (long)(distance / speedValue * 1000); this.moveTcs = new ETTaskCompletionSource(); cancellationToken.Register(() => { this.moveTcs = null; }); return(this.moveTcs.Task); }
public void LateUpdate() { // 时间间隔 this.m_delta = (TimeHelper.NowMilliSecond() - this.m_lastRecvInfoTime) / 1000f; UpdatePos(); WheelsRotation(); }
public void Awake() { Log.Warning($"Awake时间:{TimeHelper.NowMilliSecond()}"); this.m_bullet = this.GetParent <Bullet>(); this.instantiateTime = Time.time; this.m_collider = this.m_bullet.GameObject.GetComponent <SphereCollider>(); }
public ETTask WaitAsync(long time) { ETTaskCompletionSource tcs = new ETTaskCompletionSource(); Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = TimeHelper.NowMilliSecond() + time, tcs = tcs }; this.timers[timer.Id] = timer; this.timeId.Add(timer.Time, timer.Id); if (timer.Time < this.minTime) { this.minTime = timer.Time; } return(tcs.Task); }
public ETTask WaitAsync(long time, CancellationToken cancellationToken) { ETTaskCompletionSource tcs = new ETTaskCompletionSource(); Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = TimeHelper.NowMilliSecond() + time, tcs = tcs }; this.timers[timer.Id] = timer; this.timeId.Add(timer.Time, timer.Id); if (timer.Time < this.minTime) { this.minTime = timer.Time; } cancellationToken.Register(() => { this.Remove(timer.Id); }); return(tcs.Task); }
public void Update() { if (this.timeId.Count == 0) { return; } long timeNow = TimeHelper.NowMilliSecond(); if (timeNow < this.minTime) { return; } foreach (KeyValuePair <long, List <long> > kv in this.timeId.GetDictionary()) { long k = kv.Key; if (k > timeNow) { minTime = k; break; } this.timeOutTime.Enqueue(k); } while (this.timeOutTime.Count > 0) { long time = this.timeOutTime.Dequeue(); foreach (long timerId in this.timeId[time]) { this.timeOutTimerIds.Enqueue(timerId); } this.timeId.Remove(time); } while (this.timeOutTimerIds.Count > 0) { long timerId = this.timeOutTimerIds.Dequeue(); Timer timer; if (!this.timers.TryGetValue(timerId, out timer)) { continue; } this.timers.Remove(timerId); timer.tcs.SetResult(); } }
//private long castTime; public void NetForecastInfo(Vector3 nPos, Vector3 nRot) { this.m_nPos = nPos; this.m_nRot = nRot; //Log.Warning($"收到位置信息间隔时间{(TimeHelper.NowMilliSecond() - this.castTime)*1.0f / 1000}s"); //castTime = TimeHelper.NowMilliSecond(); //try { // 预测的位置 this.m_fPos = this.m_lPos + (this.m_nPos - this.m_lPos) * 2; this.m_fRot = this.m_lRot + (this.m_nRot - this.m_lRot) * 2; if (TimeHelper.NowMilliSecond() - this.m_lastRecvInfoTime > 300f) //大于0.3s { this.m_fPos = this.m_nPos; this.m_fRot = this.m_nRot; } // 时间间隔 //this.m_delta = (TimeHelper.NowMilliSecond() - this.m_lastRecvInfoTime) / 1000f; //Log.Info($"{this.m_delta}"); // 更新 this.m_lPos = this.m_nPos; this.m_lRot = this.m_nRot; } // catch (Exception e) // { // Log.Error("NetForecastInfo" + e); // } //UpdatePos(); }
public void Update() { if (this.moveTcs == null) { return; } Unit unit = this.GetParent <Unit>(); long timeNow = TimeHelper.NowMilliSecond(); if (timeNow - this.StartTime >= this.needTime) { unit.Position = this.Target; ETTaskCompletionSource tcs = this.moveTcs; this.moveTcs = null; tcs.SetResult(); return; } float amount = (timeNow - this.StartTime) * 1f / this.needTime; unit.Position = Vector3.Lerp(this.StartPos, this.Target, amount); }
public void Start() { Log.Warning($"Start时间:{TimeHelper.NowMilliSecond()}"); OnTrigger(); }