コード例 #1
0
 /*
  * -----------------------
  * BlendWithCurrentSnapshot()
  * -----------------------
  */
 public static void BlendWithCurrentSnapshot(MixerSnapshot blendSnapshot, float weight, float blendTime = 0.0f)
 {
     if (theAudioManager != null)
     {
         if (theAudioManager.audioMixer == null)
         {
             Debug.LogWarning("[AudioManager] can't call BlendWithCurrentSnapshot if the audio mixer is not set!");
             return;
         }
         if (blendTime == 0.0f)
         {
             blendTime = Time.deltaTime;
         }
         if ((theAudioManager.currentSnapshot != null) && (theAudioManager.currentSnapshot.snapshot != null))
         {
             if ((blendSnapshot != null) && (blendSnapshot.snapshot != null))
             {
                 weight = Mathf.Clamp01(weight);
                 if (weight == 0.0f)
                 {
                     // revert to the default snapshot
                     theAudioManager.currentSnapshot.snapshot.TransitionTo(blendTime);
                 }
                 else
                 {
                     AudioMixerSnapshot[] snapshots = new AudioMixerSnapshot[] { theAudioManager.currentSnapshot.snapshot, blendSnapshot.snapshot };
                     float[] weights = new float[] { 1.0f - weight, weight };
                     theAudioManager.audioMixer.TransitionToSnapshots(snapshots, weights, blendTime);
                 }
             }
         }
     }
 }
コード例 #2
0
        /*
         * -----------------------
         * SetCurrentSnapshot()
         * -----------------------
         */
        public static void SetCurrentSnapshot(MixerSnapshot mixerSnapshot)
        {
#if UNITY_EDITOR
            if (mixerSnapshot == null || mixerSnapshot.snapshot == null)
            {
                Debug.LogError("[AudioManager] ERROR setting empty mixer snapshot!");
            }
            else
            {
                Debug.Log("[AudioManager] Setting audio mixer snapshot: " + ((mixerSnapshot != null && mixerSnapshot.snapshot != null) ? mixerSnapshot.snapshot.name : "None") + " Time: " + Time.time);
            }
#endif
            if (theAudioManager != null)
            {
                if ((mixerSnapshot != null) && (mixerSnapshot.snapshot != null))
                {
                    mixerSnapshot.snapshot.TransitionTo(mixerSnapshot.transitionTime);
                }
                else
                {
                    mixerSnapshot = null;
                }
                theAudioManager.currentSnapshot = mixerSnapshot;
            }
        }