public void SetCycleStage(CycleStage stage, int offset = 0) { switch (stage) { case CycleStage.Start: _counter = (uint)Mathf.Min(Mathf.Max(0, offset), (int)_nextCycleBreakpoint); break; case CycleStage.WaitingToStop: _counter = (uint)Mathf.Min(Mathf.Max(1, 1 + offset), (int)_nextCycleBreakpoint); break; case CycleStage.StopPoint: CalculateNextCycleBreakpoint(); _counter = (uint)Mathf.Min(Mathf.Max(0, _nextCycleBreakpoint + offset), (int)_cycleLength); break; case CycleStage.WaitingToCycle: CalculateNextCycleBreakpoint(); _counter = (uint)Mathf.Min(Mathf.Max(_nextCycleBreakpoint + 1, _nextCycleBreakpoint + offset), (int)_cycleLength); break; default: ResetCycle(); break; } }
void Start() { Clouds = GetComponentsInChildren <SkyCloud>(); DaySky.color = SetColorAlpha(DaySky.color, 1); NightSky.color = SetColorAlpha(NightSky.color, 1); stage = CycleStage.Day; for (int i = 0; i < Clouds.Length; i++) { Clouds[i].SetAlpha(1); } }
// Update is called once per frame void Update() { timer += Time.deltaTime; if (stage == CycleStage.Day || stage == CycleStage.Night) { if (timer > CycleTimer) { timer = timer % CycleTimer; if (stage == CycleStage.Day) { stage = CycleStage.DayToNight; DaySky.sortingOrder = -100; NightSky.sortingOrder = -200; NightSky.color = SetColorAlpha(NightSky.color, 1); } else { stage = CycleStage.NightToDay; DaySky.sortingOrder = -200; NightSky.sortingOrder = -100; DaySky.color = SetColorAlpha(DaySky.color, 1); } } } else if (stage == CycleStage.DayToNight) { if (timer < TransitionTime) { DaySky.color = SetColorAlpha(DaySky.color, 1 - (timer / TransitionTime)); for (int i = 0; i < Clouds.Length; i++) { Clouds[i].SetAlpha(1 - (timer * 0.5f / TransitionTime)); } } else { timer = timer % CycleTimer; DaySky.color = SetColorAlpha(DaySky.color, 0); stage = CycleStage.Night; for (int i = 0; i < Clouds.Length; i++) { Clouds[i].SetAlpha(0.5f); } } } else if (stage == CycleStage.NightToDay) { if (timer < TransitionTime) { NightSky.color = SetColorAlpha(NightSky.color, 1 - (timer / TransitionTime)); for (int i = 0; i < Clouds.Length; i++) { Clouds[i].SetAlpha(0.5f + (timer * 0.5f / TransitionTime)); } } else { timer = timer % CycleTimer; NightSky.color = SetColorAlpha(NightSky.color, 0); stage = CycleStage.Day; for (int i = 0; i < Clouds.Length; i++) { Clouds[i].SetAlpha(1); } } } }