165 lines
3.9 KiB
C#
165 lines
3.9 KiB
C#
using DG.Tweening;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using UnityEngine.Video;
|
||
|
||
public class FuTiManager : MonoBehaviour
|
||
{
|
||
public static FuTiManager Instance;
|
||
|
||
[Header("被移动的屏幕")]
|
||
public RectTransform MoveCanvas;
|
||
|
||
[Header("被移动的摄像机")]
|
||
public Transform MoveCamera;
|
||
|
||
[Header("移动速度")]
|
||
public float CanvasSpeed = 5f; // 屏幕移动速度
|
||
public float CameraSpeed = 5f; //摄像机移动速度
|
||
|
||
[Header("屏幕移动限制,0是左,1是右")]
|
||
public float[] CanvasMaxValues;
|
||
|
||
[Header("摄像机移动限制,0是左,1是右")]
|
||
public float[] CameraMaxValues;
|
||
|
||
private bool isLeft = false;
|
||
private bool isRight = false;
|
||
|
||
[Header("所有页面")]
|
||
public GameObject[] AllPages;
|
||
private int m_curPageNum = 0;
|
||
|
||
[Header("爆炸摄像机")]
|
||
public Transform CameraObj;
|
||
//爆炸摄像机最佳位置
|
||
public Transform tarPos;
|
||
//爆炸摄像机移动初始位置
|
||
public Transform moveStartPos;
|
||
public float duration = 2f;
|
||
public bool IsCanMove=false;
|
||
|
||
[Header("所有视频播放器")]
|
||
public VideoPlayer[] AllVideos;
|
||
|
||
private void Awake()
|
||
{
|
||
Instance = this;
|
||
}
|
||
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
|
||
}
|
||
|
||
// Update is called once per frame
|
||
void Update()
|
||
{
|
||
HandleBridgeMovement();
|
||
}
|
||
|
||
void HandleBridgeMovement()
|
||
{
|
||
// 左箭头/右箭头 或按钮控制屏幕左右
|
||
float input = 0f;
|
||
|
||
// 键盘输入
|
||
if (Input.GetKey(KeyCode.LeftArrow))
|
||
input -= 1f;
|
||
if (Input.GetKey(KeyCode.RightArrow))
|
||
input += 1f;
|
||
|
||
// 按钮输入
|
||
if (isRight)
|
||
input += 1f;
|
||
if (isLeft)
|
||
input -= 1f;
|
||
|
||
// 限制输入范围,避免超速
|
||
input = Mathf.Clamp(input, -1f, 1f);
|
||
|
||
Vector2 newCanvasPos = MoveCanvas.anchoredPosition + new Vector2(1,0) * input * CanvasSpeed * Time.deltaTime;
|
||
newCanvasPos.x = Mathf.Clamp(newCanvasPos.x, CanvasMaxValues[0], CanvasMaxValues[1]);
|
||
MoveCanvas.anchoredPosition = newCanvasPos;
|
||
|
||
Vector3 newCameraPos = MoveCamera.position + Vector3.right * input * CameraSpeed * Time.deltaTime;
|
||
newCameraPos.x = Mathf.Clamp(newCameraPos.x, CameraMaxValues[0], CameraMaxValues[1]);
|
||
MoveCamera.position = newCameraPos;
|
||
}
|
||
|
||
public void StartMoveToLeft()
|
||
{
|
||
isLeft = true;
|
||
Debug.Log("点击到了");
|
||
}
|
||
public void StopMoveToLeft()
|
||
{
|
||
isLeft = false;
|
||
}
|
||
|
||
public void StartMoveToRight()
|
||
{
|
||
isRight = true;
|
||
}
|
||
public void StopMoveToRight()
|
||
{
|
||
isRight = false;
|
||
}
|
||
|
||
public void ToOpenPage(int pageNum)
|
||
{
|
||
if(m_curPageNum!=pageNum)
|
||
{
|
||
AllPages[pageNum].SetActive(true);
|
||
AllPages[m_curPageNum].SetActive(false);
|
||
m_curPageNum=pageNum;
|
||
|
||
if (m_curPageNum == 5)
|
||
{
|
||
QuizSystem.Instance.ToStartQuestion();
|
||
}
|
||
}
|
||
}
|
||
|
||
public void ToCameraMoveToBestPos()
|
||
{
|
||
CameraObj.transform.DOMove(tarPos.position, duration);
|
||
CameraObj.transform.DORotateQuaternion(tarPos.rotation, duration);
|
||
}
|
||
|
||
public void ToReturnCameraPos()
|
||
{
|
||
CameraObj.transform.DOMove(MoveCamera.position, duration);
|
||
CameraObj.transform.DORotateQuaternion(MoveCamera.rotation, duration).OnComplete(()=>{
|
||
//结束后回到首页
|
||
ToOpenPage(0);
|
||
})
|
||
;
|
||
}
|
||
|
||
public void ToCameraMoveToStartPos()
|
||
{
|
||
CameraObj.transform.DOMove(moveStartPos.position, duration);
|
||
CameraObj.transform.DORotateQuaternion(moveStartPos.rotation, duration).OnComplete(() => {
|
||
IsCanMove = true;
|
||
})
|
||
;
|
||
}
|
||
|
||
|
||
public void ToStartVideo(int videoNum)
|
||
{
|
||
AllVideos[videoNum].Play();
|
||
}
|
||
|
||
public void ToEndVideo(int videoNum)
|
||
{
|
||
AllVideos[videoNum].time = 0;
|
||
AllVideos[videoNum].Stop();
|
||
}
|
||
}
|