Example #1
0
    public void PlaySoundEffect(SoundDefinition sound, Vector2 pos)
    {
        var newSoundEffect = soundEffectPool.InitNewObject();

        newSoundEffect.transform.position = pos;
        newSoundEffect.GetComponent <SoundEffect>().PlaySoundDefinition(sound);
    }
Example #2
0
        void Endstand()
        {
            if (ActiveStand == null)
            {
                return;
            }

            if (StandSFXLoop != null)
            {
                SoundHandler.StopSound(StandSFXLoop);
            }

            var stand = ActiveStand;

            if (HordeMode.IsActive)
            {
                if (!string.IsNullOrWhiteSpace(stand.SFXStop))
                {
                    var def = new SoundDefinition(stand.SFXStop);
                    if (stand.GlobalSFX)
                    {
                        SoundHandler.PlaySound(def, 1.0f);
                    }
                    else
                    {
                        SoundHandler.PlaySound3D(def, stand.Position, 5000 + stand.Range, 1.0f);
                    }
                }
            }
            ActiveStand = null;
            messageTimer.Stop();
        }
Example #3
0
        public void Update()
        {
            double t = 0;

            foreach (var song in currentlyPlaying)
            {
                AudioSource aSource = song.Key;
                if (song.Value.doesLoop)
                {
                    SoundDefinition musicDefinition = song.Value;
                    t = (double)aSource.timeSamples / (double)aSource.clip.frequency;
                    if (t >= musicDefinition.loopPoint)
                    {
                        aSource.Play();
                        aSource.timeSamples = (int)(musicDefinition.loopBackTo * ((double)aSource.clip.frequency));
                    }
                }
                else
                {
                    if (aSource.time > aSource.clip.length)
                    {
                        Stop(aSource);
                    }
                }
            }
        }
Example #4
0
 void PlaySound(SoundDefinition snd)
 {
     if (sndEnabled)
     {
         SoundHandler.PlaySound(snd, 1.5f);
     }
 }
Example #5
0
        /// <summary>
        /// Called whenever a hitbox hits a hurtbox successfully.
        /// </summary>
        /// <param name="hurtableHit">The hurtable that was hit.</param>
        /// <param name="hitInfo">The hitInfo of the hitbox.</param>
        /// <param name="hitboxID">The hitbox ID of the hitbox.</param>
        protected override void OnHitboxHurt(GameObject hurtableHit, HitInfoBase hitInfo, int hitboxID, int hitboxGroup)
        {
            SoundDefinition sd = ((EntityManager)combatManager.manager).GameManager.ModManager
                                 .GetSoundDefinition(
                ((Combat.BoxGroup)combatManager.CurrentAttack.attackDefinition.boxGroups[hitboxGroup]).hitSound?.reference);

            SoundManager.Play(sd, 0, manager.transform);
            ((EntityManager)manager).power += ((Combat.HitInfo)hitInfo).attackerPowerGainOnHit;
            base.OnHitboxHurt(hurtableHit, hitInfo, hitboxID, hitboxGroup);
        }
Example #6
0
 public bool IsPlaying(SoundDefinition music)
 {
     foreach (AudioSource audio in currentlyPlaying.Keys)
     {
         if (currentlyPlaying[audio] == music)
         {
             return(true);
         }
     }
     return(false);
 }
        public override bool Evaluate(uint frame, uint endFrame,
                                      CAF.Entities.EntityManager controller, AttackEventVariables variables)
        {
            TUF.Entities.EntityManager c     = (TUF.Entities.EntityManager)controller;
            SoundDefinition            sound = c.GameManager.ModManager.GetSoundDefinition(((ModObjectLink)variables.objectVars[0]).reference);

            if (sound)
            {
                SoundManager.Play(sound, 0, controller.transform);
            }
            return(false);
        }
Example #8
0
        public AudioSource Play(SoundDefinition song, float startTime = 0)
        {
            AudioSource aSource = gameObject.AddComponent <AudioSource>();

            aSource.clip   = song.sound;
            aSource.volume = song.volume;
            aSource.loop   = song.doesLoop;
            aSource.outputAudioMixerGroup = song.mixerGroup;
            aSource.time = startTime;
            aSource.Play();
            currentlyPlaying.Add(aSource, song);
            return(aSource);
        }
Example #9
0
        public SamplePlayer(SoundDefinition soundDefinition)
        {
            this.source  = soundDefinition.SoundData;
            this.balance = soundDefinition.Balance;
            this.gain    = soundDefinition.Gain;
            this.index   = 0f;
            this.State   = SampleProviderState.Playing;
            this.Pitch   = soundDefinition.Pitch;
            this.Loop    = soundDefinition.Loop;

            // Compute left/right gain.
            ComputeGain();
        }
