Phoenix84

Sound Example

Apr 9th, 2016 (edited)
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. Declared in class:
  2. ```csharp
  3.         private MyEntity3DSoundEmitter m_soundEmitter;
  4.         public MyEntity3DSoundEmitter SoundEmitter { get { return m_soundEmitter; } }
  5. ```
  6. In Init():
  7. ```csharp
  8.             m_soundEmitter = new MyEntity3DSoundEmitter(Container.Entity as VRage.Game.Entity.MyEntity);
  9. ```
  10. Using:
  11. ```csharp
  12.         public static void PlaySound(this IMyFunctionalBlock ftl, string soundname, bool stopPrevious = false)
  13.         {
  14.             MyEntity3DSoundEmitter emitter = null;
  15.  
  16.             if( ftl.IsFTL() )
  17.                 emitter = ftl.GameLogic.GetAs<FTL>().SoundEmitter;
  18.  
  19.             if( emitter != null )
  20.             {
  21.                 if (string.IsNullOrEmpty(soundname))
  22.                 {
  23.                     emitter.StopSound((emitter.Loop ? true : false), true);
  24.                 }
  25.                 else
  26.                 {
  27.                     MySoundPair sound = new MySoundPair(soundname);
  28.                     emitter.CustomMaxDistance = (float)ftl.GetTopMostParent().PositionComp.WorldVolume.Radius * 2.0f;
  29.                     Logger.Instance.LogDebug("Distance: " + emitter.CustomMaxDistance);
  30.                     emitter.CustomVolume = 1.0f;
  31.                     emitter.PlaySound(sound, stopPrevious);
  32.                 }
  33.             }
  34.         }
  35. ```
Advertisement
Add Comment
Please, Sign In to add comment