private void LateUpdate() { if (!(m_type == ActorType.Character) || !current) { return; } switch (m_playType) { case PlayType.Footstep: { if (m_stepCycle < m_nextStep) { break; } m_nextStep = m_stepCycle + m_stepInterval; SoundPreset.PlayOneshot(m_source, current.footstepSound); break; } case PlayType.Jump: SoundPreset.PlayOneshot(m_source, current.jumpSound); break; case PlayType.Land: SoundPreset.PlayOneshot(m_source, current.landSound); break; default: break; } m_playType = PlayType.Footstep; }
/// <summary> /// Creates sound preset from all the files in the folder. /// </summary> /// <param name="localSoundsFolderPath">Path inside "Content/Sounds/" folder.</param> /// <param name="throwExceptionIfNoFilesFound"></param> /// <returns></returns> public static ReadOnlySoundPreset <TSoundKey> CreateFromFolder <TSoundKey>( string localSoundsFolderPath, bool throwExceptionIfNoFilesFound = true) where TSoundKey : struct, Enum { if (!localSoundsFolderPath.EndsWith("/")) { localSoundsFolderPath += "/"; } var preset = new SoundPreset <TSoundKey>(); foreach (var enumValue in EnumExtensions.GetValues <TSoundKey>()) { preset.Add(enumValue, localSoundsFolderPath + enumValue.ToString()); } var result = preset.ToReadOnly(); if (throwExceptionIfNoFilesFound && result.SoundsCount == 0) { throw new Exception("No sounds found at " + localSoundsFolderPath); } return(result); }
private ReadOnlySoundPreset <WeaponSound> PrepareSoundPresetWeapon() { var preset = SoundPreset.CreateFromFolder <WeaponSound>( this.SoundsFolderPath + "/Weapon/", throwExceptionIfNoFilesFound: false); //this.VerifySoundPreset(preset); return(preset); }
private ReadOnlySoundPreset <CharacterSound> PrepareSoundPresetMovement() { var preset = SoundPreset.CreateFromFolder <CharacterSound>( this.SoundsFolderPath + "/Movement/", throwExceptionIfNoFilesFound: false); //this.VerifySoundPreset(preset); return(preset); }
protected virtual ReadOnlySoundPreset <GroundSoundMaterial> PrepareSoundPresetFootsteps() { var preset = SoundPreset.CreateFromFolder <GroundSoundMaterial>( this.SoundsFolderPath + "/Footsteps/", throwExceptionIfNoFilesFound: false); this.VerifySoundPreset(preset); return(preset); }
private void OnCollisionEnter(Collision collision) { if (m_rd3 && m_type != ActorType.RigidBody || !material) { return; } if ((collision.relativeVelocity.sqrMagnitude > m_minSpeed * m_minSpeed) && m_source) { SoundPreset.PlayOneshot(m_source, material.hitSound); } }
protected virtual ReadOnlySoundPreset <CharacterSound> PrepareSoundPresetCharacter() { if (!Api.Shared.IsFolderExists(ContentPaths.Sounds + this.SoundsFolderPath)) { throw new Exception("Sounds folder for " + this + " doesn't exist"); } var preset = SoundPreset.CreateFromFolder <CharacterSound>( this.SoundsFolderPath + "/Character/", throwExceptionIfNoFilesFound: false); //this.VerifySoundPreset(preset); return(preset); }
protected override ReadOnlySoundPreset <CharacterSound> PrepareSoundPresetCharacter() { if (!Api.Shared.IsFolderExists(ContentPaths.Sounds + this.SoundsFolderPath)) { throw new Exception("Sounds folder for " + this + " doesn't exist"); } var preset = SoundPreset.CreateFromFolder <CharacterSound>( this.SoundsFolderPath + "/Character/", throwExceptionIfNoFilesFound: false, customDistance: (15, 45), customDistance3DSpread: (10, 35)); //this.VerifySoundPreset(preset); return(preset); }
// Update is called once per frame public void Play() { SoundPreset.PlayOneshot(audioSource, preset); }