Пример #1
0
 protected void PauseMusicControl(AudioAsset au, bool isPause, float fadeTime = 0.5f)
 {
     if (isPause)
     {
         //Debug.Log("PauseMusicControl Pause : "+ au.PlayState);
         if (au.PlayState == AudioPlayState.Playing)
         {
             au.SetPlayState(AudioPlayState.Pause);
             //Debug.Log("PauseMusicControl Pause");
             AddFade(au, VolumeFadeType.FadeOut, fadeTime, 0, (value) =>
             {
                 //Debug.LogWarning("PauseMusicControl Pause fade CallBack");
                 value.Pause();
             }, null);
         }
     }
     else
     {
         //Debug.Log("PauseMusicControl play : "+ au.PlayState);
         if (au.PlayState == AudioPlayState.Pause)
         {
             au.Play();
             AddFade(au, VolumeFadeType.FadeIn, fadeTime, 0, null, null);
         }
     }
 }
Пример #2
0
    public IEnumerator EaseToChangeVolume(AudioAsset au, string name, bool isLoop, float volumeScale, float delay, float fadeTime)
    {
        AudioClip ac        = GetAudioClip(name);
        float     oldVolume = au.Volume;
        float     target    = au.Volume;

        if (au.audioSource && au.IsPlay)
        {
            while (target > 0f)
            {
                float speed = oldVolume / fadeTime;
                target    = target - speed * Time.fixedDeltaTime;
                au.Volume = target;
                yield return(new WaitForFixedUpdate());
            }
            au.Stop();
        }
        au.assetName        = name;
        au.audioSource.clip = ac;
        au.audioSource.loop = isLoop;
        au.Play(delay);
        target = 0;
        yield return(new WaitForSeconds(delay));

        while (target < oldVolume)
        {
            float speed = oldVolume / fadeTime * 1.2f;
            target    = target + speed * Time.fixedDeltaTime;
            au.Volume = target;
            yield return(new WaitForFixedUpdate());
        }
        au.VolumeScale = volumeScale;
    }
Пример #3
0
 protected void PlayMusicControl(AudioAsset au, string audioName, bool isLoop = true, float volumeScale = 1, float delay = 0f, float fadeTime = 0.5f, string flag = "")
 {
     au.flag = flag;
     if (au.assetName == audioName)
     {
         if (au.PlayState != AudioPlayState.Playing)
         {
             AddFade(au, VolumeFadeType.FadeIn, fadeTime, delay, null, null);
             au.Play();
         }
     }
     else
     {
         if (au.PlayState == AudioPlayState.Playing)
         {
             AddFade(au, VolumeFadeType.FadeOut2In, fadeTime, delay, null, (value) =>
             {
                 PlayClip(value, audioName, isLoop, volumeScale, delay);
             });
         }
         else
         {
             PlayClip(au, audioName, isLoop, volumeScale, delay);
             AddFade(au, VolumeFadeType.FadeIn, fadeTime, delay, null, null);
         }
     }
 }
Пример #4
0
    public void PlaySFX(string name, float volumeScale = 1f, float delay = 0f)
    {
        AudioClip  ac = GetAudioClip(name);
        AudioAsset aa = GetEmptyAudioAssetFromSFXList();

        aa.audioSource.clip = ac;
        aa.Play(delay);
        aa.VolumeScale = volumeScale;
    }
Пример #5
0
    protected void PlayClip(AudioAsset au, string audioName, bool isLoop = true, float volumeScale = 1, float delay = 0f)
    {
        au.assetName = audioName;
        AudioClip ac = GetAudioClip(au.assetName);

        au.audioSource.clip = ac;
        au.audioSource.loop = isLoop;
        au.Play(delay);
        au.VolumeScale = volumeScale;
    }
Пример #6
0
    public void PlaySFX(GameObject owner, string name, float volumeScale = 1f, float delay = 0f)
    {
        AudioClip  ac = GetAudioClip(name);
        AudioAsset aa = GetEmptyAudioAssetFromSFXList(owner);

        aa.audioSource.clip = ac;
        aa.assetName        = name;
        aa.Play(delay);
        aa.VolumeScale = volumeScale;
        ClearMoreAudioAsset(owner);
    }