Example #10
0
 private void OnPlayEnded(AudioSource source)
 {
     playingSources.Remove(source);
     source.name = AvailableName;
     source.Stop();
     source.clip = null;
     AddSingleSource(ref source, ref availableSources);
     if (awaitingSlots.Count > 0)
     {
         SoundDefinition definition = awaitingSlots[0];
         awaitingSlots.Remove(definition);
         PlaySound(definition.clip, definition.identifier, false);
     }
 }
Example #11
0
    //Used to play sound clips with various settings
    public void PlaySound(SoundDefinition sound, Vector2 pos)
    {
        if (sound == null)
        {
            return;
        }

        if (_currentSoundEffectsContainer == null)
        {
            SetCurrentSoundEffectsContainer();
        }

        _currentSoundEffectsContainer.PlaySoundEffect(sound, pos);
    }
Example #12
0
        public void StartOutgame()
        {
            var theme = new SoundDefinition("INSTALLER_LOOP.WAV");

            theme.zSFX.IsFixed = true;
            theme.zSFX.Volume  = 0.5f;
            theme.zSFX.SetLooping(true);
            menuTheme = SoundHandler.PlaySound(theme, 0.5f);

            Arena.Menus.MainMenu.Menu.Open();

            OnOutgame?.Invoke();
            Logger.Log("Outgame started.");
        }
Example #13
0
    // Use this for initialization
    void Start()
    {
        var    serializer = new XmlSerializer(typeof(WeaponContainer));
        string path       = Application.dataPath + "/Resources/Definitions/Definitions.xml";
        var    stream     = new FileStream(path, FileMode.Open);

        container = serializer.Deserialize(stream) as WeaponContainer;

        Debug.Log("Loaded " + container.Weapons.Count.ToString() + " weapon definitions.");

        foreach (WeaponDefinition wd in container.Weapons)
        {
            Debug.Log(wd.ToString());
        }

        stream.Close();


        serializer = new XmlSerializer(typeof(BonusContainer));
        path       = Application.dataPath + "/Resources/Definitions/Definitions.xml";
        stream     = new FileStream(path, FileMode.Open);

        bonusContainer = serializer.Deserialize(stream) as BonusContainer;

        Debug.Log("Loaded " + bonusContainer.Bonuses.Count.ToString() + " bonuses.");

        foreach (BonusDefinition wd in bonusContainer.Bonuses)
        {
            Debug.Log(wd.ToString());
        }

        stream.Close();

        serializer = new XmlSerializer(typeof(SoundContainer));
        path       = Application.dataPath + "/Resources/Definitions/Definitions.xml";
        stream     = new FileStream(path, FileMode.Open);

        sounds = serializer.Deserialize(stream) as SoundContainer;

        Debug.Log("Loaded " + sounds.Sounds.Count.ToString() + " sounds");

        SoundDefinition sd = sounds.Sounds[1];

        Debug.Log("S: Name: " + sd.SoundName + " path: " + sd.Path + " type: " + sd.Type);

        stream.Close();

        FindObjectOfType <SoundController>().Init();
    }
Example #14
0
        public static ConfigFile Parse(string path)
        {
            using var reader = new JsonTextReader(new StreamReader(path));
            JToken token = JToken.ReadFrom(reader);

            return(new ConfigFile(
                       Path.GetFullPath(path),
                       token["version"].Value <int>(),
                       (token["rules"] ?? Enumerable.Empty <JToken>()).OfType <JProperty>()
                       .ToDictionary(prop => prop.Name, prop => Rule.Parse(prop.Value)),
                       (token["sounds"] ?? Enumerable.Empty <JToken>()).OfType <JProperty>()
                       .ToDictionary(prop => prop.Name, prop => SoundDefinition.Parse(path, prop.Name, prop.Value)),
                       (token["hooks"] ?? Enumerable.Empty <JToken>()).Select((token, index) => Hook.Parse(path, index, token)).ToList()
                       ));
        }
Example #15
0
        private void AddSoundToTypeMap(SoundDefinition sound)
        {
            if (soundTypes.TryGetValue(sound.type, out var list))
            {
                list.Add(sound);
                return;
            }

            var newList = new List <SoundDefinition>
            {
                sound
            };

            soundTypes.Add(sound.type, newList);
        }
