Exemplo n.º 1
0
    //
    public void Play(SoundKey key, Vector3 pos)
    {
        if (clips.ContainsKey(key) == false)
        {
            return;
        }
        //
        AudioSource playAudio = null;

        //
        foreach (AudioSource audio in fxAudios)
        {
            if (audio.gameObject.activeSelf == false)
            {
                playAudio = audio;
                break;
            }
        }
        //
        if (playAudio == null)
        {
            return;
        }
        //
        playAudio.gameObject.SetActive(true);
        //
        playAudio.transform.position = pos;
        playAudio.PlayOneShot(clips[key]);
        //
        AudioDisable(playAudio, clips[key].length);
    }
Exemplo n.º 2
0
    // Ignores Looping and SpatialBlend
    public void PlaySound(SoundKey soundKey)
    {
        Sound sound = System.Array.Find(gameSounds, s => s.soundKey == soundKey);

        if (sound != null)
        {
            if (CanPlaySound(sound))
            {
                if (oneShotObj == null)
                {
                    oneShotObj = new GameObject("Audio Manager One Shot Object");
                    oneShotObj.transform.parent = transform;
                    oneShotAudioSource          = oneShotObj.AddComponent <AudioSource>();
                }

                // Audio Source Config
                oneShotAudioSource.volume       = sound.volume;
                oneShotAudioSource.pitch        = sound.pitch;
                oneShotAudioSource.spatialBlend = 0f;
                oneShotAudioSource.loop         = false;

                oneShotAudioSource.PlayOneShot(sound.clip, sound.volume);
            }
        }
        else
        {
            Debug.LogError("Sound " + soundKey + "not found!");
        }
    }
Exemplo n.º 3
0
        public SoundEffectInstance GetSound(SoundKey key)
        {
            SoundEffectInstance sound = null;

            soundMap.TryGetValue(key, out sound);
            return(sound);
        }
Exemplo n.º 4
0
    public void Play(SoundKey key, Vector3 pos)
    {
        if (!clips.ContainsKey(key))
        {
            return;
        }

        AudioSource playAudio = null;

        foreach (AudioSource audio in fxAudios)
        {
            if (!audio.gameObject.activeSelf)
            {
                playAudio = audio;
                break;
            }
        }

        if (playAudio == null)
        {
            return;
        }

        playAudio.gameObject.SetActive(true);
        playAudio.transform.position = pos;

        playAudio.PlayOneShot(clips[key]);

        StartCoroutine(AudioDisable(playAudio, clips[key].length));
    }
Exemplo n.º 5
0
        public void PlaySound(SoundKey key)
        {
            CheckDisposed();

            Cue sound = m_soundBank.GetCue(key.ToString());

            sound.Play();
        }
Exemplo n.º 6
0
        protected void RegisterSound(SoundKey key, SoundEffectInstance sound)
        {
            if (sound == null)
            {
                throw new ArgumentNullException("sound");
            }

            soundMap[key] = sound;
        }
Exemplo n.º 7
0
    public void PlayBgm(SoundKey key)
    {
        if (!clips.ContainsKey(key))
        {
            return;
        }

        bgAudio.clip = clips[key];
        bgAudio.Play();
    }
Exemplo n.º 8
0
        protected void DeregisterSound(SoundKey key)
        {
            SoundEffectInstance sound;

            if (soundMap.TryGetValue(key, out sound))
            {
                sound.Dispose();
            }

            soundMap.Remove(key);
        }
Exemplo n.º 9
0
        private void AddKey(float time)
        {
            SoundKey newKey = ScriptableObject.CreateInstance <SoundKey>();

            newKey.Clip     = null;
            newKey.FireTime = time;

            EventOrientedKeyView e = CreateEvent(newKey);

            RebuildTrackKeys();
            InspectorProperties.Select(e);
        }
Exemplo n.º 10
0
 //
 public void PlayBGR(SoundKey key)
 {
     if (clips.ContainsKey(key) == false)
     {
         return;
     }
     //
     bgAuido.clip = clips[key];
     //
     if (bgAuido.isPlaying == false)
     {
         bgAuido.Play();
     }
 }
Exemplo n.º 11
0
        protected void RegisterSound(SoundKey key, string asset)
        {
            if (asset == null)
            {
                throw new ArgumentNullException("asset");
            }

            try
            {
                var soundEffect = Content.Load <SoundEffect>(asset);
                soundMap[key] = soundEffect.CreateInstance();
            }
            catch (ContentLoadException) { }
        }
