Exemple #1
0
        void AddSpeaker(SpeakerTrack myScript, int speakerIndex, float time)
        {
            SpeakerEvent[] n = new SpeakerEvent[myScript.Length + 1];

            SpeakerEvent ev = new SpeakerEvent();

            ev.speakerIndex = speakerIndex;
            ev.time         = time;
            bool newEvtAdded = false;
            int  i           = 0;

            foreach (SpeakerEvent ev1 in myScript.Events)
            {
                if (!newEvtAdded && ev.time < ev1.time)
                {
                    n [i++]     = ev;
                    newEvtAdded = true;
                }
                else
                {
                    n [i++] = ev1;
                }
            }
            if (newEvtAdded == false)
            {
                n[n.Length - 1] = ev;
            }

            myScript.Events = n;
        }
Exemple #2
0
        public SpeakerTrack()
        {
            Events = new SpeakerEvent[1];
            SpeakerEvent evt = new SpeakerEvent();

            Events[0] = evt;
        }
Exemple #3
0
        public int GetSpeakerAt(float time)
        {
            SpeakerEvent prevEv = null;

            foreach (SpeakerEvent evt in Events)
            {
                if (evt.time > time)
                {
                    if (prevEv != null)
                    {
                        return(prevEv.speakerIndex);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                prevEv = evt;
            }
            return(-1);
        }
        private IEnumerator PlayDialog()
        {
            float time = 0;

            DialogSoundSource.clip = Track.DialogClip;
            DialogSoundSource.Play();
            SpeakerEvent nextEv = null;

            for (int nextEventIndex = 0; nextEventIndex < Track.Length; ++nextEventIndex)
            {
                nextEv = Track.Events[nextEventIndex];
                while (nextEv.time > time)
                {
                    yield return(null);

                    time = DialogSoundSource.time;
                }
                Debug.Log("setting speaker :" + nextEv.speakerIndex + " at time " + nextEv.time);
                if (nextEv.speakerIndex == -1)
                {
                    ShutUpCurrentSpeaker();
                }
                else
                {
                    SetSpeaker(nextEv.speakerIndex);
                }
            }

            Debug.Log("Waiting for end");
            //wait for tOhe end of the  clip.
            yield return(new WaitForSeconds(DialogSoundSource.clip.length - time));

            Debug.Log("Deactivating Last speaker");
            //stop last speaker
            ShutUpCurrentSpeaker();
            coroutine = null;
        }