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 ( 'bgmSystem' , Sein . Audio . SystemActor ) ; game . addActor ( 'soundSystem' , Sein . Audio . SystemActor ) ; game . resource . load ( { type : 'Audio' , name : 'sakura.mp3' , url : getStaticAssetUrl ( '/assets/audios/sakura.mp3' ) } ) ; game . resource . load ( { type : 'Audio' , name : 'clock.mp3' , url : getStaticAssetUrl ( '/assets/audios/clock.mp3' ) , mode : 'Buffer' } ) ; } public onLoading ( state ) { this . hud . update ( state ) ; } public onCreate ( ) { const game = this . getGame ( ) ; const world = this . getWorld ( ) ; this . hud . destroy ( ) ; const bgmSystem = Sein . findActorByName < Sein . Audio . SystemActor > ( game , 'bgmSystem' ) ; const soundSystem = Sein . findActorByName < Sein . Audio . SystemActor > ( game , 'soundSystem' ) ; world . addActor ( 'audioSource1' , Sein . Audio . SourceActor , { system : bgmSystem , clips : [ { name : 'sakura' , clip : game . resource . get < 'Audio' > ( 'sakura.mp3' ) } ] , autoPlay : { loop : true } } ) ; world . addActor ( 'clock' , Sein . Audio . SourceActor , { system : soundSystem , clips : [ { name : 'clock' , clip : game . resource . get < 'Audio' > ( 'clock.mp3' ) } ] , autoPlay : { loop : true } } ) ; world . addActor ( 'audioListener' , Sein . Audio . ListenerActor ) ; game . event . add < { name : string ; value : number ; } > ( 'AudioControl' , ( { name , value } ) => { switch ( name ) { case 'BGM' : bgmSystem . volume = value ; break ; case 'Sound' : soundSystem . volume = value ; break ; default : break ; } } ) ; game . event . add < { name : string ; value : number ; } > ( 'AudioSwitch' , ( { name } ) => { let system ; switch ( name ) { case 'BGM' : system = bgmSystem ; break ; case 'Sound' : system = soundSystem ; break ; default : break ; } if ( system . context . state === 'running' ) { system . pause ( ) ; } else { system . resume ( ) ; } } ) ; createDefaultLights ( game ) ; createDefaultCamera ( game , { target : new Sein . Vector3 ( 0 , 0 , 0 ) , position : new Sein . Vector3 ( 0 , 20 , 5 ) } ) ; } }