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);
    }

    }

    }

  • 相关阅读:
    开源魔兽世界私服搭建
    centos7 普通用户无法使用ssh登录其他服务器
    Java时间格式大全
    C#中的线程之Abort陷阱
    C# 多线程学习系列四之ThreadPool取消、超时子线程操作以及ManualResetEvent和AutoResetEvent信号量的使用
    C# ThreadPool类(线程池)
    VS2019输出信息到调试控制台
    Stream/Bytes[]/Image对象相互转化
    Asp.NetCore 读取配置文件帮助类
    Java SpringBoot使用126邮箱发送html内容邮件,带附件
  • 原文地址:https://www.cnblogs.com/wowanyasuo/p/5976916.html
Copyright © 2011-2022 走看看