public void SetTimeToEnviroTime(EnviroTime time, EnviroTime newTime) { time.Days = newTime.Days; time.Hours = newTime.Hours; time.Minutes = newTime.Minutes; time.Seconds = newTime.Seconds; }
static void Draw_Time(EnvironmentSimulator sim) { EnviroTime time = sim.EnviroSky.GameTime; bool flag0, flag1, flag2, flag3, flag4; int year, day, hour, minute, second; if (shouldUpdate) { temp_year = time.Years.ToString(); temp_day = time.Days.ToString(); temp_hour = time.Hours.ToString(); temp_minute = time.Minutes.ToString(); temp_second = time.Seconds.ToString(); } GUILayout.Label("日期 和 时间", headerStyle); GUILayout.BeginHorizontal(); { temp_year = Draw_Time_Field("年", temp_year, out year, out flag0); temp_day = Draw_Time_Field("天", temp_day, out day, out flag1); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { temp_hour = Draw_Time_Field("小时", temp_hour, out hour, out flag2); temp_minute = Draw_Time_Field("分钟", temp_minute, out minute, out flag3); temp_second = Draw_Time_Field("秒", temp_second, out second, out flag4); } GUILayout.EndHorizontal(); if (GUILayout.Button("更新 日期 和 时间") && flag0 && flag1 && flag2 && flag3 && flag4) { sim.EnviroSky.SetTime(year, day, hour, minute, second); temp_year = time.Years.ToString(); temp_day = time.Days.ToString(); temp_hour = time.Hours.ToString(); temp_minute = time.Minutes.ToString(); temp_second = time.Seconds.ToString(); } }
public TimeSpan DeltaTimeSpan(DateTime newTime, EnviroTime oldEnviroTime) { DateTime dateTime = new DateTime(1, 1, oldEnviroTime.Days, oldEnviroTime.Hours, oldEnviroTime.Minutes, oldEnviroTime.Seconds); return(newTime - dateTime); }
private void OnTimeUpdate() { EnviroTime oldTime = this.OldTime; EnviroTime gameTime = this._enviroSky.GameTime; DateTime newTime = new DateTime(1, 1, gameTime.Days, gameTime.Hours, gameTime.Minutes, gameTime.Seconds); bool flag = false; if (gameTime.Days > oldTime.Days) { TimeSpan timeSpan1 = this.DeltaTimeSpan(newTime, this.OldDayUpdatedTime); TimeSpan timeSpan2 = this.DeltaTimeSpan(newTime, this.OldHourUpdatedTime); TimeSpan timeSpan3 = this.DeltaTimeSpan(newTime, this.OldMinuteUpdatedTime); TimeSpan timeSpan4 = this.DeltaTimeSpan(newTime, this.OldSecondUpdatedTime); gameTime.Days = 1; if (this._onDay != null) { this._onDay.OnNext(timeSpan1); } if (this._onHour != null) { this._onHour.OnNext(timeSpan2); } if (this._onMinute != null) { this._onMinute.OnNext(timeSpan3); } if (this._onSecond != null) { this._onSecond.OnNext(timeSpan4); } flag = true; this.SetTimeToEnviroTime(this.OldDayUpdatedTime, gameTime); this.SetTimeToEnviroTime(this.OldHourUpdatedTime, gameTime); this.SetTimeToEnviroTime(this.OldMinuteUpdatedTime, gameTime); this.SetTimeToEnviroTime(this.OldSecondUpdatedTime, gameTime); } else if (gameTime.Hours > oldTime.Hours) { TimeSpan timeSpan1 = this.DeltaTimeSpan(newTime, this.OldHourUpdatedTime); TimeSpan timeSpan2 = this.DeltaTimeSpan(newTime, this.OldMinuteUpdatedTime); TimeSpan timeSpan3 = this.DeltaTimeSpan(newTime, this.OldSecondUpdatedTime); if (this._onHour != null) { this._onHour.OnNext(timeSpan1); } if (this._onMinute != null) { this._onMinute.OnNext(timeSpan2); } if (this._onSecond != null) { this._onSecond.OnNext(timeSpan3); } flag = true; this.SetTimeToEnviroTime(this.OldHourUpdatedTime, gameTime); this.SetTimeToEnviroTime(this.OldMinuteUpdatedTime, gameTime); this.SetTimeToEnviroTime(this.OldSecondUpdatedTime, gameTime); } else if (gameTime.Minutes > oldTime.Minutes) { TimeSpan timeSpan1 = this.DeltaTimeSpan(newTime, this.OldMinuteUpdatedTime); TimeSpan timeSpan2 = this.DeltaTimeSpan(newTime, this.OldSecondUpdatedTime); if (this._onMinute != null) { this._onMinute.OnNext(timeSpan1); } if (this._onSecond != null) { this._onSecond.OnNext(timeSpan2); } flag = true; this.SetTimeToEnviroTime(this.OldMinuteUpdatedTime, gameTime); this.SetTimeToEnviroTime(this.OldSecondUpdatedTime, gameTime); } else if (gameTime.Seconds > oldTime.Seconds) { TimeSpan timeSpan = this.DeltaTimeSpan(newTime, this.OldSecondUpdatedTime); if (this._onSecond != null) { this._onSecond.OnNext(timeSpan); } flag = true; this.SetTimeToEnviroTime(this.OldSecondUpdatedTime, gameTime); } if (!flag) { return; } this.OldTime.Days = gameTime.Days; this.OldTime.Hours = gameTime.Hours; this.OldTime.Minutes = gameTime.Minutes; this.OldTime.Seconds = gameTime.Seconds; }