Example #16
0
    // Use this for initialization
    public void PlaySoundDefinition(SoundDefinition sound)
    {
        var soundeffectSource = GetComponent <AudioSource>();

        soundeffectSource.clip = sound.Clip;

        float magicNumber = 1.0f;

        //NOTE - feel free to find a better algorithm to vary volume and pitch.
        soundeffectSource.volume = sound.Volume * (magicNumber + Random.Range(1.0f - sound.VolumeModifier, 0.5f + sound.VolumeModifier));
        soundeffectSource.pitch  = sound.Pitch * (magicNumber + Random.Range(1.0f - sound.PitchModifier, 1.0f + sound.PitchModifier));

        timeLeftAlive = sound.Clip.length;
        soundeffectSource.Play();
    }
Example #17
0
        public void DoVoice(VoiceCmd cmd, float range = 3000, float volume = 0.7f)
        {
            if (this.CustomVoice <= 0)
            {
                return;
            }

            string str = string.Format("SVM_{0}_{1}.WAV", (int)this.CustomVoice, cmd);

            if (!cachedVoices.TryGetValue(str, out SoundDefinition scream))
            {
                scream = new SoundDefinition(str);
                cachedVoices.Add(str, scream);
            }
            SoundHandler.PlaySound3D(scream, this.BaseInst, range, volume);
        }
Example #18
0
        void StartStand(HordeScenario.Stand stand)
        {
            if (!HordeMode.IsActive)
            {
                return;
            }

            ActiveStand = stand;

            if (!string.IsNullOrWhiteSpace(stand.SFXStart))
            {
                var def = new SoundDefinition(stand.SFXStart);
                if (stand.GlobalSFX)
                {
                    SoundHandler.PlaySound(def, 1.0f);
                }
                else
                {
                    SoundHandler.PlaySound3D(def, stand.Position, 5000 + stand.Range, 1.0f);
                }
            }

            if (!string.IsNullOrWhiteSpace(stand.SFXLoop))
            {
                var def = new SoundDefinition(stand.SFXLoop);
                if (stand.GlobalSFX)
                {
                    SoundHandler.PlaySound(def, 1.0f);
                }
                else
                {
                    SoundHandler.PlaySound3D(def, stand.Position, 5000 + stand.Range, 0.5f, true);
                }
            }

            if (stand.Messages != null && stand.Messages.Length > 0)
            {
                messageIndex = 0;
                NextMessage();
                if (stand.Messages.Length > 1 && stand.Duration > 0)
                {
                    messageTimer.SetInterval(stand.Duration / (stand.Messages.Length - 1));
                    messageTimer.SetCallback(NextMessage);
                    messageTimer.Start();
                }
            }
        }
        public SoundDefinition GetSoundDefinition(ModObjectReference sound)
        {
            if (sound == null)
            {
                return(null);
            }

            if (!mods.ContainsKey(sound.modIdentifier))
            {
                return(null);
            }

            SoundDefinition g = mods[sound.modIdentifier].GetSoundDefinition(sound.objectName);

            if (g == null)
            {
                return(null);
            }

            return(g);
        }
Example #20
0
 public void SetUnconsciousness(Unconsciousness unconsciousness)
 {
     if (this.uncon != Unconsciousness.None && unconsciousness == Unconsciousness.None)
     {
         int voice = (int)this.CustomVoice;
         if (voice > 0 && voice < 20)
         {
             string str = string.Format("SVM_{0}_OHMYHEAD.WAV", voice);
             if (!cachedVoices.TryGetValue(str, out SoundDefinition scream))
             {
                 scream = new SoundDefinition(str);
                 cachedVoices.Add(str, scream);
             }
             SoundHandler.PlaySound3D(scream, this.BaseInst, 3000, 0.7f);
         }
     }
     this.uncon = unconsciousness;
     if (this == Hero)
     {
         oCNpcFocus.SetFocusMode(IsUnconscious ? 0 : 1);
     }
 }
Example #21
0
    IEnumerator makeAudioDefinitionsFromSoundsFile(SoundsFile sounds)
    {
        //Debug.Log(sounds.SourceCount);
        string load = loadingText;

        for (int sound = 0; sound < sounds.SoundCount; sound++)
        {
            SoundDefinition sd = sounds.GetSound(1, sound);
            audioDefinition ad = new audioDefinition();
            ad.sounds = new List <AudioClip>();
            foreach (Permutation p in sd.permutations)
            {
                AudioClip clip = AudioClip.Create("sound", p.Samples.Length, 1, (int)p.SampleRate, false);
                clip.SetData(p.Samples, 0);
                ad.sounds.Add(clip);
            }
            ad.cannotBeMediaObstructed = sd.CannotBeMediaObstructed;
            ad.cannotBeRestarted       = sd.CannotBeRestarted;
            ad.doesNotSelfAbort        = sd.DoesNotSelfAbort;
            ad.resistsPitchChanges     = sd.ResistsPitchChanges;
            ad.cannotChangePitch       = sd.CannotChangePitch;
            ad.cannotBeObstructed      = sd.CannotBeObstructed;
            ad.isAmbient = sd.IsAmbient;
            ad.chance    = sd.Chance;
            ad.lowPitch  = sd.LowPitch;
            ad.highPitch = sd.HighPitch;

            audioDefinitions.Add(ad);

            if (sound % 77 == 0)
            {
                loadingText = load + "Loading Sounds... " + sound + "/" + sounds.SoundCount;
                yield return(null);
            }
        }
        loadingText = load + "Loading Sounds... " + sounds.SoundCount + "/" + sounds.SoundCount;
    }
