示例#1
0
 protected virtual void OnEnable()
 {
     _lastPlayedSound = null;
     _lastPlayedTime  = Mathf.NegativeInfinity;
 }
示例#2
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();
        }
示例#3
0
 public void OnPlayed(SoundInstance sound)
 {
     _lastPlayedTime  = GetCurrentTime();
     _lastPlayedSound = sound;
 }