// Change current lights state public void ChangeLightState(bool redLight, bool yellowLight, bool greenLight, TrafficLightPhase parentPhase) { mParentPhase = parentPhase; OnLightStateChanged(redLight, yellowLight, greenLight); }
// coroutine for main program private IEnumerator MainProgramCo() { // select first phase from list mCurrentPhaseIndex = 0; mCurrentPhase = PhaseList[0]; // begin with all traffic lights modules set to 'Stop' state (red lights) SetAllPhasesTo(TrafficLightBase.State.Stop); while (true) { // set current phase to 'PrepareToGo' state (red and yellow lights) mCurrentPhase.SetState(TrafficLightBase.State.PrepareToGo); // wait for end of state yield return new WaitForSeconds(mCurrentPhase.PhaseStartTime); // set current phase to 'Go' state (green lights) mCurrentPhase.SetState(TrafficLightBase.State.Go); // wait for end of state yield return new WaitForSeconds(mCurrentPhase.PhaseActiveTime); // set current phase to 'PrepareToStop' state (yellow lights) mCurrentPhase.SetState(TrafficLightBase.State.PrepareToStop); // wait for end of state yield return new WaitForSeconds(mCurrentPhase.PhaseEndTime); // set current phase to 'Stop' state (red lights) mCurrentPhase.SetState(TrafficLightBase.State.Stop); // this phase has ended so make delay between phases before nex phase will be started yield return new WaitForSeconds(PhaseDelay); // calculate next phase index mCurrentPhaseIndex++; mCurrentPhaseIndex = mCurrentPhaseIndex % PhaseList.Count; // select next phase and continue program's loop mCurrentPhase = PhaseList[mCurrentPhaseIndex]; } }