当前位置:网站首页>Self use tool unity video player that monkeys can use
Self use tool unity video player that monkeys can use
2022-06-28 03:35:00 【Starve fish】
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
public class Movie : MonoBehaviour
{
[Tooltip(" Whether to hide when the program starts running UI,false For hiding ")] public bool OpenMovie_Awake = true;
[Header("Buttons")]
[Tooltip(" Play button ")] public Button Start;
[Tooltip(" Broadcasting speed +")] public Button SpeedUp;
[Tooltip(" Broadcasting speed -")] public Button SpeedDown;
[Header("UI")]
[Tooltip(" Input VideoPlayer")] public VideoPlayer VideoPlayers;
[Tooltip(" Broadcasting speed Text")] public Text SpeedShow;
[Tooltip(" Playback time and total duration Text")] public Text TimeShow;
[Header(" Slider bar . You need to add a sliding event to the slider ")]
[Tooltip(" Volume bar ")] public Slider Volume;
[Tooltip(" Progress bar ")] public Slider Times;
[Header(" Video playback speed ")]
[Range(0f, 1f)]
public float PlayBackSpeedChange = 0.5f;// Playback speed adjusted each time
[Range(0f, 5f)]
public float PlayBackSpeedMax = 3f;// Maximum playback speed
public static int PlayingURL;// Play current URL
public static string[] URL = { @"file://D:/Test/Movie01.mov"};// Video collection
void Awake()
{
VideoPlayers.GetComponent<VideoPlayer>().url = URL[0];
AddListerer();
_MovieOpend = true;
}
public void Update()// The playback speed text is adjusted here
{
SpeedShow.text = " Broadcasting speed X" + VideoPlayers.playbackSpeed.ToString("#0.0");
TimeShow.text = ($"{(int)VideoPlayers.time / 60}:{(VideoPlayers.time % 60).ToString("00")}/{(int)VideoPlayers.length / 60}:{(VideoPlayers.length % 60).ToString("00")}");
if (VideoPlayers.frameRate / VideoPlayers.frameCount > 0)// Progress bar
{
if (!Input.GetMouseButton(0) || _volumedraging)
Times.value = (float)VideoPlayers.time / (float)VideoPlayers.length;
}
if (Input.GetMouseButtonUp(0)) _volumedraging = false;// Prevent sliding the volume bar to lock the progress bar
}
/// <summary>
/// Progress bar
/// </summary>
public void Ondrag()
{
if (Input.GetMouseButton(0) && !_volumedraging)
VideoPlayers.time = Times.value * (float)VideoPlayers.length;
}
/// <summary>
/// The volume
/// </summary>
public void VolumeDrag()
{
_volumedraging = true;
VideoPlayers.SetDirectAudioVolume(0, Volume.value);
}
/// <summary>
/// Add listeners for all buttons
/// </summary>
void AddListerer()
{
Start.onClick.AddListener(() =>// Play
{
if (_Pauseing)
{
VideoPlayers.playbackSpeed = 1f;
Start.gameObject.transform.Find("Text").GetComponent<Text>().text = " Pause ";
_Pauseing = false;
}
else
{
VideoPlayers.playbackSpeed = 0f;
Start.gameObject.transform.Find("Text").GetComponent<Text>().text = " Play ";
_Pauseing = true;
}
});
SpeedUp.onClick.AddListener(() =>
{
if (VideoPlayers.playbackSpeed < PlayBackSpeedMax)
VideoPlayers.playbackSpeed += PlayBackSpeedChange;
});
SpeedDown.onClick.AddListener(() =>
{
if (VideoPlayers.playbackSpeed > 0f)
VideoPlayers.playbackSpeed -= PlayBackSpeedChange;
});
}
bool _MovieOpend;
bool _Pauseing = false;
bool _volumedraging;
}
design sketch
边栏推荐
猜你喜欢
随机推荐
爱普生L3153打印机如何清洗喷头
猴子都会用的圆形滑动自动吸附UI工具
A pit filling trip based on LNMP to build a personal website
matlab习题 —— 数据的基本处理
物体上下漂浮工具
基于 WPF 的酷炫 GUI 窗口的简易实现
What is the difference between slice and array in go question bank 12?
【小程序】使用font-awesome字体图标的解决文案(图文)
用于 C# 的 SQL 基本语法总结
数据库系列之MySQL和TiDB中慢日志分析
crond BAD FILE MODE /etc/cron.d
Anaconda命令用法
TypeScript 联合类型
17 `bs object Node name h3 Parent ` parents get parent node ancestor node
【PaddleDetection】ModuleNotFoundError: No module named ‘paddle‘
Importer un fichier Excel, résoudre le problème de sauter les cellules vides et de ne pas lire, et avancer l'indice, et retourner Blank As NULL Red
导入Excel文件,解决跳过空白单元格不读取,并且下标前移的问题,以及RETURN_BLANK_AS_NULL报红
Dataloader参数collate_fn的使用
Floating point and complex type of go data type (4)
Relative path writing of files









