using System; using System.Collections; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using UnityEngine.Video; public class ClientWorkMessageResultView2SceneController : MonoBehaviour { public static ClientWorkMessageResultView2SceneController Instance; public GameObject step1Panel; public Button step1NextButton; public GameObject step2Panel; public Button step2NextButton; public Button step2ExitButton; public GameObject step3Panel; public Button step3NextButton; public GameObject step4Panel; public VideoPlayer step4VideoPlayer; public RawImage step4RawImage; public GameObject step5Panel; public VideoPlayer step5VideoPlayer; public RawImage step5RawImage; private void Awake() { Instance = this; } // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { if (step1NextButton) { step1NextButton.onClick.AddListener(step1NextButton_onClicked); } if (step2NextButton) { step2NextButton.onClick.AddListener(step2NextButton_onClicked); } if (step2ExitButton) { step2ExitButton.onClick.AddListener(step2ExitButton_onClicked); } if (step3NextButton) { step3NextButton.onClick.AddListener(step3NextButton_onClicked); } if (step4VideoPlayer != null) { // 設置影片結束事件 step4VideoPlayer.loopPointReached += step4VideoPlayer_onVideoFinished; // 設置影片顯示 if (step4RawImage != null) { step4VideoPlayer.targetTexture = null; step4VideoPlayer.renderMode = VideoRenderMode.RenderTexture; RenderTexture rt = new RenderTexture(1080, 1920, 24); step4VideoPlayer.targetTexture = rt; step4VideoPlayer.isLooping = false; step4RawImage.texture = rt; } } if (step5VideoPlayer != null) { // 設置影片結束事件 step5VideoPlayer.loopPointReached += step5VideoPlayer_onVideoFinished; // 設置影片顯示 if (step5RawImage != null) { step5VideoPlayer.targetTexture = null; step5VideoPlayer.renderMode = VideoRenderMode.RenderTexture; RenderTexture rt = new RenderTexture(1080, 1920, 24); step5VideoPlayer.targetTexture = rt; step5VideoPlayer.isLooping = false; step5RawImage.texture = rt; } } processStep(1); } private void step5VideoPlayer_onVideoFinished(VideoPlayer source) { if (ClientMessageHandler.Instance) { ClientMessageHandler.Instance.SendMessageToServer("workProcess", "exit"); } StartCoroutine(LoadExitScene()); } private void step4VideoPlayer_onVideoFinished(VideoPlayer source) { if (ClientMessageHandler.Instance) { ClientMessageHandler.Instance.SendMessageToServer("workProcess", "continue"); } } private void step3NextButton_onClicked() { processStep(4); } private void step2ExitButton_onClicked() { processStep(5); } private void step2NextButton_onClicked() { processStep(3); } private void step1NextButton_onClicked() { processStep(2); } public void processStep(int step) { if (step1Panel) { step1Panel.SetActive(step == 1 ? true : false); } if (step2Panel) { step2Panel.SetActive(step == 2 ? true : false); } if (step3Panel) { step3Panel.SetActive(step == 3 ? true : false); } if (step4Panel) { step4Panel.SetActive(step == 4 ? true : false); if (step == 4) { step4VideoPlayer.Play(); } } if (step5Panel) { step5Panel.SetActive(step == 5 ? true : false); if (step == 5) { step5VideoPlayer.Play(); } } } public IEnumerator LoadExitScene() { yield return new WaitForSeconds(0f); SceneManager.LoadScene("ClientWorkMessageResultExitScene"); } // Update is called once per frame void Update() { } }