1.在一个plane上播放
1 2 3 4 5 6 7 8 9 10 11 12 |
using UnityEngine; using System.Collections; public class MobileMovieTexture : MonoBehaviour { public MovieTexture movTexture; void Start() { GetComponent<Renderer>().material.mainTexture = movTexture; movTexture.Play(); } } |
2.GUI.DrawTexture
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
using UnityEngine; using System.Collections; public class moiveTextureGUi : MonoBehaviour { public MovieTexture mt; void Start() { mt.loop = true; } void OnGUI() { GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),mt,ScaleMode.StretchToFill); if (GUILayout.Button("play")) { if (!mt.isPlaying) { mt.Play(); } } } } |
3. Handheld.PlayFullScreenMovie
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
using UnityEngine; using System.Collections; /// <summary> /// 事先装个QuickTime /// 一般在游戏开始前,会播放一个CG动画,点击屏幕救你可以关闭了 /// 视频文件放在StreamingAssets文件夹下 /// </summary> public class TestHeadMoiveOnMobile : MonoBehaviour { void Start() { Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.CancelOnInput); } void OnGUI() { //视频播放时触摸屏幕视频关闭 if (GUI.Button(new Rect(20, 10, 300, 50), "PLAY ContronlMode.CancleOnTouch")) { Handheld.PlayFullScreenMovie("test.mp4",Color.black,FullScreenMovieControlMode.CancelOnInput); } //视频播放时弹出控件,控制视频暂停,播放,全屏等 if (GUI.Button(new Rect(20, 90, 200, 50), "PLAY ControlMode.Full")) { Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.Full); } //视频播放时无法停止,当其播放完一次 后自动关闭 if (GUI.Button(new Rect(20, 170, 200, 50), "PLAY ControlMode.Hidden")) { Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.Hidden); } //视频播放时弹出控件,可控制播放进度 if (GUI.Button(new Rect(20, 250, 200, 50), "PLAY ControlMode.Minimal")) { Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.Minimal); } } } |
第三种方式,只能在真机上测试,才有效果哦。
一般选用:视频播放时触摸屏幕视频关闭
Handheld.PlayFullScreenMovie(“test.mp4″,Color.black,FullScreenMovieControlMode.CancelOnInput);