void Awake() { if( mInstance != null ) { Debug.LogError( string.Format( "Only one instance of RegionAgent allowed! Destroying:" + gameObject.name +", Other:" + mInstance.gameObject.name ) ); Destroy( gameObject ); return; } mInstance = this; }
public SpawnerInfo( Vector3 newPosition, Animator newAnimator, RegionAgent.RegionType newRegion ) { position = newPosition; animator = newAnimator; region = newRegion; }
public static void FadeInRegionMusic( RegionAgent.RegionType region ) { if( instance ) instance.internalFadeInRegionMusic( region ); }
private IEnumerator RegionFade( RegionAgent.RegionType region, bool fadeIn ) { AudioSource regionSource = null; float regionVolume = 0f; switch( region ) { case RegionAgent.RegionType.BridgeRegion: regionSource = BridgeRegionSource; regionVolume = BridgeRegionVolume; BridgeRegionSourceRequested = true; break; case RegionAgent.RegionType.CryoRegion: regionSource = CryoRegionSource; regionVolume = CryoRegionVolume; CryoRegionSourceRequested = true; break; case RegionAgent.RegionType.DiscoRegion: regionSource = DiscoRegionSource; regionVolume = DiscoRegionVolume; DiscoRegionSourceRequested = true; break; case RegionAgent.RegionType.EngineRegion: regionSource = EngineRegionSource; regionVolume = EngineRegionVolume; EngineRegionSourceRequested = true; break; case RegionAgent.RegionType.HubRegion: regionSource = HubRegionSource; regionVolume = HubRegionVolume; HubRegionSourceRequested = true; break; case RegionAgent.RegionType.JanitorRegion: regionSource = JanitorRegionSource; regionVolume = JanitorRegionVolume; JanitorRegionSourceRequested = true; break; case RegionAgent.RegionType.SpaceRegion: regionSource = SpaceRegionSource; regionVolume = SpaceRegionVolume; SpaceRegionSourceRequested = true; break; } //ensure this coroutine has sole control of region source yield return null; yield return null; switch( region ) { case RegionAgent.RegionType.BridgeRegion: BridgeRegionSourceRequested = false; break; case RegionAgent.RegionType.CryoRegion: CryoRegionSourceRequested = false; break; case RegionAgent.RegionType.DiscoRegion: DiscoRegionSourceRequested = false; break; case RegionAgent.RegionType.EngineRegion: EngineRegionSourceRequested = false; break; case RegionAgent.RegionType.HubRegion: HubRegionSourceRequested = false; break; case RegionAgent.RegionType.JanitorRegion: JanitorRegionSourceRequested = false; break; case RegionAgent.RegionType.SpaceRegion: SpaceRegionSourceRequested = false; break; } if( regionSource == null ) yield break; float toValue = ( fadeIn ? regionVolume : 0f ); float sign = ( fadeIn ? 1f : -1f ); while( regionSource.volume != toValue ) { regionSource.volume += FadeSpeed * regionVolume * Time.deltaTime * sign; regionSource.volume = Mathf.Clamp( regionSource.volume, 0f, regionVolume ); bool regionRequested = false; switch( region ) { case RegionAgent.RegionType.BridgeRegion: regionRequested = BridgeRegionSourceRequested; break; case RegionAgent.RegionType.CryoRegion: regionRequested = CryoRegionSourceRequested; break; case RegionAgent.RegionType.DiscoRegion: regionRequested = DiscoRegionSourceRequested; break; case RegionAgent.RegionType.EngineRegion: regionRequested = EngineRegionSourceRequested; break; case RegionAgent.RegionType.HubRegion: regionRequested = HubRegionSourceRequested; break; case RegionAgent.RegionType.JanitorRegion: regionRequested = JanitorRegionSourceRequested; break; case RegionAgent.RegionType.SpaceRegion: regionRequested = SpaceRegionSourceRequested; break; } if( regionRequested ) yield break; yield return null; } }
private void internalFadeOutRegionMusic( RegionAgent.RegionType region ) { StartCoroutine( RegionFade( region, false ) ); }
private void internalFadeInRegionMusic( RegionAgent.RegionType region ) { StartCoroutine( RegionFade( region, true ) ); }