123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- using Agora.Rtc;
- using BeinLab.Util;
- using DG.Tweening;
- using LitJson;
- using ShadowStudio.Tool;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.Video;
- using XRTool.Util;
- using XRTool.WorldUI;
- using RenderHeads.Media.AVProVideo;
- namespace ShadowStudio.Model
- {
- public class VideoComponent : UIComponent
- {
- private bool isMove;
- private Vector3 imageScale;
- private RenderTexture videoTexture;
- private XRVideoPlayer moviesPlayer;
- public float clickTime = 0.2f;
- public MeshRenderer mVideoRenderer;
- private float pressTime;
- public RenderTexture VideoTexture { get => videoTexture; set => videoTexture = value; }
- public XRVideoPlayer MoviesPlayer
- {
- get
- {
- if (!moviesPlayer)
- {
- //moviesPlayer = UnityUtil.GetBreadthChild<XRVideoPlayer>(Dlg.FullUIRoot, "XRVideoPlayer");
- moviesPlayer = GetComponent<XRVideoPlayer>();
- }
- return moviesPlayer;
- }
- }
- void Start()
- {
- StartCoroutine(PlayerFirstFrame());
- // MoviesPlayer.applyToMesh.Player.MediaPath =
- }
- //public override void DestroyArt()
- //{
- // MoviesPlayer.VideoPlayer.Stop();
- // gameObject.SetActive(false);
- // base.DestroyArt();
- //}
- /// <summary>
- /// 第一次打开加载时无缩略图,为生成缩略图
- /// </summary>
- /// <returns></returns>
- IEnumerator PlayerFirstFrame()
- {
- int temp = 0;
- yield return new WaitForSeconds(2f);
- while (temp < 2)
- {
- playVideoManager();
- temp++;
- }
- }
- private void OnTransferSelect(bool isSelect)
- {
- if (!isSelect)
- {
- MoviesPlayer.hideControl();
- }
- else
- {
- MoviesPlayer.showControl();
- }
- }
- public override void SetContainer(ArtContainerHandler container, Object art, ArtInfo info)
- {
- base.SetContainer(container, art, info);
- if (art == null)
- {
- string targetUrl = info.Url;
- if (!targetUrl.StartsWith("http"))
- {
- targetUrl = ResourcesManager.ArtServerPath + "/" + targetUrl;
- }
- if (!targetUrl.Contains("https"))
- targetUrl = "https" + targetUrl.Substring(4, targetUrl.Length - 4);
- // MoviesPlayer.VideoPlayer.url = targetUrl;
- MoviesPlayer.AVProVideoPlayer.SetUrl(targetUrl);
-
-
- }
- else if (art is VideoClip)
- {
- Debug.Log(art.name);
-
- // MoviesPlayer.VideoPlayer.clip = art as VideoClip;
- MoviesPlayer.AVProVideoPlayer.SetUrl(Application.streamingAssetsPath + "/AVProVideoZYK/" + art.name + ".mp4");
-
- }
- MoviesPlayer.XRSlider.onValueChanged.AddListener(setVidoPlayerTime);
-
- MoviesPlayer.XRSlider.OnSliderDown.AddListener(OnSliderDown);
- MoviesPlayer.XRSlider.OnSliderUp.AddListener(OnSliderUp);
- imageScale = MoviesPlayer.Pause.transform.localScale;
- if (container && container.Transfer)
- {
- container.Transfer.EditTransfer += OnEditTransfer;
- }
- this.GetComponent<RectTransform>().offsetMax = Vector2.zero;
- this.GetComponent<RectTransform>().offsetMin = Vector2.zero;
- }
- private void OnEditTransfer(TransferState state)
- {
- if (state == TransferState.Stop)
- {
- OnTransferSelect(true);
- }
- else if (state == TransferState.Over)
- {
- OnTransferSelect(false);
- }
- }
- void setVidoPlayerTime(float f)
- {
- }
- public void OnSliderDown(PointerEventData eventData)
- {
- MoviesPlayer.isDown = true;
- }
- public void OnSliderUp(PointerEventData eventData)
- {
- MoviesPlayer.sliderChanged(MoviesPlayer.XRSlider.value);
- StopCoroutine(pointerUp(false));
- MoviesPlayer.isDown = true;
- StartCoroutine(pointerUp(true));
- MoviesPlayer.isDown = true;
- }
- IEnumerator pointerUp(bool isSend = true)
- {
- yield return new WaitForSeconds(1f);
- MoviesPlayer.isDown = false;
- if (isSend)
- {
- VideoState("vdFrame", MoviesPlayer.XRSlider.value.ToString());
- SendTransfer(0, (int)TransferState.Stop);
- //sendMessage();
- }
- }
- public void playVideoManager()
- {
- isMove = Time.time - pressTime < clickTime;
- if (!isMove)
- {
- if (MoviesPlayer.AVProVideoPlayer.IsPlaying())
- {
- PauseVideo();
- }
- else
- {
- PlayVideo();
- }
- }
- }
- public void PlayVideo(bool isSend = true)
- {
- if (!MoviesPlayer.AVProVideoPlayer.IsPlaying())
- {
- MoviesPlayer.Pause.transform.DOScale(imageScale * 1.1f, 0.3f).OnComplete<Tween>(() =>
- {
- MoviesPlayer.Pause.transform.localScale = Vector3.zero;
- }).OnKill<Tween>(() =>
- {
- MoviesPlayer.Pause.transform.localScale = Vector3.zero;
- });
- // MoviesPlayer.VideoPlayer.Play();
- MoviesPlayer.AVProVideoPlayer.Play();
- VideoState("vdFrame", MoviesPlayer.XRSlider.value.ToString());
- MoviesPlayer.hideControl();
- }
- if (isSend)
- {
- VideoState("vdPlay", "1");
- //sendMessage();
- SendTransfer(0, (int)TransferState.Stop);
- }
- }
- public void PauseVideo(bool isSend = true)
- {
- if (MoviesPlayer.AVProVideoPlayer.IsPlaying())
- {
- MoviesPlayer.Pause.transform.localScale = imageScale * 1.1f;
- MoviesPlayer.Pause.transform.DOScale(imageScale, 0.3f).OnComplete<Tween>(() =>
- {
- MoviesPlayer.Pause.transform.localScale = imageScale;
- }).OnKill<Tween>(() =>
- {
- MoviesPlayer.Pause.transform.localScale = imageScale;
- });
- // MoviesPlayer.VideoPlayer.Pause();
- MoviesPlayer.AVProVideoPlayer.Pause();
- VideoState("vdFrame", MoviesPlayer.XRSlider.value.ToString());
- }
- if (isSend)
- {
- VideoState("vdPlay", "0");
- //sendMessage();
- SendTransfer(0, (int)TransferState.Stop);
- }
- }
- //public override void SendTransfer(int state, bool isEditting)
- //{
- // base.SendTransfer(state, isEditting);
- //}
- bool isPlay;
- public override void TransferSyn(GoodsInfo goods, bool smooth = true)
- {
- base.TransferSyn(goods, smooth);
- // Debug.Log(goods.goods_extended);
- CheckVideoState(goods.goods_extended);
- // goods.goods_extended
- }
- private void CheckVideoState(string goods_extended)
- {
- try
- {
- JsonData dataInfo = JsonMapper.ToObject(goods_extended);
- if (dataInfo != null)
- {
- if (dataInfo.Keys.Contains("vdPlay"))
- {
- if (dataInfo["vdPlay"].ToString() == "1")
- {
- isPlay = true;
- PlayVideo(false);
- }
- else
- {
- isPlay = false;
- PauseVideo(false);
- }
- }
- if (dataInfo.Keys.Contains("vdFrame"))
- {
- if (Mathf.Abs(MoviesPlayer.XRSlider.value - float.Parse(dataInfo["vdFrame"].ToString())) > 0.01f)
- {
- StartCoroutine(pointerUp(false));
- MoviesPlayer.isDown = true;
- MoviesPlayer.XRSlider.value = float.Parse(dataInfo["vdFrame"].ToString());
- MoviesPlayer.sliderChanged(MoviesPlayer.XRSlider.value);
- }
- }
- }
- }
- catch
- {
- }
- }
- void VideoState(string type, string info)
- {
- JsonData dataInfo = new JsonData();
- try
- {
- dataInfo = JsonMapper.ToObject(Container.data.goods_extended);
- }
- catch
- {
- }
- dataInfo[type] = info;
- Container.data.goods_extended = dataInfo.ToJson();
- }
- }
- }
|