1蛔添、觸控屏上左右滑動翻頁
/*****************************
* Title:
* Date: 2023.01.01
* Author: 玄策
* UnityVersion: 2019.4.28
* Func:
*
****************************/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using UnityEngine.Video;
public class Test : MonoBehaviour
{
public Transform[] Trs;
public int Index;
bool isPress;
private void Awake()
{
//鎖定最大幀率為60幀
//Application.targetFrameRate = 60;
}
void Start()
{
//將子物體加入集合
Trs = new Transform[transform.childCount];
for (int i = 0; i < transform.childCount; i++)
{
Trs[i] = transform.GetChild(i);
}
//初始
Trs[0].GetComponent<VideoPlayer>().Play();
for (int i = 1; i < Trs.Length; i++)
{
Trs[i].gameObject.SetActive(false);
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.A) && Index < Trs.Length -1 && !isPress)
{
isPress = true;
Debug.Log("往左滑動");
//中間視頻往左
Trs[Index].DOLocalMoveX(-1920, 1f).SetEase(Ease.OutBack).OnComplete(
() =>
{
Trs[Index - 1].gameObject.SetActive(false);
isPress = false;
});
Trs[Index].GetComponent<VideoPlayer>().Stop();
//右邊視頻往左
Trs[Index + 1].gameObject.SetActive(true);
Trs[Index + 1].localPosition = new Vector3(1920, 0, 0);
Trs[Index + 1].DOLocalMoveX(0, 1f).SetEase(Ease.OutBack);
Trs[Index + 1].GetComponent<VideoPlayer>().Play();
Index++;
}
if(Input.GetKeyDown(KeyCode.D) && Index > 0 && !isPress)
{
isPress = true;
Debug.Log("往右滑動");
//中間視頻往右
Trs[Index].DOLocalMoveX(1920, 1f).SetEase(Ease.OutBack).OnComplete(
() =>
{
Trs[Index + 1].gameObject.SetActive(false);
isPress = false;
}); ;
Trs[Index].GetComponent<VideoPlayer>().Stop();
//左邊視頻往右
Trs[Index - 1].gameObject.SetActive(true);
Trs[Index - 1].localPosition = new Vector3(-1920, 0, 0);
Trs[Index - 1].DOLocalMoveX(0, 1f).SetEase(Ease.OutBack);
Trs[Index - 1].GetComponent<VideoPlayer>().Play();
Index--;
}
}
}
2戚长、左右按鈕控制翻頁
/*****************************
* Title:
* Date: 2023.01.01
* Author: 玄策
* UnityVersion: 2022.3.0
* Func:
*
****************************/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PageChange : MonoBehaviour
{
public List<Transform> _listTr; //翻頁面集合
int Index; //翻頁面Index
public Button BtnUpPage, BtnNextPage; //上下翻頁按鈕
void Start()
{
BtnUpPage.onClick.AddListener(UpPage);
BtnNextPage.onClick.AddListener(NextPage);
}
private void Update()
{
if (Index == 0)
{
BtnUpPage.interactable = false;
}
else if (Index == _listTr.Count - 1)
{
BtnNextPage.interactable = false;
}
else
{
BtnUpPage.interactable = true;
BtnNextPage.interactable = true;
}
}
void UpPage()
{
if (Index > 0)
{
_listTr[Index].gameObject.SetActive(false);
_listTr[Index - 1].gameObject.SetActive(true);
Index--;
}
}
void NextPage()
{
if (Index < _listTr.Count - 1)
{
_listTr[Index].gameObject.SetActive(false);
_listTr[Index + 1].gameObject.SetActive(true);
Index++;
}
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者