Example #22
0
        public void StartOutgame()
        {
            var theme = new SoundDefinition("INSTALLER_LOOP.WAV");

            theme.zSFX.IsFixed = true;
            theme.zSFX.Volume  = 0.5f;
            theme.zSFX.SetLooping(true);
            _MenuTheme = SoundHandler.PlaySound(theme, 0.5f);

            if (_DiContainer == null)
            {
                _DiContainer = _DiBuilder.Build();
            }
            _DiContainer.Resolve <LoginMenu>().Open();

            OnOutgame?.Invoke();
            Logger.Log("Outgame started.");


            InputControl.Active = _DiContainer.Resolve <ArenaControl>();


            Logger.Log("SumpfkrautOnline ClientScripts loaded!");
        }
Example #23
0
 //Note - currently we're not using any of the additional properties of the sound definition to change the sound of music files.
 //So far there is no reason to but we can easily modify this method to use pitch, volume, etc.
 public void PlayMusic(SoundDefinition song)
 {
     musicSource.GetComponent <AudioSource>().clip = song.Clip;
     musicSource.GetComponent <AudioSource>().Play();
 }
 public void PlaySound(SoundDefinition definition, Vector3 position, float velocity = 0f)
 {
 }
Example #25
0
 private void Play(SoundDefinition definition)
 {
     Play(definition.clip, definition.identifier, definition.audioGroup, null, definition.loop);
 }
Example #26
0
        public override void OnReadScriptVobMsg(PacketReader stream)
        {
            var msgID = (ScriptVobMessageIDs)stream.ReadByte();

            switch (msgID)
            {
            case ScriptVobMessageIDs.HitMessage:
                var attackerID = stream.ReadUShort();
                if (WorldInst.Current.BaseWorld.TryGetVob(attackerID, out NPC attacker))
                {
                    int index = Randomizer.GetInt(hitSounds.Count);
                    SoundHandler.PlaySound3D(hitSounds[index], this.BaseInst);

                    if (this.CustomVoice > 0 && screamTimer.IsReady)
                    {
                        index = Randomizer.GetInt(6) - 2;
                        if (index > 0)
                        {
                            string str = string.Format("SVM_{0}_AARGH_{1}.WAV", (int)this.CustomVoice, index);
                            if (!cachedVoices.TryGetValue(str, out SoundDefinition scream))
                            {
                                scream = new SoundDefinition(str);
                                cachedVoices.Add(str, scream);
                            }
                            SoundHandler.PlaySound3D(scream, this.BaseInst, 3000, 0.8f);
                        }
                    }

                    if (!this.ModelInst.IsInAnimation())
                    {
                        this.BaseInst.gModel.StartAni("T_GOTHIT", 0);
                    }

                    // fixme: transmit hit direction and use stumble animation
                }
                break;

            case ScriptVobMessageIDs.ParryMessage:
                attackerID = stream.ReadUShort();
                if (WorldInst.Current.BaseWorld.TryGetVob(attackerID, out NPC targetNPC))
                {
                    this.BaseInst.gAI.StartParadeEffects(targetNPC.gVob);
                }
                break;

            case ScriptVobMessageIDs.Climb:
                var ledge = new NPC.ClimbingLedge(stream);
                this.BaseInst.SetGClimbingLedge(ledge);
                break;

            case ScriptVobMessageIDs.Uncon:
                SetUnconsciousness((Unconsciousness)stream.ReadByte());
                break;

            case ScriptVobMessageIDs.Voice:
                DoVoice((VoiceCmd)stream.ReadByte());
                break;

            case ScriptVobMessageIDs.VoiceShout:
                DoVoice((VoiceCmd)stream.ReadByte(), 6000, 0.8f);
                break;

            default:
                break;
            }
        }
 private void DoHitSound(SoundDefinition soundDef)
 {
 }
Example #28
0
 public void Init(SoundDefinition _definition)
 {
     definition = _definition;
     clip       = Resources.Load <AudioClip>(definition.Path);
 }