Пример #7
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(Clips, true);
        if (EditorGUI.EndChangeCheck())
        {
            MatchWeightsWithClips();
        }

        EditorGUILayout.PropertyField(Priority);
        EditorGUILayout.PropertyField(Looping);

        EditorGUILayout.PropertyField(PlayMode);

        if (asset.PlayMode == PlaylistMode.WeightedRandom)
        {
            EditorGUILayout.PropertyField(Weights, true);
        }

        EditorGUILayout.PropertyField(PitchBase);
        EditorGUILayout.PropertyField(PitchOffset);
        EditorGUILayout.PropertyField(VolumeBase);
        EditorGUILayout.PropertyField(VolumeOffset);

        EditorGUILayout.PropertyField(FadeTimeIn);
        EditorGUILayout.PropertyField(FadeTypeIn);
        EditorGUILayout.PropertyField(FadeTimeOut);
        EditorGUILayout.PropertyField(FadeTypeOut);

        EditorGUILayout.PropertyField(Attenuation);
        EditorGUILayout.PropertyField(MinimumDistance);
        EditorGUILayout.PropertyField(MaximumDistance);

        serializedObject.ApplyModifiedProperties();

        if (GUILayout.Button("Play"))
        {
            _inspectorVoice = asset.Play();
        }
        if (_inspectorVoice == null)
        {
            GUI.enabled = false;
        }
        if (GUILayout.Button("Stop"))
        {
            AudioPlayer.Instance.Stop(_inspectorVoice);
        }
        GUI.enabled = true;
    }
Пример #8
0
    protected void PlayClip(AudioAsset au, string audioName, bool isLoop = true, float volumeScale = 1, float delay = 0f, float pitch = 1)
    {
        //if (au.PlayState == AudioPlayState.Playing)
        //    au.Stop();
        UnloadClip(au);
        au.assetName = audioName;
        AudioClip ac = GetAudioClip(au.assetName);

        au.audioSource.clip  = ac;
        au.audioSource.loop  = isLoop;
        au.audioSource.pitch = pitch;
        au.VolumeScale       = volumeScale;
        au.Play(delay);
    }
Пример #9
0
    private void LateUpdate()
    {
        if (playNonFilling == false)
        {
            return;
        }
        playNonFilling = false;

        AudioAsset asset = CreateAsset(fillWithLowPriority ? high : low);

        asset.Play();

        Debug.LogWarning("calling Debug.Break() to evaluate profiler manually");
    }
Пример #10
0
    //Use all available sources in the pool by filling them with either high or low priority sounds
    //Then use the playNonFilling to attempt to add the other type
    //This tests that high-priority voices can appropriately steal sources from low priorities
    //and that low-priority voices cannot steal from a source with high priority
    //(Note that 'high priority' refers to lower priority numbers)

    private void Awake()
    {
        new GameObject("sound").AddComponent <AudioPlayer>();

        AudioAsset asset = CreateAsset(fillWithLowPriority ? low : high);

        asset.Looping    = true;
        asset.VolumeBase = AudioUtil.DecibelToVolumeFactor(-50);

        for (int i = 0; i < AudioSettings.GetConfiguration().numRealVoices; i++)
        {
            asset.Play();
        }
    }
Пример #11
0
    protected void PlayClip(AudioAsset au, string audioName, bool isLoop = true, float volumeScale = 1, float delay = 0f, float pitch = 1)
    {
        if (!ResourcesConfigManager.GetIsExitRes(audioName))
        {
            Debug.LogError("不存在音频:" + audioName);
            return;
        }
        //if (au.PlayState == AudioPlayState.Playing)
        //    au.Stop();
        UnloadClip(au);
        au.assetName = audioName;
        AudioClip ac = GetAudioClip(au.assetName);

        au.audioSource.clip  = ac;
        au.audioSource.loop  = isLoop;
        au.audioSource.pitch = pitch;
        au.VolumeScale       = volumeScale;
        au.Play(delay);
    }