示例#1
0
    public void LimitVoices()
    {
        if (activeVoices.Count > maxVoices)
        {
            RemoveInactiveSources(activeVoices);
        }

        while (activeVoices.Count > maxVoices)
        {
            for (int i = 0; i < activeVoices.Count; i++)
            {
                if (activeVoices[i] != null)
                {
                    if (activeVoices[i].clip != null)
                    {
                        AudioInfoOld audioInfo   = AudioPlayerOld.AudioInfos[activeVoices[i].clip.name];
                        float        initFadeOut = audioInfo.fadeOut;
                        audioInfo.fadeOut = 0.1F;
                        Sampler.Stop(activeVoices[0]);
                        audioInfo.fadeOut = initFadeOut;
                        activeVoices.RemoveAt(i);
                        break;
                    }
                }
            }
        }
    }
示例#2
0
    public static AudioSource Play(string instrumentName, int midiNote, float velocity, GameObject sourceObject = null, float delay = 0, AudioPlayerOld.SyncMode syncMode = AudioPlayerOld.SyncMode.None)
    {
        AudioSource  audioSource;
        Instrument   instrument = Instruments[instrumentName];
        AudioInfoOld audioInfo  = AudioPlayerOld.AudioInfos[instrument.referenceClips[midiNote].name];
        AudioClip    audioClip  = null;
        float        initVolume = audioInfo.volume;

        midiNote = GetAdjustedNote(midiNote, velocity, instrument);

        if (!string.IsNullOrEmpty(instrument.originalClips[midiNote]))
        {
            audioClip = instrument.audioClips[midiNote];
        }
        else
        {
            if (instrument.generateMode == Instrument.GenerateModes.None || instrument.generateMode == Instrument.GenerateModes.PreGenerateAll)
            {
                audioClip = instrument.audioClips[midiNote];
            }
            else
            if (instrument.generateMode == Instrument.GenerateModes.GenerateAtRuntime)
            {
                if (instrument.audioClips[midiNote] != null)
                {
                    audioClip = instrument.audioClips[midiNote];
                }

                if (audioClip == null)
                {
                    audioClip = CreateAudioClip(instrument, midiNote);
                }

                if (!audioInfo.loop && instrument.destroyIdle)
                {
                    Instance.coroutineHolder.RemoveCoroutines(instrumentName + midiNote);
                    Instance.coroutineHolder.AddCoroutine(instrumentName + midiNote, RemoveAfterDelay(audioClip, instrument.idleThreshold, (float)(AudioPlayerOld.GetAdjustedDelay(audioInfo.delay, audioInfo.syncMode) + AudioPlayerOld.GetAdjustedDelay(delay, syncMode))));
                }
            }
        }

        if (instrument.velocityAffectsVolume)
        {
            audioInfo.volume *= instrument.velocityCurve.Evaluate(velocity / 127);
        }

        audioSource = AudioPlayerOld.Play(audioClip, audioInfo, sourceObject, delay, syncMode);
        if (instrument.sendToPD)
        {
            audioSource.gameObject.GetOrAddComponent <AudioGainManager>().Initialize(instrument.name + "~");
        }
        instrument.activeVoices.Add(audioSource);

        audioInfo.volume = initVolume;
        return(audioSource);
    }
示例#3
0
    public override void OnInspectorGUI()
    {
        audioInfo = (AudioInfoOld)target;
        if (!audioInfo.init)
        {
            audioInfo.Start();
        }
        else
        {
            Update();
        }

        Begin();

        EditorGUILayout.Space();
        EditorGUILayout.PropertyField(serializedObject.FindProperty("fadeIn"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("fadeInCurve"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("fadeOut"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("fadeOutCurve"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("randomVolume"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("randomPitch"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("delay"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("syncMode"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("doNotKill"));
        if (PDPlayerOld.Instance != null)
        {
            EditorGUILayout.PropertyField(serializedObject.FindProperty("sendToPD"));
        }
        else
        {
            serializedObject.FindProperty("sendToPD").boolValue = false;
        }
        EditorGUILayout.PropertyField(serializedObject.FindProperty("effects"), true);
        ShowRTPCs();
        ShowBuses();
        EditorGUILayout.PropertyField(serializedObject.FindProperty("clipInfo"), true);

        End();
    }