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; namespace ShadowStudio.Model { public class VideoComponent : UIComponent { private bool isMove; private Vector3 imageScale; private RenderTexture videoTexture; private XRVideoPlayer moviesPlayer; public float clickTime = 0.2f; private float pressTime; // 临时局域网版本用 PlayeBtn PauseBtn public SCButton PlayeBtn; public SCButton PauseBtn; public RenderTexture VideoTexture { get => videoTexture; set => videoTexture = value; } public XRVideoPlayer MoviesPlayer { get { if (!moviesPlayer) { //moviesPlayer = UnityUtil.GetBreadthChild(Dlg.FullUIRoot, "XRVideoPlayer"); moviesPlayer = GetComponent(); } return moviesPlayer; } } 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; } MoviesPlayer.VideoPlayer.url = targetUrl; } else if (art is VideoClip) { MoviesPlayer.VideoPlayer.clip = art as VideoClip; } 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().offsetMax = Vector2.zero; this.GetComponent().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.VideoPlayer.isPlaying) { PauseVideo(); } else { PlayVideo(); } } } public void PlayVideo(bool isSend = true) { if (!MoviesPlayer.VideoPlayer.isPlaying) { MoviesPlayer.Pause.transform.DOScale(imageScale * 1.1f, 0.3f).OnComplete(() => { MoviesPlayer.Pause.transform.localScale = Vector3.zero; }).OnKill(() => { MoviesPlayer.Pause.transform.localScale = Vector3.zero; }); MoviesPlayer.VideoPlayer.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.VideoPlayer.isPlaying) { MoviesPlayer.Pause.transform.localScale = imageScale * 1.1f; MoviesPlayer.Pause.transform.DOScale(imageScale, 0.3f).OnComplete(() => { MoviesPlayer.Pause.transform.localScale = imageScale; }).OnKill(() => { MoviesPlayer.Pause.transform.localScale = imageScale; }); MoviesPlayer.VideoPlayer.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(); } } }