예제 #1
0
    /// <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));
    }
예제 #2
0
        /// <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();
        }
예제 #3
0
    /// <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);
    }
예제 #4
0
    /// <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);
    }
예제 #5
0
        /// <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;
        }
예제 #6
0
 /// <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;
 }
예제 #7
0
        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;
            }
        }
예제 #8
0
        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();
                }
            }
        }