/// <summary> /// 播放音效 /// </summary> /// <param name="abName">音效的ab名字</param> /// <param name="loop">是否循环</param> /// <param name="isFade">是否淡化背景音乐</param> /// <returns> 返回音效id</returns> public void PlaySound(int id, bool loop = false, Action action = null, bool isFade = true) { if (CurrentSoundId >= 39 && CurrentSoundId <= 45) { return; } StopSound(); soundID++; var audioSource = gameObject.AddComponent <AudioSource>(); Debug.Log(GetDubbingName(id)[0] + "----" + GetDubbingName(id)[1]); AudioClip audioClip = ResourceManager.GetInstance.LoadAudioClip(GetDubbingName(id)[0], GetDubbingName(id)[1]); //动态添加音效 audioSource.clip = audioClip; audioSource.loop = loop; audioSource.volume = volume; audioSource.Play(); CurrentSoundId = id; SoundDictionary.Add(soundID, audioSource); if (isFade) { foreach (var item in SoundDictionary) { if (item.Key != soundID) { item.Value.DOFade(0.2f, 1f); } } CurrentMusic.DOFade(0.2f, 2); } StartCoroutine(PlaySoundEndDestroy(audioSource, soundID, action, isFade)); }
/// <summary> /// /// </summary> public Program() { Screen = Video.SetVideoMode(ScreenWidth, ScreenHeight); map = new MapDrawer(Screen); console = new BBConsole(Screen); gui = new BBUI(Screen, console); TextDrawer.Initialize(Screen); // Data loading // Sounds initialization SoundHandler soundHandler = new SoundHandler(); soundBox = soundHandler.initializeSounds(); Console.WriteLine("Sounds Loading "); musicBox = soundHandler.initializeMusics(); Console.WriteLine("Musics Loading"); //MusicBox["dtowne"].Play(); map.loadMap(MapPlayed); // Loading of the map Console.WriteLine("Map Loading"); Video.WindowIcon(); Video.WindowCaption = "BloodBox ! It roxes so much !"; this.AddHandlers(); Events.Run(); }
/// <summary> /// Similar to the regular Play method but can pass random pitch /// </summary> /// <param name="eventEnum"></param> /// <param name="minPitch"></param> /// <param name=""></param> public static void PlayRandomPitch(SoundEventEnum eventEnum, float minPitch, float floatMaxPitch) { //Find value in dictionary SoundDictionary dictionary = SoundReferences.Instance.soundDictionary; AudioClip sound = dictionary.references.Single(s => s.Key == eventEnum).Value; AudioManager.CreateTemporarySoundRandomPitch(sound); }
/// <summary> /// Play sound using AudioManager and SoundReferences dictionary /// </summary> /// <param name="eventEnum enum"></param> public static void Play(SoundEventEnum eventEnum) { //Find value in dictionary SoundDictionary dictionary = SoundReferences.Instance.soundDictionary; AudioClip sound = dictionary.references.Single(s => s.Key == eventEnum).Value; AudioManager.CreateTemporarySound(sound); }
/// <summary>This method initialize the sound dictionary</summary> /// <returns>Sounds dictionary</returns> public SoundDictionary initializeSounds() { // Start the dictionary SoundDictionary sounds = new SoundDictionary(); // Add the sounds // sounds.Add("dead", new Sound("sounds/dead.wav")); // sounds.Add("bhit", new Sound("sounds/bhit.wav")); // sounds.Add("fball", new Sound("sounds/fball.wav")); // sounds.Add("walk1", new Sound("sounds/walk1.wav")); return sounds; }
/// <summary> /// 停止音效的播放 /// </summary> /// <param name="soundID"></param> public void StopSound(int soundID = 0) { if (SoundDictionary.ContainsKey(soundID)) { Destroy(SoundDictionary[soundID]); SoundDictionary.Remove(soundID); } if (soundID == 0) { foreach (var source in SoundDictionary) { Destroy(source.Value); } SoundDictionary.Clear(); } CurrentSoundId = -1; }
public CwavBlock() { Sounds = new SoundDictionary { { CwavKind.Cursor, CwavFile.Empty() }, { CwavKind.Launch, CwavFile.Empty() }, { CwavKind.Folder, CwavFile.Empty() }, { CwavKind.Close, CwavFile.Empty() }, { CwavKind.Frame0, CwavFile.Empty() }, { CwavKind.Frame1, CwavFile.Empty() }, { CwavKind.Frame2, CwavFile.Empty() }, { CwavKind.OpenLid, CwavFile.Empty() }, }; Scanned = new List <CwavFile>(7); foreach (var pair in Sounds) { pair.Value.PropertyChanged += SoundEffectOnPropertyChanged; } }
public void Play(string name) { SoundData data; Console.WriteLine(string.Format("Try to play sound {0}.", name)); if (SoundDictionary.TryGetValue(name, out data)) { SoundEffectInstance sound = _soundEffects[data.Name]; if ((_currentSoundData.Priority <= data.Priority || _currentSound.State != SoundState.Playing) && sound.State != SoundState.Playing) { if (_currentSound != null) { _currentSound.Stop(); } _currentSoundData = data; _currentSound = sound; sound.Play(); } } }