Core.Object | +--Engine.Actor | +--Engine.Keypoint | +--UnrealShare.DynamicAmbientSound
sound
Sounds[16]
bool
bDontRepeat
bInitiallyOn
int
lastSound
float
maxReCheckTime
minReCheckTime
numSounds
playProbability
rePlayTime
soundPlaying
void
BeginPlay()
Timer()
00001 //============================================================================= 00002 // DynamicAmbientSound. 00003 //============================================================================= 00004 class DynamicAmbientSound extends Keypoint; 00005 00006 var() bool bInitiallyOn; // Initial state 00007 var() sound Sounds[16]; // What to play (must be at least one sound) 00008 var() float playProbability; // The chance of the sound effect playing 00009 var() float minReCheckTime; // Try to restart the sound after (min amount) 00010 var() float maxReCheckTime; // Try to restart the sound after (max amount) 00011 var() bool bDontRepeat; // Never play two of the same sound in a row 00012 var bool soundPlaying; // Is it currently playing it? 00013 var float rePlayTime; 00014 var int numSounds; // The number of sounds available 00015 var int lastSound; // Which sound was played most recently? 00016 00017 function BeginPlay () 00018 { 00019 00020 local int i; 00021 00022 // Calculate how many sounds the user specified 00023 numSounds=6; 00024 for (i=0; i<16; i++) 00025 { 00026 if (Sounds[i] == None) 00027 { 00028 numSounds=i; 00029 break; 00030 } 00031 } 00032 00033 lastSound=-1; 00034 if (bInitiallyOn) 00035 { 00036 // Which sound should be played? 00037 i = Rand(numSounds); 00038 PlaySound (Sounds[i]); 00039 lastSound = i; 00040 } 00041 00042 rePlayTime = (maxReCheckTime-minReCheckTime)*FRand() + minReCheckTime; 00043 SetTimer(rePlayTime, False); 00044 } 00045 00046 00047 function Timer () 00048 { 00049 00050 local int i; 00051 00052 if (FRand() <= playProbability) 00053 { 00054 00055 // Play the sound 00056 // Which sound should be played? 00057 i = Rand(numSounds); 00058 while( i == lastSound && bDontRepeat && numSounds > 1 ) 00059 i = Rand(numSounds); 00060 00061 PlaySound (Sounds[i]); 00062 lastSound = i; 00063 } 00064 00065 rePlayTime = (maxReCheckTime-minReCheckTime)*FRand() + minReCheckTime; 00066 SetTimer(rePlayTime, False); 00067 } 00068 00069 defaultproperties 00070 { 00071 playProbability=0.600000 00072 minReCheckTime=5.000000 00073 maxReCheckTime=10.000000 00074 bStatic=False 00075 }