Example #1
0
    public IEnumerator SetState(SemaphoreSection.SectionType targetSection, float delay = 0)
    {
        yield return(new WaitForSeconds(delay));

        while (state != targetSection)
        {
            settingState = true;
            switch (targetSection)
            {
            case SemaphoreSection.SectionType.red:

                switch (state)
                {
                case SemaphoreSection.SectionType.red:
                    Section.EnableLight();
                    yield return(null);

                    break;

                case SemaphoreSection.SectionType.yellow:
                    SetSingleSectionState(SemaphoreSection.SectionType.red);
                    yield return(null);

                    break;

                case SemaphoreSection.SectionType.green:
                    yield return(StartCoroutine(Section.Blink()));

                    SetSingleSectionState(SemaphoreSection.SectionType.yellow);
                    yield return(StartCoroutine(SetState(targetSection, sectionChangeDelay)));

                    break;
                }

                break;

            case SemaphoreSection.SectionType.yellow:
                switch (state)
                {
                case SemaphoreSection.SectionType.red:
                    SetSingleSectionState(SemaphoreSection.SectionType.yellow);
                    yield return(null);

                    break;

                case SemaphoreSection.SectionType.yellow:
                    Section.EnableLight();
                    yield return(null);

                    break;

                case SemaphoreSection.SectionType.green:
                    yield return(StartCoroutine(Section.Blink()));

                    SetSingleSectionState(SemaphoreSection.SectionType.yellow);
                    yield return(StartCoroutine(SetState(targetSection, sectionChangeDelay)));

                    break;
                }

                break;

            case SemaphoreSection.SectionType.green:
                switch (state)
                {
                case SemaphoreSection.SectionType.red:
                    SetSingleSectionState(SemaphoreSection.SectionType.yellow);
                    yield return(StartCoroutine(SetState(targetSection, sectionChangeDelay)));

                    break;


                case SemaphoreSection.SectionType.yellow:
                    SetSingleSectionState(SemaphoreSection.SectionType.green);
                    yield return(null);

                    break;

                case SemaphoreSection.SectionType.green:
                    Section.EnableLight();
                    yield return(null);

                    break;
                }

                break;
            }
        }

        settingState = false;
        sectionChangeFinished?.Invoke();
    }
Example #2
0
 void SetSingleSectionState(SemaphoreSection.SectionType targetSection)
 {
     Section.DisableLight();
     sections[(int)targetSection].EnableLight();
     state = targetSection;
 }