UnrealShare
Class TriggeredAmbientSound

source: e:\games\UnrealTournament\UnrealShare\Classes\TriggeredAmbientSound.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Keypoint
         |
         +--UnrealShare.TriggeredAmbientSound
Direct Known Subclasses:None

class TriggeredAmbientSound
extends Engine.Keypoint

//============================================================================= // TriggeredAmbientSound. //=============================================================================
Variables
 sound AmbSound
 bool bInitiallyOn
 bool bPlayOnceOnly
 float rePlayTime
 float rePlayVariance


Function Summary
 void BeginPlay()
 void Timer()
 void Trigger(Actor Other, Pawn EventInstigator)
 void Trigger(Actor Other, Pawn EventInstigator)
 void UnTrigger(Actor Other, Pawn EventInstigator)



Source Code


00001	//=============================================================================
00002	// TriggeredAmbientSound.
00003	//=============================================================================
00004	class TriggeredAmbientSound extends Keypoint;
00005	
00006	// Re-plays a sound effect if triggered.  If in state TriggerToggled,
00007	// the sound is turned off if triggered, and turned on, etc..
00008	// when triggered again.  In the OnWhileTriggered state, the instigator
00009	// must stay within the trigger's radius for the sound effect to continue
00010	// playing.  bInitiallyOn determines if the sound is playing from the 
00011	// start, and does not apply in the OnWhileTriggered state.  A variance
00012	// can also be set for the timing, so that the replay time can seem
00013	// more 'real'.
00014	
00015	var() bool  bInitiallyOn;
00016	var() sound AmbSound;
00017	var() float rePlayTime;
00018	var() float rePlayVariance;
00019	var() bool  bPlayOnceOnly;
00020	
00021	var	  bool  bIsOn;
00022	var	  bool  bPlayedOnce;
00023	
00024	function BeginPlay () {
00025		
00026		local float timeDelta;
00027		
00028		if (bInitiallyOn) {
00029			PlaySound (AmbSound, , Float(SoundVolume)/128, , Float(SoundRadius)*25);
00030			bIsOn = true;
00031		}
00032	
00033		timeDelta = (rePlayVariance*2)*FRand() - rePlayVariance + rePlayTime;
00034		SetTimer(timeDelta, False);
00035	}
00036	
00037	
00038	function Timer () {
00039	
00040		local float timeDelta;
00041		
00042		if ( (bIsOn && !bPlayOnceOnly) || (bIsOn && bPlayOnceOnly && !bPlayedOnce) ) {
00043		
00044			// Replay the sound
00045			// Which sound should be played?
00046			PlaySound (AmbSound, , Float(SoundVolume)/128, , Float(SoundRadius)*25);
00047			bPlayedOnce = true;
00048		}
00049	
00050		timeDelta = (rePlayVariance*2)*FRand() - rePlayVariance + rePlayTime;
00051		SetTimer(timeDelta, False);
00052	}
00053	
00054	
00055	state() TriggerToggled
00056	{
00057		function Trigger( actor Other, pawn EventInstigator )
00058		{
00059			bIsOn = !bIsOn;
00060			bPlayedOnce = false;
00061		}
00062	}
00063	
00064	
00065	state() OnWhileTriggered
00066	{
00067		function Trigger( actor Other, pawn EventInstigator )
00068		{
00069			bIsOn = true;
00070			bPlayedOnce = false;
00071		}
00072	
00073		function UnTrigger( actor Other, pawn EventInstigator )
00074		{
00075			bIsOn = false;
00076		}
00077	
00078	Begin:
00079		bIsOn = false;
00080	}
00081	
00082	defaultproperties
00083	{
00084	}

End Source Code