Exemplo n.º 12
0
            public SoundKeyView(SoundTrackBar trackBar, SoundKey key)
                : base(trackBar, key)
            {
                this._SoundKey = key;
                _PreviewImage  = new AudioPreviewCurve()
                {
                    Margin = new Skill.Framework.UI.Thickness(2), BackgroundColor = Color.clear
                };
                _LblClipName = new Skill.Framework.UI.Label()
                {
                    Style = Resources.Styles.EventLabel
                };

                Controls.Add(_PreviewImage);
                Controls.Add(_LblClipName);
            }
Exemplo n.º 13
0
    //
    public void Play(SoundKey key, int audioIndex, bool loop = false)
    {
        AudioSource playAudio = null;

        playAudio = fxAudios[(fxAudios.Count - 1) - audioIndex];
        //
        if (loop == true)
        {
            if (playAudio.isPlaying == true)
            {
                return;
            }
        }
        //
        playAudio.gameObject.SetActive(true);
        playAudio.PlayOneShot(clips[key]);
        AudioDisable(playAudio, clips[key].length);
    }
Exemplo n.º 14
0
    public AudioSource PlaySound(SoundKey soundKey, Vector3 position)
    {
        Sound sound = System.Array.Find(gameSounds, s => s.soundKey == soundKey);

        if (sound != null)
        {
            if (CanPlaySound(sound))
            {
                GameObject soundGameObject = new GameObject("Audio Manager 3D Object");
                soundGameObject.transform.position = position;
                soundGameObject.transform.parent   = transform;
                AudioSource audioSource = soundGameObject.AddComponent <AudioSource>();

                // Audio Source Config
                audioSource.clip         = sound.clip;
                audioSource.volume       = sound.volume;
                audioSource.pitch        = sound.pitch;
                audioSource.spatialBlend = sound.spatialBlend;
                audioSource.loop         = sound.loop;

                if (sound.loop)
                {
                    audioSource.Play();
                    return(audioSource);
                }
                else
                {
                    audioSource.Play();
                    Object.Destroy(soundGameObject, audioSource.clip.length);
                    return(audioSource);
                    // TODO: To improve performace: Object Pooling
                }
            }
            else
            {
                return(null);
            }
        }
        else
        {
            Debug.LogError("Sound " + soundKey + "not found!");
            return(null);
        }
    }
Exemplo n.º 15
0
    public void Play(SoundKey key, Transform target = null)
    {
        if (!clips.ContainsKey(key))
        {
            return;
        }

        AudioSource playAudio = null;

        foreach (AudioSource audio in fxAudios)
        {
            if (!audio.gameObject.activeSelf)
            {
                playAudio = audio;
                break;
            }
        }

        if (playAudio == null)
        {
            return;
        }

        playAudio.gameObject.SetActive(true);

        if (transform == null)
        {
            playAudio.transform.SetParent(Camera.main.transform);
        }
        else
        {
            playAudio.transform.SetParent(target);
        }

        playAudio.transform.localPosition = Vector3.zero;

        playAudio.PlayOneShot(clips[key]);

        StartCoroutine(AudioDisable(playAudio, clips[key].length));
    }
Exemplo n.º 16
0
    //
    public void Play(SoundKey key, Transform target = null, float effVol = -1.0f)
    {
        if (clips.ContainsKey(key) == false)
        {
            return;
        }
        //
        AudioSource playAudio = null;

        //
        foreach (AudioSource audio in fxAudios)
        {
            if (audio.gameObject.activeSelf == false)
            {
                playAudio = audio;
                break;
            }
        }
        if (playAudio == null)
        {
            return;
        }
        //
        playAudio.gameObject.SetActive(true);
        //
        if (target != null)
        {
            playAudio.transform.SetParent(target);
        }
        //
        playAudio.transform.localPosition = Vector3.zero;
        //
        playAudio.PlayOneShot(clips[key]);
        //
        AudioDisable(playAudio, clips[key].length);
    }
Exemplo n.º 17
0
 public SoundEffectInstance GetSound(SoundKey key)
 {
     SoundEffectInstance sound = null;
     soundMap.TryGetValue(key, out sound);
     return sound;
 }
Exemplo n.º 18
0
        protected void RegisterSound(SoundKey key, SoundEffectInstance sound)
        {
            if (sound == null) throw new ArgumentNullException("sound");

            soundMap[key] = sound;
        }
Exemplo n.º 19
0
        protected void RegisterSound(SoundKey key, string asset)
        {
            if (asset == null) throw new ArgumentNullException("asset");

            try
            {
                var soundEffect = Content.Load<SoundEffect>(asset);
                soundMap[key] = soundEffect.CreateInstance();
            }
            catch (ContentLoadException) { }
        }
Exemplo n.º 20
0
        protected void DeregisterSound(SoundKey key)
        {
            SoundEffectInstance sound;
            if (soundMap.TryGetValue(key, out sound)) sound.Dispose();

            soundMap.Remove(key);
        }