Exemplo n.º 1
0
 public void FadeIn(SoundId soundId, float fadeTime)
 {
     if (!IsPlaying(soundId))
     {
         Coroutine c = StartCoroutine(fadeInCoroutine(soundId, volumeSettingBySoundId[soundId], fadeTime));
     }
 }
Exemplo n.º 2
0
    public void PlayAtPosition(SoundId id, Vector2 pos)
    {
        float dist = Vector2.Distance(this.player.transform.position, pos);

        if (dist > this.spatialSoundsMaxDistance)
        {
            return;
        }

        Sound sound = this.sounds.Find(o => o.id == id);

        if (sound == null)
        {
            Debug.LogWarning("Couldn't find sound with id " + id.ToString());
            return;
        }

        sound.ApplyPitch(this.sfxSource);

        float t = (dist - this.spatialSoundsMinDistance) / (this.spatialSoundsMaxDistance - this.spatialSoundsMinDistance);

        t = Mathf.Clamp01(t);

        this.sfxSource.PlayOneShot(sound.clip, sound.volume * this.spatialSoundFalloffCurve.Evaluate(t));
    }
Exemplo n.º 3
0
 public void FadeOut(SoundId soundId, float fadeTime)
 {
     if (IsPlaying(soundId))
     {
         Coroutine c = StartCoroutine(fadeOutCoroutine(Guid.NewGuid(), soundId, volumeSettingBySoundId[soundId], fadeTime));
     }
 }
