public void PlayLoop(int soundID, Surface.Substance substance, Surface.Cue cue, float volume, Vector3 position = new Vector3(), Transform transformToFollow = null) { if (loopSoundEventDict.ContainsKey(soundID)) { //we've already created our loop, so merely update it with the current volume if (loopSoundEventDict[soundID] != null) { loopSoundEventDict[soundID].volume = volume; } } else { //Debug.Log("new loop created."); //TODO: Check the type of substance and only create a new AudioSource for new types of sounds //create entry for our looped sound so we can end it later GameObject go = new GameObject(substance + ":" + cue); SoundEvent se = go.AddComponent <SoundEvent>(); se.Initialize(surfaceDataDict[substance].GetSound(cue), SoundEvent.Category.Loop); if (transformToFollow != null) { //if we are following a transform position, the position should be ignored se.SetFollowTransform(transformToFollow); } else { se.SetPosition(position); } se.volume = volume; loopSoundEventDict.Add(soundID, se); loopSoundEventDict[soundID].Play(); } }
public void Play(Surface.Substance substance, Surface.Cue cue, Vector3 position, float volume) { if (surfaceDataDict.ContainsKey(substance)) { AudioSource.PlayClipAtPoint(surfaceDataDict[substance].GetSound(cue), position, volume); } }
public void PlayOneShot(Surface.Substance substance, Surface.Cue cue, float volume, Vector3 position) { if (surfaceDataDict.ContainsKey(substance)) { GameObject go = new GameObject(substance + ":" + cue); SoundEvent se = go.AddComponent <SoundEvent>(); se.Initialize(surfaceDataDict[substance].GetSound(cue), SoundEvent.Category.OneShot); se.SetPosition(position); se.volume = volume; se.Play(); } }
/// <summary> /// Returns the movement rate to apply to player movement. /// TODO: Make this more robust. Currently used as a simple multiplier by the force. /// </summary> /// <returns>The movement rate.</returns> /// <param name="substance">Surface.Substance from CollisionData</param> public static float GetMovementRate(Surface.Substance substance) { switch (substance) { case Substance.Solid: return(1); case Substance.Sand: return(0.5f); case Substance.Stone: return(1.0f); case Substance.Grass: return(0.8f); default: return(1); } }
int lastCollisionSFXIndex = -1; //makes the randomization work, see GetCollisionSound() public SurfaceSoundData(Surface.Substance type) { substance = type; sfxCollisionBank = new List <AudioClip>(); }