Exemplo n.º 1
0
 void Awake()
 {
     Position           = AudioPosition.Center;
     lastPositionQueued = Position;
     lowPriority        = false;
     Load();
     audioQueue = new Queue <string>();
     StartCoroutine(PlayQueue());
 }
Exemplo n.º 2
0
    IEnumerator PlayQueue()
    {
        while (true)
        {
            bool areThereClipsHighPriority = false;
            foreach (string clip in audioQueue.ToArray())
            {
                if (clip.Substring(0, 1) != "[")
                {
                    if (clip.Substring(0, 1) != "*")
                    {
                        areThereClipsHighPriority = true;
                        break;
                    }
                }
            }

            if (audioQueue.Count != 0 && (!source.isPlaying || (lowPriority && areThereClipsHighPriority)))
            {
                if (source.isPlaying)
                {
                    source.Stop();
                }
                string nextSound = audioQueue.Dequeue();
                switch (nextSound)
                {
                case "[front]": Position = AudioPosition.Front; break;

                case "[left]": Position = AudioPosition.Left;; break;

                case "[right]": Position = AudioPosition.Right; break;

                case "[center]": Position = AudioPosition.Center; break;

                case "[space]": yield return(new WaitForSeconds(0.1f)); break;

                default:
                    lowPriority = (nextSound.Substring(0, 1) == "*");     // if the clip is low priority any other not low-priority clip can interrupt it automatically
                    if (lowPriority)
                    {
                        nextSound = nextSound.Substring(1);
                    }
                    source.clip = SoundBank.GetSound(nextSound);
                    if (source.clip != null)
                    {
                        source.Play();
                        //if (!lowPriority) {
                        //    yield return new WaitForSeconds(source.clip.length);
                        //}
                    }
                    break;
                }
            }
            yield return(null);
        }
    }
Exemplo n.º 3
0
 public void GetToast(AudioManager audioManager, AudioPosition position, bool interrupt = true)
 {
     if (IsDead())
     {
         audioManager.Play(name + " is-dead", "", true, position);
     }
     else
     {
         audioManager.Play("_" + name + " " + currentHealth + (currentStamina < 0 ? "" : ", stamina " + currentStamina), "", interrupt, position);
     }
 }
Exemplo n.º 4
0
 public void GetToast(AudioManager audioManager, AudioPosition position)
 {
     if (explored)
     {
         audioManager.Play("this-path-have-beed-already-explored", "", true);
     }
     else
     {
         audioManager.Play("you-peek-at-this-path", "", true);
         Character.GetRandomCharacter(enemies).GetToast(audioManager, position, false);
     }
 }
Exemplo n.º 5
0
    public void Play(string clips, string message = "", bool interrupt = false, AudioPosition pos = AudioPosition.Center)
    {
        bool lowP = false;

        if (message != "")
        {
            Debug.Log(message);
        }
        else
        {
            Debug.Log(clips.Replace("-", " ").Replace("_", "").Replace("*", ""));
        }
        if (interrupt)
        {
            Interrupt();
        }
        if (lastPositionQueued != pos)
        {
            switch (pos)
            {
            case AudioPosition.Center: audioQueue.Enqueue("[center]"); break;

            case AudioPosition.Front: audioQueue.Enqueue("[front]"); break;

            case AudioPosition.Left: audioQueue.Enqueue("[left]"); break;

            case AudioPosition.Right: audioQueue.Enqueue("[right]"); break;
            }
            lastPositionQueued = pos;
        }
        lowP = (clips.Substring(0, 1) == "*");
        if (lowP)
        {
            clips = clips.Substring(1);
        }

        List <string> playable = new List <string>(clips.Split(','));

        foreach (string s in playable)
        {
            SplitSpaces(s.Trim(), lowP);
        }
    }