예제 #1
0
파일: Tunneler.cs 프로젝트: VoidXH/Cavern
 /// <summary>
 /// Provides the <paramref name="source"/> a clip from either Cavern or Unity.
 /// </summary>
 public static void TunnelClips(ref Clip source, AudioClip unity, Clip cavern, ref int lastClipHash)
 {
     if (cavern)
     {
         if (!source || lastClipHash != cavern.GetHashCode())
         {
             source       = cavern;
             lastClipHash = cavern.GetHashCode();
         }
     }
     else if (unity)
     {
         if (!source || lastClipHash != unity.GetHashCode())
         {
             float[] AllData = new float[unity.channels * unity.samples];
             unity.GetData(AllData, 0);
             source       = new Clip(AllData, unity.channels, unity.frequency);
             lastClipHash = unity.GetHashCode();
         }
     }
     else if (source && lastClipHash != 0)
     {
         source       = null;
         lastClipHash = 0;
     }
 }
예제 #2
0
        public static void PlayVoice(AudioClip clip, bool loop     = false, System.Action onBeganCallback = null,
                                     System.Action onEndedCallback = null)
        {
            var audioMgr = AudioManager.Instance;

            audioMgr.CurrentVoiceName = "voice" + clip.GetHashCode();

            if (!Settings.IsVoiceOn.Value)
            {
                return;
            }


            VoicePlayer.SetOnStartListener(musicUnit =>
            {
                onBeganCallback.InvokeGracefully();

                VoicePlayer.SetOnStartListener(null);
            });

            VoicePlayer.SetAudioExt(AudioManager.Instance.gameObject, clip, audioMgr.CurrentVoiceName, loop);

            VoicePlayer.SetOnFinishListener(musicUnit =>
            {
                onEndedCallback.InvokeGracefully();

                VoicePlayer.SetOnFinishListener(null);
            });
        }
예제 #3
0
 public override int GetHashCode()
 {
     if (clip == null)
     {
         return(loop.GetHashCode());
     }
     return(clip.GetHashCode() ^ loop.GetHashCode());
 }
예제 #4
0
 public void Play(AudioClip clip, bool loop, float volume)
 {
     if (Target != null)
     {
         Code          = clip.GetHashCode();
         Target.clip   = clip;
         Target.loop   = loop;
         Target.volume = volume;
         Target.Play();
     }
 }
예제 #5
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Time.GetHashCode();
         hashCode = (hashCode * 397) ^ (Animation != null ? Animation.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Transition != null ? Transition.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Sound != null ? Sound.GetHashCode() : 0);
         return(hashCode);
     }
 }
예제 #6
0
        public bool IsCached(AudioClip audioclip)
        {
            return(this.SEClipsCache.Any(clip =>
            {
                if (clip == null || clip.SEClip == null)
                {
                    return false;
                }

                return clip.SEClip.GetHashCode() == audioclip.GetHashCode();
            }));
        }
예제 #7
0
    /// <summary>
    /// Plays a one-shot sound.
    /// Only allows one instance of the same sound to be played per frame.
    /// TODO: Allow customizeable volume stacking behavior when this happens.
    /// </summary>
    /// <returns>AudioSource used to play the sound, or null if no sound was played.</returns>
    /// <param name="audioClipPath">Audio clip to play.</param>
    public static AudioSource PlaySound(AudioClip clip, float volume = 1.0f)
    {
        Assert.IsNotNull(clip);
        if (clip == null)
        {
            return(null);
        }

        if (Instance.played.Contains(clip.GetHashCode()))
        {
            return(null);
        }
        Instance.played.Add(clip.GetHashCode());

        Instance.PurgeSources();
        AudioSource source = Instance.gameObject.AddComponent <AudioSource>();

        source.outputAudioMixerGroup = staticSfxMixerGroup;
        source.volume = volume;
        source.PlayOneShot(clip);
        return(source);
    }
