Petition-to-the-Gods-V3/Assets/Scripts/Client/ClientWorkMessageResultExitSceneController.cs
chiyu.lin 1009485339 fix Q23
串接頭也不回離開的評分
2025-11-19 19:11:16 +08:00

99 lines
2.7 KiB
C#

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 SurveyManager surveyManager;
private void Awake()
{
Instance = this;
surveyManager = step1Panel.GetComponentInChildren<SurveyManager>(includeInactive: true);
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
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);
surveyManager.OnSurveyConfirmed = OnSurveyConfirmed;
}
private void OnSurveyConfirmed(int val1, int val2, int val3, string text)
{
if (ClientMessageHandler.Instance)
{
GameMessageSurvey msgObj = new GameMessageSurvey {
val1 = val1,
val2 = val2,
val3 = val3,
text1 = text
};
string payload = JsonUtility.ToJson(msgObj);
ClientMessageHandler.Instance.SendMessageToServer("gameSurvey", payload);
}
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");
}
}