loudixvmuniu/Assets/_Scripts/Application/UI/ThreeVideoChoicePrefab.cs
2025-01-09 18:12:40 +08:00

77 lines
3.2 KiB
C#

using CG.Framework;
using CG.UTility;
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
/*******************************************************************************
*Create By CG
*Function
*******************************************************************************/
namespace ZXK.LouDiXvMuNiu
{
public class ThreeVideoChoicePrefab : UIBase
{
private Text _answerText = null;
private Transform _videoItemContainer = null;
private Button _closeBtn = null;
protected override void Awake()
{
base.Awake();
_answerText = transform.Find("Mask/Connet/AnswerText").GetComponent<Text>();
_videoItemContainer = transform.Find("Mask/Connet/QuestionsConnet");
_closeBtn= transform.Find("Mask/Connet/CloseButton").GetComponent<Button>();
}
/// <summary>
/// 弹出选择题界面(奇数个选项)
/// </summary>
/// <param name="question"></param>
/// <param name="answer"></param>
/// <param name="rightNumber"></param>
/// <param name="isSelAble">选项是否可选</param>
/// <param name="configBtnEvent"></param>
public void InitQuestionPanel(string question, string[] videosPath,string[] tipMsg, int rightNumber, bool selAble, System.Action configBtnEvent)
{
question = question.Replace("\u0020", "\u00A0");
_answerText.text = question;
for (int i = 0; i < _videoItemContainer.childCount; i++)
{
if (i < videosPath.Length)
{
string _videoPath = Application.streamingAssetsPath + ConstCtrl.VIDEO_CSDY_PATH + videosPath[i] + ".mp4";
_videoItemContainer.GetChild(i).gameObject.SetActive(true);
VideoPlayer videoPlayCtrl = _videoItemContainer.GetChild(i).Find("Video Player").GetComponent<VideoPlayer>();
videoPlayCtrl.url = _videoPath;
_videoItemContainer.GetChild(i).Find("Text").GetComponent<Text>().text = tipMsg[i];
videoPlayCtrl.Play();
_videoItemContainer.GetChild(i).GetComponent<Toggle>().interactable = selAble;
}
else
{
_videoItemContainer.GetChild(i).gameObject.SetActive(false);
}
}
_closeBtn.onClick.AddListener(() =>
{
if (!_videoItemContainer.GetChild(rightNumber).GetComponent<Toggle>().isOn)
{
_videoItemContainer.GetChild(0).GetComponent<Toggle>().isOn = false;
_videoItemContainer.GetChild(1).GetComponent<Toggle>().isOn = false;
_videoItemContainer.GetChild(2).GetComponent<Toggle>().isOn = false;
}
Image rightImg = _videoItemContainer.GetChild(rightNumber).Find("Selected").GetComponent<Image>();
rightImg.DOFade(1.0f,1.0f).SetLoops(6, LoopType.Yoyo).OnComplete(() =>
{
configBtnEvent?.Invoke();
});
});
transform.SetAsLastSibling();
}
}
}