155 lines
4.3 KiB
C#
155 lines
4.3 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.IO;
|
||
|
using UnityEngine.UI;
|
||
|
using TMPro;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.Networking;
|
||
|
using UnityEngine.Video;
|
||
|
|
||
|
namespace HK
|
||
|
{
|
||
|
public class HomeUI : UIBase
|
||
|
{
|
||
|
[SerializeField] private RawImage rawVideo;
|
||
|
[SerializeField] private Button btnNext;
|
||
|
[SerializeField] private Button btnENG;
|
||
|
[SerializeField] private Button btnChin;
|
||
|
[SerializeField] private Button btnSetting;
|
||
|
[SerializeField] private Button btnClose;
|
||
|
[SerializeField] private List<string> videoClips;
|
||
|
|
||
|
VideoPlayer player;
|
||
|
|
||
|
public override void OnInit()
|
||
|
{
|
||
|
base.OnInit();
|
||
|
|
||
|
#region AutoGen_Init
|
||
|
|
||
|
rawVideo = GetValue<RawImage>("rawVideo");
|
||
|
btnNext = GetValue<Button>("btnNext");
|
||
|
btnENG = GetValue<Button>("btnENG");
|
||
|
btnChin = GetValue<Button>("btnChin");
|
||
|
btnSetting = GetValue<Button>("btnSetting");
|
||
|
btnClose = GetValue<Button>("btnClose");
|
||
|
|
||
|
btnNext.onClick.AddListener(OnClickbtnNext);
|
||
|
btnENG.onClick.AddListener(OnClickbtnENG);
|
||
|
btnChin.onClick.AddListener(OnClickbtnChin);
|
||
|
btnSetting.onClick.AddListener(OnClickbtnSetting);
|
||
|
btnClose.onClick.AddListener(OnClickbtnClose);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
player = rawVideo.GetComponent<VideoPlayer>();
|
||
|
}
|
||
|
|
||
|
public override void OnOpen()
|
||
|
{
|
||
|
base.OnOpen();
|
||
|
StartCoroutine(LoopPlayVideo());
|
||
|
}
|
||
|
|
||
|
public override void OnClose()
|
||
|
{
|
||
|
base.OnClose();
|
||
|
StopCoroutine(LoopPlayVideo());
|
||
|
}
|
||
|
|
||
|
|
||
|
IEnumerator LoopPlayVideo()
|
||
|
{
|
||
|
while (true)
|
||
|
{
|
||
|
foreach (var clip in videoClips)
|
||
|
{
|
||
|
var path = Path.Combine(Application.streamingAssetsPath, clip);
|
||
|
UnityWebRequest www = UnityWebRequest.Get(path);
|
||
|
yield return www.SendWebRequest();
|
||
|
|
||
|
if (!www.isDone)
|
||
|
{
|
||
|
Debug.LogError("Failed to load video: " + www.error);
|
||
|
}
|
||
|
|
||
|
player.url = path;
|
||
|
// player.url = Path.Combine(Environment.CurrentDirectory, clip);
|
||
|
player.Prepare();
|
||
|
|
||
|
// Wait until the video is prepared
|
||
|
while (!player.isPrepared)
|
||
|
{
|
||
|
yield return null;
|
||
|
}
|
||
|
|
||
|
player.Play();
|
||
|
|
||
|
// Wait until the video is done playing
|
||
|
while (player.isPlaying)
|
||
|
{
|
||
|
yield return null;
|
||
|
}
|
||
|
|
||
|
// Release memory
|
||
|
player.Stop();
|
||
|
Resources.UnloadUnusedAssets();
|
||
|
System.GC.Collect();
|
||
|
|
||
|
// Optional delay between clips
|
||
|
yield return new WaitForSeconds(1);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#region AutoGen_Method
|
||
|
|
||
|
private void OnClickbtnNext()
|
||
|
{
|
||
|
UIManager.Instance.ShowUI(nameof(AgreementUI));
|
||
|
UIManager.Instance.HideUI(this);
|
||
|
}
|
||
|
|
||
|
private void OnClickbtnENG()
|
||
|
{
|
||
|
LanguageManager.Instance.ChangeLanguageType(LanguageManager.LanguageType.English);
|
||
|
}
|
||
|
|
||
|
private void OnClickbtnChin()
|
||
|
{
|
||
|
LanguageManager.Instance.ChangeLanguageType(LanguageManager.LanguageType.Chinese);
|
||
|
}
|
||
|
|
||
|
private void OnClickbtnSetting()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
private void OnClickbtnClose()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
public override void OnDispose()
|
||
|
{
|
||
|
base.OnDispose();
|
||
|
|
||
|
#region AutoGen_Dispose
|
||
|
|
||
|
btnNext.onClick.RemoveListener(OnClickbtnNext);
|
||
|
btnENG.onClick.RemoveListener(OnClickbtnENG);
|
||
|
btnChin.onClick.RemoveListener(OnClickbtnChin);
|
||
|
btnSetting.onClick.RemoveListener(OnClickbtnSetting);
|
||
|
btnClose.onClick.RemoveListener(OnClickbtnClose);
|
||
|
|
||
|
rawVideo = null;
|
||
|
btnNext = null;
|
||
|
btnENG = null;
|
||
|
btnChin = null;
|
||
|
btnSetting = null;
|
||
|
btnClose = null;
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
}
|
||
|
}
|