| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 | 
							- using UnityEngine;
 
- using UnityEngine.UI;
 
- using UnityEngine.Video;
 
- using YooAsset;
 
- using GFGGame.Launcher;
 
- using System.Collections;
 
- namespace GFGGame
 
- {
 
-     public class UICGView : SingletonMonoBase<UICGView>
 
-     {
 
-         private const float VideoWidth = 1920f;
 
-         private const float VideoHeight = 1080f;
 
-         private GameObject _ui;
 
-         private AssetOperationHandle handle;
 
-         private RawFileOperationHandle videoHandle;
 
-         private RawImage imgVideo;
 
-         private Button BtnFullScreen;
 
-         private Button BtnSkipVertical;
 
-         private Button BtnSkipHorizontal;
 
-         private VideoPlayer videoPlayer;
 
-         public void Show()
 
-         {
 
-             MusicManager.Instance.Stop();
 
-             string path = ResPathUtil.GetUUIPrefabPath("UICG");
 
-             handle = YooAssets.LoadAssetSync<GameObject>(path);
 
-             _ui = handle.InstantiateSync(UGUIManager.Instance.desktop.transform);
 
-             imgVideo = _ui.transform.Find("ImgVideo").GetComponent<RawImage>();
 
-             Vector2 imgVideoSizeDelta = imgVideo.rectTransform.sizeDelta;
 
-             imgVideoSizeDelta.x = Screen.width;
 
-             imgVideoSizeDelta.y = (VideoHeight / VideoWidth) * imgVideoSizeDelta.x;
 
-             imgVideo.rectTransform.sizeDelta = imgVideoSizeDelta;
 
-             
 
-             BtnFullScreen = _ui.transform.Find("BtnFullScreen").GetComponent<Button>();
 
-             RectTransform rectbtnFullScreen = BtnFullScreen.GetComponent<RectTransform>();
 
-             Vector2 buttonSizeDelta = rectbtnFullScreen.sizeDelta;
 
-             Vector2 anchoredPosition = rectbtnFullScreen.anchoredPosition;
 
-             anchoredPosition.y = -imgVideoSizeDelta.y / 2 - buttonSizeDelta.y;
 
-             rectbtnFullScreen.anchoredPosition = anchoredPosition;
 
-             BtnFullScreen.onClick.AddListener(OnClickBtnFullScreen);
 
-             BtnSkipVertical = _ui.transform.Find("BtnSkipVertical").GetComponent<Button>();
 
-             RectTransform rectBtnSkipVertical = BtnSkipVertical.GetComponent<RectTransform>();
 
-             anchoredPosition = rectBtnSkipVertical.anchoredPosition;
 
-             anchoredPosition.y = rectbtnFullScreen.anchoredPosition.y;
 
-             rectBtnSkipVertical.anchoredPosition = anchoredPosition;
 
-             BtnSkipVertical.onClick.AddListener(OnClickrectBtnSkip);
 
-             BtnSkipHorizontal = _ui.transform.Find("BtnSkipHorizontal").GetComponent<Button>();
 
-             BtnSkipHorizontal.gameObject.SetActive(false);
 
-             BtnSkipHorizontal.onClick.AddListener(OnClickrectBtnSkip);
 
-             videoPlayer = _ui.transform.Find("VideoPlayer").GetComponent<VideoPlayer>();
 
-             videoPlayer.loopPointReached += OnVideoEnded;
 
-             videoPlayer.prepareCompleted += OnVideoPrepared;
 
-             string assetPath = ResPathUtil.GetVideoPath("cg");
 
-             videoHandle = YooAssets.LoadRawFileSync(assetPath);
 
-             videoPlayer.url = videoHandle.GetRawFilePath();
 
-             videoPlayer.Play();
 
-             
 
-         }
 
-         private void OnVideoPrepared(VideoPlayer source)
 
-         {
 
-             videoPlayer.prepareCompleted -= OnVideoPrepared;
 
-             StartCoroutine(FadeButtonOverTime(BtnFullScreen));
 
-             StartCoroutine(FadeButtonOverTime(BtnSkipVertical));
 
-             StartCoroutine(FadeButtonOverTime(BtnSkipHorizontal));
 
-         }
 
-         IEnumerator FadeButtonOverTime(Button btn)
 
-         {
 
-             Image buttonImage = btn.GetComponent<Image>();
 
-             //Image img = btn.GetComponentInChildren<Image>();
 
-             yield return new WaitForSeconds(39 - 3f);
 
-             if (buttonImage != null)
 
-             {
 
-                 // 获取初始颜色
 
-                 Color startColor = buttonImage.color;
 
-                 //Color startColorText = img.color;
 
-                 // 目标颜色,透明度设为 0
 
-                 Color targetColor = new Color(startColor.r, startColor.g, startColor.b, 0f);
 
-                 //Color targetColorText = new Color(startColorText.r, startColorText.g, startColorText.b, 0f);
 
-                 float fadeDuration = 1f;
 
-                 // 记录开始时间
 
-                 float startTime = Time.time;
 
-                 while (Time.time - startTime < fadeDuration)
 
-                 {
 
-                     // 在一定时间内逐渐插值颜色
 
-                     float t = (Time.time - startTime) / fadeDuration;
 
-                     buttonImage.color = Color.Lerp(startColor, targetColor, t);
 
-                     //img.color = Color.Lerp(startColorText, targetColorText, t);
 
-                     yield return null; // 等待下一帧
 
-                 }
 
-                 // 设置最终颜色,确保透明度为 0
 
-                 buttonImage.color = targetColor;
 
-                 //img.color = targetColorText;
 
-             }
 
-         }
 
-         private void OnVideoEnded(VideoPlayer source)
 
-         {
 
-             this.Hide();
 
-         }
 
-         private void OnClickrectBtnSkip()
 
-         {
 
-             Hide();
 
-         }
 
-         private void OnClickBtnFullScreen()
 
-         {
 
-             BtnSkipVertical.gameObject.SetActive(false);
 
-             BtnSkipHorizontal.gameObject.SetActive(true);
 
-             BtnFullScreen.gameObject.SetActive(false);
 
-             imgVideo.rectTransform.localRotation = Quaternion.Euler(0, 0, -90);
 
-             Vector2 imgVideoSizeDelta = imgVideo.rectTransform.sizeDelta;
 
-             imgVideoSizeDelta.y = Screen.width;
 
-             imgVideoSizeDelta.x = (VideoWidth / VideoHeight) * imgVideoSizeDelta.y;
 
-             imgVideo.rectTransform.sizeDelta = imgVideoSizeDelta;
 
-             if(videoPlayer.time <= 3)
 
-             {
 
-                 videoPlayer.Stop();
 
-                 videoPlayer.Play();
 
-             }
 
-             RectTransform rectBtnSkipVertical = BtnSkipHorizontal.GetComponent<RectTransform>();
 
-             Vector2 anchoredPosition = rectBtnSkipVertical.anchoredPosition;
 
-             anchoredPosition.y = (Screen.height - imgVideoSizeDelta.x)/2 + rectBtnSkipVertical.sizeDelta.x/2;
 
-             rectBtnSkipVertical.anchoredPosition = anchoredPosition;
 
-         }
 
-         public void Hide()
 
-         {
 
-             StopAllCoroutines();
 
-             videoPlayer.Stop();
 
-             videoPlayer.loopPointReached -= OnVideoEnded;
 
-             handle.Release();
 
-             handle = null;
 
-             videoHandle.Release();
 
-             videoHandle = null;
 
-             GameObject.Destroy(_ui);
 
-             _ui = null;
 
-             StoryController.ShowLevelView(100001001);
 
-         }
 
-     }
 
- }
 
 
  |