using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using RenderHeads.Media.AVProVideo;
using System;
using DG.Tweening;
using HedgehogTeam.EasyTouch;
public class AVProXuLieZhen1 : MonoBehaviour
{
//获取视频
public MediaPlayer video;
//当前视频秒数
public float _currentFrame = 0;
//视频的最大秒数
public float VideoMaxTime = 3000;
//围绕一个点旋转点物体
public GameObject[] RoundImg;
//被围绕 旋转点点
public GameObject RoundPoint;
//判断是哪一个方向 旋转播放
public int isRotateDirection = 3;
//五张热点图
//public GameObject[] hotPic5;
void Update()
{
//刚开始给视频暂停
video.Stop();
//EasyTouch事件
Gesture gesture = EasyTouch.current;
if (gesture != null && EasyTouch.EvtType.On_Swipe == gesture.type)
{
//滑动事件
OnSwiper(gesture);
}
if (isRotateDirection == 1) {
if (_currentFrame == 3000) //大于3秒时
{
_currentFrame = 0;
}
_currentFrame += 20f;
if (_currentFrame == VideoMaxTime)
{
isRotateDirection = 3; //重新置为其他数字 未播放状态
//显示5个 热点图片
for (int i = 0; i < RoundImg.Length; i++)
{
RoundImg[i].SetActive(true);
}
}
video.Control.Seek(_currentFrame); //设置视频当前播放时间
}
else if (isRotateDirection == 2)
{
if (_currentFrame == 0)
{
_currentFrame = 3000;
}
_currentFrame -= 20f;
if (_currentFrame == 0) //等于0秒时
{
isRotateDirection = 3; //重新置为其他数字 未播放状态
//显示5个 热点图片
for (int i = 0; i < RoundImg.Length; i++)
{
RoundImg[i].SetActive(true);
}
}
video.Control.Seek(_currentFrame);//设置视频当前播放时间
}
}
//当触摸滑动
private void OnSwiper(Gesture gesture)
{
//向右 右上角 右下角方向滑动时 触发
if (gesture.swipe == EasyTouch.SwipeDirection.Right || gesture.swipe == EasyTouch.SwipeDirection.DownRight || gesture.swipe == EasyTouch.SwipeDirection.UpRight)
{
//当视频秒数 超过8秒时
//if (_currentFrame < VideoMaxTime)
//{
// _currentFrame+= 50f;
//}
//else
//{
// _currentFrame = 0;
//}
//video.Control.Seek(_currentFrame); //设置视频当前播放时间
//向右滑动时 顺时针播放
isRotateDirection = 1;
video.Play();
for (int i = 0; i < RoundImg.Length; i++)
{
RoundImg[i].SetActive(false);
}
//for (int i = 0; i < RoundImg.Length; i++)
//{
// //图片围绕一个点旋转
// RoundImg[0].transform.RotateAround(RoundPoint.transform.position, RoundPoint.transform.forward, -50f * Time.deltaTime);
//}
}
//向左 左上角 左下角方向滑动时 触发
if (gesture.swipe == EasyTouch.SwipeDirection.Left || gesture.swipe == EasyTouch.SwipeDirection.DownLeft || gesture.swipe == EasyTouch.SwipeDirection.UpLeft)
{
//当视频大于0秒时
//if (_currentFrame > 0)
//{
// _currentFrame-= 50f;
//}
//else
//{
// _currentFrame = VideoMaxTime;
//}
//video.Control.Seek(_currentFrame);//设置视频当前播放时间
video.Play();
isRotateDirection = 2;
for (int i = 0; i < RoundImg.Length; i++)
{
RoundImg[i].SetActive(false);
}
}
}
private void OnEnable()
{
//_currentFrame = 0;
//video.Control.Seek(0);
//显示 图标时 重置图标的位置 防止错位
RoundImg[0].transform.localPosition = new Vector3(243, 6, 0);
RoundImg[1].transform.localPosition = new Vector3(2, -98, 0);
RoundImg[2].transform.localPosition = new Vector3(-221, -55, 0);
RoundImg[3].transform.localPosition = new Vector3(-311, 31, 0);
RoundImg[4].transform.localPosition = new Vector3(228, 160, 0);
}
private void OnDisable()
{
//隐藏是 设置为未旋转状态
isRotateDirection = 3;
_currentFrame = 0;
video.Control.Seek(0);
}
}
我这里使用了 AVPro 视频插件
和 EasyTouch插件