using System; using System.Collections; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using UnityEngine.Video; public class ClientWorkMessageResultExitSceneController : MonoBehaviour { public static ClientWorkMessageResultExitSceneController Instance; public GameObject step1Panel; public Button step1SubmitButton; public GameObject step2Panel; public VideoPlayer step2VideoPlayer; public RawImage step2RawImage; private void Awake() { Instance = this; } // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { if (step1SubmitButton) { step1SubmitButton.onClick.AddListener(step1SubmitButton_onClicked); } if (step2VideoPlayer != null) { // 設置影片結束事件 step2VideoPlayer.loopPointReached += step2VideoPlayer_onVideoFinished; // 設置影片顯示 if (step2RawImage != null) { step2VideoPlayer.targetTexture = null; step2VideoPlayer.renderMode = VideoRenderMode.RenderTexture; RenderTexture rt = new RenderTexture(1080, 1920, 24); step2VideoPlayer.targetTexture = rt; step2VideoPlayer.isLooping = false; step2RawImage.texture = rt; } } processStep(1); } private void step1SubmitButton_onClicked() { if (ClientMessageHandler.Instance) { ClientMessageHandler.Instance.SendMessageToServer("workProcess", "survey_ok"); } processStep(2); } private void step2VideoPlayer_onVideoFinished(VideoPlayer source) { StartCoroutine(LoadNextScene()); } public void processStep(int step) { if (step1Panel) { step1Panel.SetActive(step == 1 ? true : false); } if (step2Panel) { step2Panel.SetActive(step == 2 ? true : false); if (step2VideoPlayer != null) { step2VideoPlayer.Play(); } } } // Update is called once per frame void Update() { } public IEnumerator LoadNextScene() { yield return new WaitForSeconds(0f); SceneManager.LoadScene("ClientHomeScene"); } }