Unity_触摸屏_AvPro序列帧效果(二)

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插件

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值