Narrator controller. Makes A User Friendly Singleton Object To Link All Scripts Of Type: OnCallPlayEventAudio OnTriggerPlay To Play From The Same AudioSource
Ejemplo n.º 1
0
    private void Start()
    {
        narrator = NarratorController.NarratorInstance;

        inputHandler = GameObject.FindGameObjectWithTag("Player").GetComponent<InputHandler>();
    }
    private void Update()
    {
        if(activePower.CurrentPower != ActivePower.Logio)
        {
            activePower.CurrentPower = ActivePower.Logio;
        }

        waitAtStart -= Time.deltaTime;
        if (waitAtStart <= 0 && !triggered)
        {
            narrator = NarratorController.NarratorInstance;
            narrator.PlayNewClip(audioClips[audioClipIndex], gameObject.GetInstanceID(), (IDestroyAudioEvent)this);

            myState = EAudioState.isPlaying;

            startTime = Time.time;
            triggered = true;

        }

        if(myState == EAudioState.isWaiting)
            return;

        if(myState == EAudioState.isFinished)
        {
            if( NarratorController.NarratorInstance.isPlaying() )
                myState = EAudioState.isPlaying;

            if( !colliderToTrigger.isTrigger )
            {
                colliderToTrigger.isTrigger = true;
            }
            return;
        }

        if(myState == EAudioState.isPaused)
        {
            if( Time.time > (startTime + waitTimeBetweenClips))
            {
                if(audioClipIndex == 2)
                    return;

                if(audioClipIndex == 3) // Out Of Cutscene Bounds
                {
                    myState = EAudioState.isFinished;
                    trigger.GetComponent<BoxCollider>().isTrigger = true;
                    //Destroy(this);
                }

                if(audioClipIndex == 1)
                {
                    playerInputManager.ControllerConstraints = EControlConstraints.EnableAllExceptPowers;
                    narrator.PlayNewClip(audioClips[audioClipIndex], gameObject.GetInstanceID(), (IDestroyAudioEvent)this);
                    myState = EAudioState.isPlaying;
                }

                startTime = Time.time;
            }// If Timer Hasnt Finished Then Wait
        }

        if(myState == EAudioState.isPlaying)
        {
            // If narrator hasnt finished return
            if(audioClipIndex == audioClips.Length && !NarratorController.NarratorInstance.isPlaying())
            {
                myState = EAudioState.isFinished;
                return;
            }

            // Evade NullReferenceExceptions
            if(audioClipIndex == audioClips.Length)
                return;

            if(Time.time < (startTime + audioClips[audioClipIndex].length))
            {
                // Figure out a button to skip (select/back maybe?)
                if( inputHandler.isSkip )
                {
                    narrator.Stop();
                    startTime = Time.time + 0.25f;
                    myState = EAudioState.isPaused;
                    audioClipIndex++;
                    return;
                }

            }

            if(Time.time > (startTime + audioClips[audioClipIndex].length))
            {
                startTime = Time.time;
                myState = EAudioState.isPaused;
                audioClipIndex++;
            }
        }
    }