zoukankan      html  css  js  c++  java
  • Unity3D 视频播放

    视频播发有两种方法:
    (1)plane上
    using UnityEngine;
    using System.Collections;

    public class Test: MonoBehaviour
    {

    //电影纹理
    public MovieTexture movTexture;

    void Start()
    {
    //设置当前对象的主纹理为电影纹理
    gameObject.GetComponent<Renderer>().material.mainTexture = movTexture;
    //设置电影纹理播放模式为循环
    movTexture.loop = true;
    }

    void OnGUI()
    {
    if(GUILayout.Button("播放/继续"))
    {
    //播放/继续播放视频
    if(!movTexture.isPlaying)
    {
    movTexture.Play();
    }

    }

    if(GUILayout.Button("暂停播放"))
    {
    //暂停播放
    movTexture.Pause();
    }

    if(GUILayout.Button("停止播放"))
    {
    //停止播放
    movTexture.Stop();
    }
    }
    }
    (2)摄像机上播放

    using UnityEngine;
    using System.Collections;

    public class Test: MonoBehaviour
    {

    //电影纹理
    public MovieTexture movTexture;

    void Start()
    {
    //设置电影纹理播放模式为循环
    movTexture.loop = true;
    }

    void OnGUI()
    {
    //绘制电影纹理
    GUI.DrawTexture (new Rect (0,0, Screen.width, Screen.height),movTexture,ScaleMode.StretchToFill);

    if(GUILayout.Button("播放/继续"))
    {
    //播放/继续播放视频
    if(!movTexture.isPlaying)
    {
    movTexture.Play();
    }

    }

    if(GUILayout.Button("暂停播放"))
    {
    //暂停播放
    movTexture.Pause();
    }

    if(GUILayout.Button("停止播放"))
    {
    //停止播放
    movTexture.Stop();
    }
    }

    }
    (3)视频大小调控
    transform.localScale = new Vector(1,1,1);
    (4)移动设备播放
    using UnityEngine;
    using System.Collections;

    public class Test : MonoBehaviour {

    void OnGUI()
    {
    if (GUI.Button (new Rect (20,10,200,50), "PLAY ControlMode.CancelOnTouch"))
    {
    Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.CancelOnInput);
    }

    if (GUI.Button (new Rect (20,90,200,25), "PLAY ControlMode.Full"))
    {
    Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.Full);
    }

    if (GUI.Button (new Rect (20,170,200,25), "PLAY ControlMode.Hidden"))
    {
    Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.Hidden);
    }

    if (GUI.Button (new Rect (20,250,200,25), "PLAY ControlMode.Minimal"))
    {
    Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.Minimal);
    }

    }

    }

  • 相关阅读:
    一,初次接触html+css需要注意的小问题
    Pycharm如何在控制台输出窗口中使用Python解释器
    Silver Cow Party POJ
    Constructing Roads POJ
    小希的迷宫 HDU
    Wireless Network POJ
    Scanner读取记事本文件内容为空的解决办法
    mysql limit的使用方法
    Can you find it? HDU-2141 (二分查找模版题)
    【2028-07-18】精力是有限的,但智慧是无限的
  • 原文地址:https://www.cnblogs.com/wowanyasuo/p/5976916.html
Copyright © 2011-2022 走看看