76 lines
1.7 KiB
C#
76 lines
1.7 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.Video;
|
||
|
||
public class GuoLuManager : MonoBehaviour
|
||
{
|
||
public static GuoLuManager Instance;
|
||
|
||
[Header("所有页面")]
|
||
public GameObject[] AllPages;
|
||
private int m_curPageNum = 0;
|
||
|
||
[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()
|
||
{
|
||
|
||
}
|
||
|
||
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 ToStartVideo(int videoNum)
|
||
{
|
||
AllVideos[videoNum].Play();
|
||
}
|
||
|
||
public void ToEndVideo(int videoNum)
|
||
{
|
||
AllVideos[videoNum].time = 0;
|
||
AllVideos[videoNum].Stop();
|
||
ClearRenderTexture(videoNum);
|
||
}
|
||
|
||
// 清空RenderTexture(填充黑色)
|
||
private void ClearRenderTexture(int num)
|
||
{
|
||
if (AllVideos[num].targetTexture == null) return;
|
||
|
||
// 保存当前激活的RenderTexture,避免影响其他渲染
|
||
RenderTexture currentActiveRT = RenderTexture.active;
|
||
// 激活目标RenderTexture
|
||
RenderTexture.active = AllVideos[num].targetTexture;
|
||
// 用黑色填充(0,0,0,0表示透明,根据需求调整)
|
||
GL.Clear(true, true, Color.black);
|
||
// 恢复之前激活的RenderTexture
|
||
RenderTexture.active = currentActiveRT;
|
||
}
|
||
}
|