Esempio n. 1
0
        public SequenceSoundInstance Fetch(ISoundPool soundPool)
        {
            if (!IsPlayable())
            {
                return(null);
            }

            SequenceSoundInstance sound = soundPool.FetchFromPool <SequenceSoundInstance>();

            sound.name = name;

            for (int i = 0; i < _sections.Length; i++)
            {
                if (!_sections[i].Sound.IsEmpty)
                {
                    sound.AddSection(_sections[i]);
                }
            }

            if (_outputMixer != null)
            {
                sound.SetMixerGroup(_outputMixer);
            }

            AddFilters(sound);

            return(sound);
        }
Esempio n. 2
0
        /// <summary>
        /// Fetches and then plays a sound that will follow a transform around.
        /// </summary>
        /// <param name="followTransform">The transform to follow</param>
        public static SequenceSoundInstance Play(this SequenceSoundBank soundBank, Transform followTransform)
        {
            if (soundBank != null)
            {
                SequenceSoundInstance sound = soundBank.Fetch(RuntimeSoundPool.Instance);
                sound.Play3D(followTransform);
                soundBank.OnPlayed(sound);

                return(sound);
            }

            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Fetches and then plays a sound at a specific position.
        /// </summary>
        /// <param name="position">The world-space position of the sound emission</param>
        public static SequenceSoundInstance Play(this SequenceSoundBank soundBank, Vector3 position)
        {
            if (soundBank != null)
            {
                SequenceSoundInstance sound = soundBank.Fetch(RuntimeSoundPool.Instance);
                sound.Play3D(position);
                soundBank.OnPlayed(sound);

                return(sound);
            }

            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Fetches and then plays a non-spatial sound, ie. one that does not emit from a specific location and rolloff.
        /// </summary>
        /// <param name="soundBank">The sound bank used to set-up the sound instance</param>
        public static SequenceSoundInstance Play(this SequenceSoundBank soundBank)
        {
            if (soundBank != null)
            {
                SequenceSoundInstance sound = soundBank.Fetch(RuntimeSoundPool.Instance);
                sound.Play2D();
                soundBank.OnPlayed(sound);

                return(sound);
            }

            return(null);
        }
Esempio n. 5
0
        public override SoundInstance TestInEditor(ISoundPool soundPool)
        {
            SequenceSoundInstance sound = Fetch(soundPool);

            if (sound != null)
            {
                sound.Play2D();
                OnPlayed(sound);

                return(sound);
            }

            return(null);
        }
Esempio n. 6
0
        void DrawButtonSection()
        {
            if (targets.Length > 1)
            {
                return;
            }

            SerializedProperty clipsProperty = serializedObject.FindProperty("_audioClips");

            if (Event.current.commandName == "ObjectSelectorClosed" && _pickedObjectReady)
            {
                _pickedObjectReady = false;
                if (EditorGUIUtility.GetObjectPickerObject() != null)
                {
                    if (clipsProperty.arraySize == 0 || clipsProperty.GetArrayElementAtIndex(clipsProperty.arraySize - 1).objectReferenceValue != null)
                    {
                        clipsProperty.arraySize++;
                    }

                    clipsProperty.GetArrayElementAtIndex(clipsProperty.arraySize - 1).objectReferenceValue = EditorGUIUtility.GetObjectPickerObject();
                    serializedObject.ApplyModifiedProperties();
                }
            }

            GUILayout.BeginHorizontal();

            if (clipsProperty != null)
            {
                if (GUILayout.Button("Add Clip", GUILayout.MaxWidth(80)))
                {
                    UnityEngine.Object defaultClip = null;

                    if (clipsProperty.arraySize > 0)
                    {
                        defaultClip = clipsProperty.GetArrayElementAtIndex(clipsProperty.arraySize - 1).objectReferenceValue;
                    }

                    _pickedObjectReady = true;
                    EditorGUIUtility.ShowObjectPicker <AudioClip>(defaultClip, false, "", -1);
                }

                if (GUILayout.Button("Clear Clips", GUILayout.MaxWidth(80)))
                {
                    clipsProperty.arraySize = 0;
                    serializedObject.ApplyModifiedProperties();
                }
            }

            if (_bank is BlendSoundBank)
            {
                EditorGUIUtility.labelWidth = 45f;
                _blendParameter             = EditorGUILayout.Slider(new GUIContent("Blend"), _blendParameter, 0, 1);
            }
            else if (_bank is SequenceSoundBank)
            {
                SequenceSoundInstance sequence = null;
                if (_lastInstance != null)
                {
                    sequence = _lastInstance as SequenceSoundInstance;
                }

                if (sequence != null && sequence.HasPreviousSection)
                {
                    if (GUILayout.Button("<<", GUILayout.MaxWidth(50f)))
                    {
                        sequence.PlayPreviousSection();
                    }
                }
                else
                {
                    EditorGUI.BeginDisabledGroup(true);
                    GUILayout.Button("<<", GUILayout.MaxWidth(50f));
                    EditorGUI.EndDisabledGroup();
                }

                if (sequence != null && sequence.HasNextSection)
                {
                    if (GUILayout.Button(">>", GUILayout.MaxWidth(50f)))
                    {
                        sequence.PlayNextSection();
                    }
                }
                else
                {
                    EditorGUI.BeginDisabledGroup(true);
                    GUILayout.Button(">>", GUILayout.MaxWidth(50f));
                    EditorGUI.EndDisabledGroup();
                }

                GUILayout.FlexibleSpace();
            }
            else
            {
                GUILayout.FlexibleSpace();
            }

            if (GUILayout.Button("PLAY", GUILayout.MaxWidth(80f)))
            {
                if (_soundPool == null)
                {
                    _soundPool = new EditorSoundPool();
                    Selection.selectionChanged += _soundPool.Clear;
                }
                else
                {
                    _soundPool.Clear();
                }

                _lastInstance = _bank.TestInEditor(_soundPool);
            }

            if (GUILayout.Button("STOP", GUILayout.MaxWidth(80f)))
            {
                if (_lastInstance != null)
                {
                    _lastInstance.StopAndDestroy();
                }
            }

            BlendSoundInstance blend = _lastInstance as BlendSoundInstance;

            if (blend != null)
            {
                blend.SetBlendParameter(_blendParameter);
            }

            GUILayout.EndHorizontal();
        }