1 usingUnityengine;2 usingSystem.Collections;3 4 Public classTestlage:monobehaviour {5 PublicMoviemanage Movie;//defining a player component6 Publicuitexture uitexture;7 Publicgameobject ga;8 Private stringRootPath ="streamingassets/moviesamples/";//the address where the music is stored9 //Use this for initializationTen voidStart () { One } A //Update is called once per frame - voidUpdate () { - } the /// <summary> - ///callback Method - /// </summary> - /// <param name= "str" ></param> + Public voidMyaction (stringstr) - { + Debug.Log (str); A } at voidOngui () - { - if(Guilayout.button ("PLAY")) - { - if(ga==NULL) - { in creat (); - } to movie.setaction (myaction); +Movie.playmovie ("handoffate"); - } the if(Guilayout.button ("PAUSE")) * { $ if(ga!=NULL)Panax Notoginseng { - Movie.pausemovie (); the } + } A if(Guilayout.button ("STOP")) the { + if(GA! =NULL) - { $ Movie.stopmovie (); $ } - } - if(Guilayout.button ("Destroy")) the { - if(GA! =NULL)Wuyi { the Destroymovie (); - } Wu } - } About $ Public voidDestroymovie () - { - if(ga!=NULL) - { A Movie.Texture1.Stop (); + Destroy (GA); the } - } $ the Public voidcreat () the { theGA = Nguitools.addchild ( This. Gameobject); theGa.name ="GA"; -Ga. Addcomponent<moviemanage>(); inMovie =ga. Getcomponent ("Moviemanage") asMoviemanage;//Get player Component theUitexture Tex = nguitools.addchild<uitexture>(ga.gameobject); the } About}
Movie Management Code
1 usingUnityengine;2 usingSystem.Collections;3 usingSystem;4 /// <summary>5 ///Description:6 ///methods: 1 Moviemanage.playmovie ("Moviename"); Moviename is the name of the movie and must be under the Resources folder, RootPath is relative resources. 7 ///2 MovieManage.Texture1.Play (); play a movie8 ///3 Movie.Texture1.Pause (); Pause movie9 ///4 Movie.Texture1.Stop (); stop playing the movieTen /// </summary> One Public classMoviemanage:monobehaviour { A Private stringRootPath ="streamingassets/moviesamples/";//the address where the music is stored - Publicmovietexture Texture1; - Publicuitexture uitexture; the Privateaction<string>Action; - Public BOOLCheckflag =false; - - Public BOOLSpflag =true; + - Public voidSetaction (action<string>action) + { A This. Action =Action; at } - //Use this for initialization - voidStart () { - } - //Update is called once per frame - voidUpdate () { in if(Checkflag) - { toUitexture.getcomponent<uiwidget> (). width =Screen.width; +Uitexture.getcomponent<uiwidget> (). Height =Screen.height; - if(Spflag) the { * if(!texture1.isplaying) $ {Panax NotoginsengAction"movietest Test"); -Checkflag =false; the texture1.stop (); + Destroy (gameobject); A } the + } - } $ } $ Public voidPlaymovie (stringmoviename) - { -Uitexture = (uitexture) This. Transform. Findchild ("Texture"). Getcomponent<uitexture>(); the //here the resource is loaded, movie is the video file name does not need suffix name -Texture1 = (movietexture) resources.load (RootPath + moviename,typeof(Movietexture));WuyiUitexture.maintexture=Texture1; the Texture1.play (); -Checkflag =true; WuSpflag =true; - } About Public voidStopmovie () $ { -Spflag =false; - texture1.stop (); - } A Public voidPausemovie () + { the texture1.pause (); -Spflag =false; $ } the the}
Core code:
GA = Nguitools.addchild (this.gameobject);//automatic generation of Gameobject objects
Ga.name = "GA";//Modify Name
Ga. Addcomponent<moviemanage> ();//Add footstep components
Movie =ga. Getcomponent ("Moviemanage") as moviemanage;//get player component
Uitexture Tex = nguitools.addchild<uitexture> (ga.gameobject);//Add Uitexture component to GA.
Ngui Dynamic Playback Video