Esempio n. 1
0
        public AudioItem GetNext()
        {
            AudioItem item = audioItems[next];

            next = (next + 1) % audioItems.Length;
            return(item);
        }
Esempio n. 2
0
        private void Play(AudioItem audioItem)
        {
            if (audioItem == null)
            {
                return;
            }
            AudioSource source = GetNextAudioSource();

            if (source == null)
            {
                return;
            }
            source.outputAudioMixerGroup = output;
            source.volume = volume;
            source.clip   = audioItem.AudioClip;
            source.pitch  = Random.Range(audioItem.PitchRange.x, audioItem.PitchRange.y);
            source.Play();
        }
        private void OnEnable()
        {
            list = new ReorderableList(serializedObject:    serializedObject,
                                       elements:            serializedObject.FindProperty("audioItems"),
                                       draggable:           false,
                                       displayHeader:       true,
                                       displayAddButton:    true,
                                       displayRemoveButton: true)
            {
                drawHeaderCallback = (rect) => { EditorGUI.LabelField(rect, "Audio Items"); },

                drawElementCallback = (rect, index, active, focused) => {
                    SerializedProperty elm = list.serializedProperty.GetArrayElementAtIndex(index);

                    rect.y += 2f;
                    if (ButtonPlay(new Rect(rect.width * 0.4f, rect.y, 30, EditorGUIUtility.singleLineHeight)))
                    {
                        Play(elm);
                    }
                    EditorGUI.ObjectField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight),
                                          elm.FindPropertyRelative("clip"));

                    rect.y += EditorGUIUtility.singleLineHeight + 2f;
                    float w = EditorGUI.Slider(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight),
                                               "Weight",
                                               elm.FindPropertyRelative("weight").floatValue,
                                               0f,
                                               1f);
                    elm.FindPropertyRelative("weight").floatValue = w;

                    float weightSum = AudioItemSet.ComputeWeightSum(serializedObject.targetObject as AudioItemSet);
                    serializedObject.FindProperty("weightSum").floatValue = weightSum;

                    rect.y += EditorGUIUtility.singleLineHeight + 2f;
                    Vector2 pr = elm.FindPropertyRelative("pitchRange").vector2Value;
                    EditorGUI.MinMaxSlider(new Rect(rect.x, rect.y, rect.width - 120f, EditorGUIUtility.singleLineHeight),
                                           "Pitch Range",
                                           ref pr.x,
                                           ref pr.y,
                                           -3f,
                                           3f);
                    pr.x = EditorGUI.FloatField(new Rect(rect.width - 90f, rect.y, 50f, EditorGUIUtility.singleLineHeight), pr.x);
                    pr.y = EditorGUI.FloatField(new Rect(rect.width - 30f, rect.y, 50f, EditorGUIUtility.singleLineHeight), pr.y);
                    elm.FindPropertyRelative("pitchRange").vector2Value = pr;
                },

                onAddCallback = rlist => {
                    int index = rlist.serializedProperty.arraySize;
                    rlist.serializedProperty.arraySize++;
                    rlist.index = index;
                    SerializedProperty audioItem = rlist.serializedProperty.GetArrayElementAtIndex(index);
                    audioItem.FindPropertyRelative("clip").objectReferenceValue = null;
                    audioItem.FindPropertyRelative("weight").floatValue         = AudioItem.GetDefaultWeight();
                    audioItem.FindPropertyRelative("pitchRange").vector2Value   = AudioItem.GetDefaultPitchRange();
                },

                onRemoveCallback = rlist => {
                    ReorderableList.defaultBehaviours.DoRemoveButton(rlist);
                    AudioItemSet.ComputeWeightSum(serializedObject.targetObject as AudioItemSet);
                },

                elementHeight = (EditorGUIUtility.singleLineHeight + 2) * 3f + 2
            };
        }
 private static void Play(AudioItem audioItem)
 {
     Play(audioItem.AudioClip, audioItem.PitchRange.x, audioItem.PitchRange.y);
 }