Exemplo n.º 4
0
        public override void Run(Combat.Character character)
        {
            SoundId?soundid             = EvaluationHelper.AsSoundId(character, SoundId, null);
            Int32   volume              = EvaluationHelper.AsInt32(character, Volume, 0);
            Int32   channelindex        = EvaluationHelper.AsInt32(character, ChannelNumber, -1);
            Boolean priority            = EvaluationHelper.AsBoolean(character, ChannelPriority, false);
            Single  frequencymultiplier = EvaluationHelper.AsSingle(character, FrequencyMultiplier, 1.0f);
            Boolean loop   = EvaluationHelper.AsBoolean(character, LoopSound, false);
            Int32?  pan    = EvaluationHelper.AsInt32(character, PanSound, null);
            Int32?  abspan = EvaluationHelper.AsInt32(character, PanSoundAbsolute, null);

            if (soundid == null)
            {
                return;
            }

            Audio.SoundManager soundmanager = SoundId.IsCommon(false) ? character.Engine.CommonSounds : character.SoundManager;

            Audio.Channel channel = soundmanager.Play(channelindex, soundid.Value, priority, volume, frequencymultiplier, loop);
            if (channel != null && pan != null)
            {
                channel.RelativePan(pan.Value);
            }
            if (channel != null && abspan != null)
            {
                channel.AbsolutePan(abspan.Value);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            base.LoadContent();

            _Player = new Player(this, _PlayerInitialPosition);
            _Camera = new Camera(this, ResolutionManager.VirtualWidth, ResolutionManager.VIRTUAL_HEIGHT, _CameraInitialPositionCenter);

            _Player.PlayerMoved += _Camera.UpdateCameraPosition;

            ObjectManager.AddObjects(_Scenery.ToArray());
            ObjectManager.AddObjects(_Player, _Camera);

            // A real game would probably have more content than this sample, so
            // it would take longer to load. We simulate that by delaying for a
            // while, giving you a chance to admire the beautiful loading screen.
            Thread.Sleep(1000);

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            CutlassEngine.Game.ResetElapsedTime();

            SoundId backgroundMusic = SoundManager.AddSound(new CutlassSong("Content/Sounds/Music/Constance"));

            SoundManager.GetSound(backgroundMusic).Play();
        }
    public void PlayPlayerJumpSfx()
    {
        SoundId id = SoundId.None;

        switch (this.materialZone)
        {
        case MaterialZone.Zone.Grass:
            id = SoundId.PlayerJumpGrass;
            break;

        case MaterialZone.Zone.Rock:
            id = SoundId.PlayerJumpRock;
            break;

        case MaterialZone.Zone.Wood:
            id = SoundId.PlayerJumpWood;
            break;

        default:
            return;
        }

        PlaySfx(id);
        FMODUnity.RuntimeManager.PlayOneShot(jump, transform.position);
    }
Exemplo n.º 7
0
            private static void LoadSoundFromBundle(GameObject gameObject, SoundId id, string path)
            {
                //Debug.LogError("LoadSoundFromBundle id= " + id.ToString());
                //Sounds[(int)id] = gameObject.AddComponent<AudioSource>();
                //Sounds[(int)id].clip = Resources.Load(path, typeof(AudioClip)) as AudioClip;

                //				asrc.clip = GlobalVariable.AssetBundleSound.clips[GlobalVariable.AssetBundleSound.ids.IndexOf(id)];


                if (soundHelper != null)
                {
                    if (soundHelper.MapSound.ContainsKey(id))
                    {
                        AudioSource asrc = gameObject.AddComponent <AudioSource>();
                        asrc.clip  = soundHelper.MapSound[id];
                        Sounds[id] = asrc;
                        //Debug.LogError("BUNDLE : " + asrc.clip.name);
                    }
                    else
                    {
                        Debug.LogError("NOT BUNDLE : " + id);
                    }
                }
                else
                {
                    Debug.LogError("SoundAssetBundleHelper.Instance nulllll");
                }
            }
    public void PlayPlayerStepSfx()
    {
        SoundId id = SoundId.None;

        switch (this.materialZone)
        {
        case MaterialZone.Zone.Grass:
            id         = SoundId.PlayerStepGrass;
            m_Material = 0;
            FMODUnity.RuntimeManager.StudioSystem.setParameterByID(Material_ID, m_Material);
            footstepsEv.start();
            break;

        case MaterialZone.Zone.Rock:
            id         = SoundId.PlayerStepRock;
            m_Material = 1;
            FMODUnity.RuntimeManager.StudioSystem.setParameterByID(Material_ID, m_Material);
            footstepsEv.start();
            break;

        case MaterialZone.Zone.Wood:
            id         = SoundId.PlayerStepWood;
            m_Material = 2;
            FMODUnity.RuntimeManager.StudioSystem.setParameterByID(Material_ID, m_Material);
            footstepsEv.start();
            break;

        default:
            return;
        }

        PlaySfx(id);
    }
Exemplo n.º 9
0
        public override void LoadContent()
        {
            base.LoadContent();

            _BackgroundMusic = SoundManager.AddSound(new CutlassSong("Content/Sounds/Music/TellerOfTheTales"));
            SoundManager.GetSound(_BackgroundMusic).PlayFadeIn(5000);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Plays the requested sound.
        /// </summary>
        /// <param name="channelindex">The non-negative channelnumber where the sound is to be played. -1 for any available channel.</param>
        /// <param name="id">The SoundId identifing the sound to be played.</param>
        /// <param name="lowpriority">If true and there is a currently playing sound on the same channel, the requested sound will not play.</param>
        /// <param name="volume">The volume level of the sound.</param>
        /// <param name="freqmul">The multiplier applied the sound to change its pitch. 1.0f for no change.</param>
        /// <param name="looping">Whether the sound should loop automatically until stopped.</param>
        /// <returns>The Channel where the sound is playing, if available. If the sound cannot be played, then null.</returns>
        public Channel Play(Int32 channelindex, SoundId id, bool lowpriority, int volume, float freqmul, bool looping)
        {
            if (channelindex < -1)
            {
                throw new ArgumentOutOfRangeException("channelindex");
            }
            if (id == SoundId.Invalid)
            {
                return(null);
            }

            byte[] sound = null;
            if (m_sounds.TryGetValue(id, out sound) == false)
            {
                return(null);
            }

            Channel channel = GetChannel(channelindex);

            if (channel == null || (channel.IsPlaying == true && lowpriority == true))
            {
                return(null);
            }

            volume += m_soundsystem.GlobalVolume;
            //volume = Misc.Clamp(volume, (Int32)Volume.Min, (Int32)Volume.Max);

            channel.Play(new ChannelId(this, channelindex), m_soundsystem.CloneBuffer(sound), freqmul, looping, volume);

            return(channel);
        }
Exemplo n.º 11
0
 public void UnPause(SoundId id)
 {
     if (activeSounds.ContainsKey(id))
     {
         activeSounds[id].UnPause();
     }
 }
Exemplo n.º 12
0
    /// <summary>
    /// newVolume is a float between 0 and 1
    /// </summary>
    /// <param name="newVolume"></param>
    public void SetVolume(SoundId soundId, float newVolume)
    {
        AudioSource audioSource = getAudioSource(soundId);

        audioSource.volume = newVolume;
        volumeSettingBySoundId[soundId] = newVolume;
    }
Exemplo n.º 13
0
 public void Stop(SoundId id)
 {
     if (activeSounds.ContainsKey(id))
     {
         activeSounds[id].Stop();
         activeSounds.Remove(id);
     }
 }
Exemplo n.º 14
0
    public void Stop(SoundId soundId)
    {
        AudioSource audioSource = getAudioSource(soundId);

        if (audioSource.isPlaying)
        {
            audioSource.Stop();
        }
    }
Exemplo n.º 15
0
        /// <summary>
        /// Determines whether the SoundManager contains a sound indentified by a given SoundId.
        /// </summary>
        /// <param name="id">the SoundId that indentifies a sound.</param>
        /// <returns>true is the SoundManager contains the requested sound; false otherwise.</returns>
        public Boolean ContainsSound(SoundId id)
        {
            if (id == SoundId.Invalid)
            {
                return(false);
            }

            return(m_sounds.ContainsKey(id));
        }
Exemplo n.º 16
0
    public float GetSoundLength(SoundId id)
    {
        if (sounds.ContainsKey(id))
        {
            return(sounds[id].clip.length);
        }

        //Return 0 if not found -- should not happen
        return(0f);
    }
Exemplo n.º 17
0
 public static void PauseSound(SoundId soundId)
 {
     try {
         if (soundId != null && Sounds[soundId] != null)
         {
             Sounds[soundId].Pause();
         }
     } catch (Exception exception) {
         Debug.LogError("PauseSound error: " + exception.Message);
     }
 }
Exemplo n.º 18
0
            public static void ChangeBackgroundSound(SoundId bgsoundid)
            {
                return;

                StopBackgroundSound();
                AutoPlayLoopSounds[0] = bgsoundid;
                if (ENABLE_BGSOUND)
                {
                    PlayLoopSound(AutoPlayLoopSounds[0]);
                }
            }
Exemplo n.º 19
0
            private static void LoadSound(GameObject gameObject, SoundId id, string path)
            {
                //Sounds[(int)id] = gameObject.AddComponent<AudioSource>();
                //Sounds[(int)id].clip = Resources.Load(path, typeof(AudioClip)) as AudioClip;

                AudioSource asrc = gameObject.AddComponent <AudioSource>();

                asrc.clip = Resources.Load(path, typeof(AudioClip)) as AudioClip;

                Sounds[id] = asrc;
            }
Exemplo n.º 20
0
		public SoundFileSubHeader(File file)
		{
			if (file == null) throw new ArgumentNullException("file");

			Byte[] data = file.ReadBytes(16);
			if (data.Length != 16) throw new ArgumentException("File is not long enough", "file");

			m_nextoffset = BitConverter.ToInt32(data, 0);
			m_length = BitConverter.ToInt32(data, 4);
			m_id = new SoundId(BitConverter.ToInt32(data, 8), BitConverter.ToInt32(data, 12));
		}
        public static void SetOnClickWithSound(this Button button, Action action, SoundId id = SoundId.ClickSound)
        {
            if (!button)
            {
                return;
            }

            button.SetOnClick(action);

            button.onClick.AddListener(() => { id.Play2D(); });
        }
Exemplo n.º 22
0
        public override void Run(Combat.Character character)
        {
            int?time       = EvaluationHelper.AsInt32(character, Time, 30);
            var buffertime = EvaluationHelper.AsInt32(character, EndCommandBufferTime, 0);
            var movetime   = EvaluationHelper.AsInt32(character, MoveTime, 0);
            var pausebg    = EvaluationHelper.AsBoolean(character, PauseBackgrounds, true);
            var power      = EvaluationHelper.AsInt32(character, PowerAdd, 0);

#warning Documentation states that default should be 30. Testing looks to be 100.
            var animationnumber = EvaluationHelper.AsInt32(character, AnimationNumber, 100);

            var soundid           = EvaluationHelper.AsSoundId(character, SoundId, null);
            var animationposition = EvaluationHelper.AsPoint(character, AnimationPosition, new Point(0, 0));
            var darkenscreen      = EvaluationHelper.AsBoolean(character, DarkenScreen, true);
            var p2defmul          = EvaluationHelper.AsSingle(character, P2DefenseMultiplier, null);
            var unhittable        = EvaluationHelper.AsBoolean(character, Unhittable, true);

            if (time == null)
            {
                return;
            }

            var pause = character.Engine.SuperPause;
            pause.Set(character, time.Value, buffertime, movetime, false, pausebg);

            character.BasePlayer.Power += power;

            var data = new Combat.ExplodData();
            data.PositionType    = PositionType.P1;
            data.Location        = (Vector2)animationposition;
            data.RemoveTime      = -2;
            data.CommonAnimation = EvaluationHelper.IsCommon(AnimationNumber, true);
            data.AnimationNumber = animationnumber;
            data.Scale           = Vector2.One;
            data.SuperMove       = true;
            data.Creator         = character;
            data.Offseter        = character;
            data.DrawOnTop       = true;

            var explod = new Combat.Explod(character.Engine, data);
            if (explod.IsValid)
            {
                explod.Engine.Entities.Add(explod);
            }

            if (soundid != null)
            {
                Audio.SoundManager soundmanager = SoundId.IsCommon(true) ? character.Engine.CommonSounds : character.SoundManager;
                soundmanager.Play(soundid.Value);
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// play 1 sound trong khoang thoi gian duration, goi ngoai mainthread
 /// </summary>
 /// <param name="soundId">tham so sound co the sua tuy theo api</param>
 /// <param name="duration">tham so thoi gian co the sua tuy vao api</param>
 public static void PlaySound(SoundId soundId)
 {
     //LogMng.Log("Sound", "PlaySound " + soundId + ", " + ENABLE);
     try {
         if (ENABLE && soundId != null && Sounds[soundId] != null)
         {
             //play sound
             Sounds[soundId].loop = false;
             Sounds[soundId].Play();
         }
     } catch (Exception exception) {
         Debug.LogError("PlaySound error: " + exception.Message);
     }
 }
    public void PlaySound(SoundId id)
    {
        List <SoundObject> ss = sounds.FindAll(x => x.soundId == id && !x.gameObject.activeSelf);

        if (ss != null && ss.Count > 0)
        {
            SoundObject s = ss[UnityEngine.Random.Range(0, ss.Count - 1)];

            if (s != null)
            {
                s.gameObject.SetActive(true);
            }
        }
    }
Exemplo n.º 25
0
    public void PlaySfx(SoundId id)
    {
        Sound sound = this.sounds.Find(o => o.id == id);

        if (sound == null)
        {
            Debug.LogWarning("Couldn't find sound with id " + id.ToString());
            return;
        }

        sound.ApplyPitch(this.sfxSource);

        this.sfxSource.PlayOneShot(sound.clip, sound.volume);
    }
Exemplo n.º 26
0
    public IEnumerator fadeOutCoroutine(Guid coroutineKey, SoundId soundId, float normalVolume, float FadeTime)
    {
        AudioSource audioSource = getAudioSource(soundId);

        while (audioSource.volume > 0)
        {
            audioSource.volume -= normalVolume * Time.deltaTime / FadeTime;

            yield return(null);
        }

        audioSource.Stop();
        audioSource.volume = normalVolume;
    }
Exemplo n.º 27
0
        void PlaySound(Character attacker, Character target, SoundId soundid, Boolean playersound)
        {
            if (attacker == null)
            {
                throw new ArgumentNullException("attacker");
            }
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            Audio.SoundManager snd = (playersound == true) ? attacker.SoundManager : attacker.Engine.CommonSounds;
            snd.Play(-1, soundid, false, 0, 1.0f, false);
        }
Exemplo n.º 28
0
    public void Play(SoundId soundId, bool restart = false)
    {
        AudioSource audioSource = getAudioSource(soundId);

        if (audioSource.isPlaying && restart)
        {
            audioSource.Stop();
        }

        if (!audioSource.isPlaying)
        {
            audioSource.Play();
        }
    }
Exemplo n.º 29
0
    public void PlaySound(SoundId id, bool isLoop = false, long delay = 0)
    {
        int soundId = (int)id;

        if (soundId < 0 || soundId >= soundList.Length)
        {
            return;
        }
        if (audioSourceSound != null)
        {
            audioSourceSound.clip = soundList[soundId].audoClip;
            audioSourceSound.loop = isLoop;
            audioSourceSound.Play((ulong)delay);
        }
    }
    public void StopMusic(SoundId id)
    {
        SoundObject s = sounds.Find(x => x.soundId == id);

        if (currentMusic != null)
        {
            currentMusic.SetActive(false);
        }

        if (s != null)
        {
            s.gameObject.SetActive(false);
            currentMusic = s.gameObject;
        }
    }
Exemplo n.º 31
0
            public static void PlayLoopSound(SoundId soundId)
            {
                try {
                    //LogMng.Log("Sound", "PlayLoopSound " + soundId + ", " + ENABLE_BGSOUND);
                    if (ENABLE_BGSOUND && soundId != null && Sounds[soundId] != null)
                    {
                        //play sound

                        Sounds[soundId].loop = true;
                        Sounds[soundId].Play();
                    }
                } catch (Exception exception) {
                    Debug.LogError("PlayLoopSound error: " + exception.Message);
                }
            }
Exemplo n.º 32
0
		void PlaySound(Character attacker, Character target, SoundId soundid, Boolean playersound)
		{
			if (attacker == null) throw new ArgumentNullException("attacker");
			if (target == null) throw new ArgumentNullException("target");

			Audio.SoundManager snd = (playersound == true) ? attacker.SoundManager : attacker.Engine.CommonSounds;
			snd.Play(-1, soundid, false, 0, 1.0f, false);
		}
Exemplo n.º 33
0
		/// <summary>
		/// Plays the requested sound.
		/// </summary>
		/// <param name="id">The SoundId identifing the sound to be played.</param>
		/// <returns>The Channel where the sound is playing, if available. If the sound cannot be played, then null.</returns>
		public Channel Play(SoundId id)
		{
			return Play(-1, id, false, 0, 1, false);
		}
Exemplo n.º 34
0
		/// <summary>
		/// Determines whether the SoundManager contains a sound indentified by a given SoundId.
		/// </summary>
		/// <param name="id">the SoundId that indentifies a sound.</param>
		/// <returns>true is the SoundManager contains the requested sound; false otherwise.</returns>
		public Boolean ContainsSound(SoundId id)
		{
			if (id == SoundId.Invalid) return false;

			return m_sounds.ContainsKey(id);
		}
Exemplo n.º 35
0
		/// <summary>
		/// Plays the requested sound.
		/// </summary>
		/// <param name="channelindex">The non-negative channelnumber where the sound is to be played. -1 for any available channel.</param>
		/// <param name="id">The SoundId identifing the sound to be played.</param>
		/// <param name="lowpriority">If true and there is a currently playing sound on the same channel, the requested sound will not play.</param>
		/// <param name="volume">The volume level of the sound.</param>
		/// <param name="freqmul">The multiplier applied the sound to change its pitch. 1.0f for no change.</param>
		/// <param name="looping">Whether the sound should loop automatically until stopped.</param>
		/// <returns>The Channel where the sound is playing, if available. If the sound cannot be played, then null.</returns>
		public Channel Play(Int32 channelindex, SoundId id, Boolean lowpriority, Int32 volume, Single freqmul, Boolean looping)
		{
			if (channelindex < -1) throw new ArgumentOutOfRangeException("channelindex");
			if (id == SoundId.Invalid) return null;

			SecondaryBuffer sound = null;
			if (m_sounds.TryGetValue(id, out sound) == false) return null;

			Channel channel = GetChannel(channelindex);
			if (channel == null || (channel.IsPlaying == true && lowpriority == true)) return null;

			volume += m_soundsystem.GlobalVolume;
			volume = Misc.Clamp(volume, (Int32)Volume.Min, (Int32)Volume.Max);

			channel.Play(new ChannelId(this, channelindex), m_soundsystem.CloneBuffer(sound), freqmul, looping, volume);

			return channel;
		}
Exemplo n.º 36
0
		public static SoundId AsSoundId(Object state, IExpression expression, SoundId failover)
		{
			if (expression == null || expression.IsValid == false) return failover;

			Number[] result = expression.Evaluate(state);

			if (result.Length > 0 && result[0].NumberType != NumberType.None)
			{
				if (result.Length > 1 && result[1].NumberType != NumberType.None)
				{
					return new SoundId(result[0].IntValue, result[1].IntValue);
				}
				else
				{
					return new SoundId(result[0].IntValue, 0);
				}
			}

			return failover;
		}