예제 #8
0
        public static void PlayMusic(AudioClip clip, bool loop   = true, System.Action onBeganCallback = null,
                                     System.Action onEndCallback = null, bool allowMusicOff            = true, float volume = -1f)
        {
            var audioMgr = AudioManager.Instance;

            audioMgr.CurrentMusicName = "music" + clip.GetHashCode();

            if (!Settings.IsMusicOn.Value && allowMusicOff)
            {
                onBeganCallback.InvokeGracefully();
                onEndCallback.InvokeGracefully();
                return;
            }

            Log.I(">>>>>> Start Play Music");

            // TODO: 需要按照这个顺序去 之后查一下原因
            // 需要先注册事件,然后再play
            MusicPlayer.SetOnStartListener(musicUnit =>
            {
                onBeganCallback.InvokeGracefully();

                if (volume < 0)
                {
                    MusicPlayer.SetVolume(Settings.MusicVolume.Value);
                }
                else
                {
                    MusicPlayer.SetVolume(volume);
                }

                // 调用完就置为null,否则应用层每注册一个而没有注销,都会调用
                MusicPlayer.SetOnStartListener(null);
            });

            MusicPlayer.SetAudioExt(audioMgr.gameObject, clip, audioMgr.CurrentMusicName, loop);

            MusicPlayer.SetOnFinishListener(musicUnit =>
            {
                onEndCallback.InvokeGracefully();

                // 调用完就置为null,否则应用层每注册一个而没有注销,都会调用
                MusicPlayer.SetOnFinishListener(null);
            });
        }
예제 #9
0
        public AudioClip GetCachedClip(AudioClip audioclip)
        {
            IEnumerable <SE> _cachedSE = this.SEClipsCache.Where(clip =>
            {
                if (clip == null || clip.SEClip == null)
                {
                    return(false);
                }

                return(clip.SEClip.GetHashCode() == audioclip.GetHashCode());
            });

            if (_cachedSE == null || _cachedSE.Count() == 0)
            {
                return(null);
            }

            return(_cachedSE.First().SEClip);
        }
예제 #10
0
    public AudioSource PlaySound(AudioClip clip, float volume = 1.0f)
    {
        Assert.IsNotNull(clip);
        int clipHash = clip.GetHashCode();

        if (sources.ContainsKey(clipHash))
        {
            return(null);
        }

        PurgeSources();
        AudioSource source = gameObject.AddComponent <AudioSource>();

        sources.Add(clipHash, source);
        source.outputAudioMixerGroup = sfxMixerGroup;
        source.volume = volume;
        source.PlayOneShot(clip);
        return(source);
    }
예제 #11
0
    public void PlayMusic(string name, bool loop = true)
    {
        AudioClip clip = ResourceManager.LoadAudioClip("Sound", name);

        if (sourceMusic.isPlaying)
        {
            if (sourceMusic.clip.GetHashCode() == clip.GetHashCode())
            {
                return;
            }
        }

        sourceMusic.clip     = clip;
        sourceMusic.priority = 50;
        sourceMusic.loop     = loop;

        if (enableMusic)
        {
            sourceMusic.Play();
        }
    }
예제 #12
0
 public override int GetHashCode()
 {
     return((_intro == null ? 0 : 2 * _intro.GetHashCode()) + (_loop == null ? 0 : _loop.GetHashCode()));
 }
예제 #13
0
        public static AudioPlayer PlaySound(AudioClip clip, bool loop = false, Action <AudioPlayer> callBack = null,
                                            int customEventId         = -1)
        {
            if (!Settings.IsSoundOn.Value)
            {
                return(null);
            }

            var soundPlayer = SafeObjectPool <AudioPlayer> .Instance.Allocate();

            soundPlayer.SetAudioExt(AudioManager.Instance.gameObject, clip, "sound" + clip.GetHashCode(), loop);
            soundPlayer.SetVolume(Settings.SoundVolume.Value);
            soundPlayer.SetOnFinishListener(soundUnit =>
            {
                if (callBack != null)
                {
                    callBack(soundUnit);
                }

                AudioManager.Instance.RemoveSoundPlayerFromPool(soundPlayer);
            });

            soundPlayer.customEventID = customEventId;

            AudioManager.Instance.AddSoundPlayer2Pool(soundPlayer);
            return(soundPlayer);
        }
예제 #14
0
 public override int GetHashCode()
 {
     return((null == clip) ? 0 : clip.GetHashCode());
 }