|
可以直接将ogg格式的材质赋给物体,这样需要加代码让这个这个视频播放起来。
function Update () {
renderer.material.mainTexture.Play();
}
这里的代码,实现播放暂停以及切换视频。不过这个代码要赋给摄像机,如果赋给物体的话在编辑器里好用,但是发布出来的时候就不好用了。
public var bofang:boolean = false;
public var movieTexture:MovieTexture;
function Start(){
movieTexture.Stop();
}
private var flag01:boolean = true;
function Update(){
if(!bofang){
return;
}
// 赋值剪辑到音频源
// 与音频同步播放
audio.clip = movieTexture.audioClip;
// 播放视频和音频
movieTexture.loop = true;
//renderer.material.mainTexture.wrapMode = TextureWrapMode.Clamp;
if(flag01){
movieTexture.Play();
audio.Play();
}else{
movieTexture.Pause();
audio.Pause();
}
}
//加上 播放暂停 关闭
//播放器
private var BFQWidth:float = 650;
private var BFQHeight:float = 490;
var BFQTexture:Texture;
private var BFQGBWidth:float = 16;
private var BFQGBHeight:float = 15;
var BFQGBStyle:GuiStyle;//关闭按钮
//播放器 播放暂停
private var BFQPlayWidth:float = 22;
private var BFQPlayHeight:float = 22;
var BFQPlayStyle:GUIStyle;//播放按钮
var BFQPauseStyle:GUIStyle;//暂停按钮
function OnGUI(){
if(!bofang){
return;
}
GUI.DrawTexture(new Rect(187, 139, BFQWidth, BFQHeight), BFQTexture, ScaleMode.StretchToFill);
GUI.DrawTexture (Rect (192,144, 640, 480),movieTexture,ScaleMode.ScaleToFit );
movieTexture.Play();
//关闭按钮
if(GUI.Button (Rect (800, 155, BFQGBWidth, BFQGBHeight),"",BFQGBStyle)){
GameObject.Find("Data").GetComponent("Data").cameraMain.enabled = true;
GameObject.Find("Data").GetComponent("Data").cameraView.enabled = false;
bofang = false;
guiTexture.texture = null;
gameObject.GetComponent("MovieControler").enabled = false;
}
//播放暂停
if(!flag01){
if(GUI.Button (Rect (800, 597, BFQPlayWidth, BFQPlayHeight),"",BFQPlayStyle)){
flag01 = true;
}
}else{
if(GUI.Button (Rect (800, 597, BFQPlayWidth, BFQPlayHeight),"",BFQPauseStyle)){
flag01 = false;
}
}
}
function GuanBi(){
GameObject.Find("Data").GetComponent("Data").cameraMain.enabled = true;
GameObject.Find("Data").GetComponent("Data").cameraView.enabled = false;
bofang = false;
guiTexture.texture = null;
gameObject.GetComponent("MovieControler").enabled = false;
}
// 确保我们有GUI 纹理和音频源
@script RequireComponent(GUITexture)
@script RequireComponent(AudioSource)
转自:http://ilaoxu.com/the-unity-sino-movietexture-video-player.html
|
|