File Author Date Description import * as Sein from 'seinjs' ; import 'seinjs-audio' ; import { createDefaultLights , createDefaultCamera , createLoadingHUD } from '../../utils' ; export default class MainScript extends Sein . LevelScriptActor { private hud : any ; public onPreload ( ) { const game = this . getGame ( ) ; this . hud = createLoadingHUD ( game ) ; game . resource . register ( 'Audio' , Sein . Audio . Loader ) ; game . addActor ( 'audioSystem' , Sein . Audio . SystemActor ) ; game . resource . load ( { type : 'Audio' , name : 'sakura.mp3' , url : getStaticAssetUrl ( '/assets/audios/sakura.mp3' ) } ) ; } public onLoading ( state ) { this . hud . update ( state ) ; } public onCreate ( ) { const game = this . getGame ( ) ; const world = this . getWorld ( ) ; this . hud . destroy ( ) ; const audioSystem = Sein . findActorByClass ( game , Sein . Audio . SystemActor ) ; const source1 = world . addActor ( 'audioSource1' , Sein . Audio . SourceActor , { system : audioSystem , clips : [ { name : 'sakura' , clip : game . resource . get < 'Audio' > ( 'sakura.mp3' ) } ] , spaceOptions : { maxDistance : 10 } , autoPlay : { loop : true } , position : new Sein . Vector3 ( 0 , 0 , 0 ) } ) ; source1 . addComponent ( 'sphere' , Sein . BSPSphereComponent , { radius : source1 . audio . spaceOption . maxDistance , material : new Sein . PBRMaterial ( { baseColor : new Sein . Color ( 1 , 0 , 0 , 1 ) , wireframe : true } ) } ) ; const listener1 = world . addActor ( 'audioListener' , Sein . Audio . ListenerActor , { position : new Sein . Vector3 ( - 5 , 0 , 0 ) } ) ; listener1 . addComponent ( 'sphere' , Sein . BSPSphereComponent , { radius : .4 , material : new Sein . PBRMaterial ( { baseColor : new Sein . Color ( 0 , 1 , 0 , 1 ) } ) } ) ; const listener2 = world . addActor ( 'audioListener' , Sein . Audio . ListenerActor , { position : new Sein . Vector3 ( 5 , 0 , 0 ) } ) ; listener2 . addComponent ( 'sphere' , Sein . BSPSphereComponent , { radius : .4 , material : new Sein . PBRMaterial ( { baseColor : new Sein . Color ( 0 , 0 , 1 , 1 ) } ) } ) ; game . event . add < number > ( 'AudioControl' , ( value ) => { if ( value === 1 ) { listener1 . enable ( ) ; } else { listener2 . enable ( ) ; } } ) ; createDefaultLights ( game ) ; createDefaultCamera ( game , { target : new Sein . Vector3 ( 0 , 0 , 0 ) , position : new Sein . Vector3 ( 0 , 20 , 1 ) } ) ; } }