123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using RenderHeads.Media.AVProVideo;
- using UnityEngine;
- public class TemplateVideo : BaseTemPlate
- {
- private Navigator.VideoControl m_VideoCtr;
- private AVProVideoPlayer m_Video;
- protected override void OnEnable()
- {
- base.OnEnable();
- //if (GameManager.Instance.IsRuning && string.IsNullOrWhiteSpace(m_VideoCtr.VideoURL))
- //{
- // if (File.Exists(Data.localSavePath))
- // {
- // m_VideoCtr.VideoURL = Data.localSavePath;
- // }
- // else
- // {
- // m_VideoCtr.VideoURL = null;
- // }
- //}
- //m_VideoCtr.m_IsPlaying = false;
- //m_VideoCtr.PlayVideo();
- if (GameManager.Instance.IsRuning && string.IsNullOrWhiteSpace(m_Video.GetUrl()))
- {
- if (File.Exists(Data.localSavePath))
- {
- m_Video.SetUrl(Data.localSavePath);
- }
- else
- {
- m_Video.SetUrl(null);
- }
- }
- m_Video.transform.GetComponent<VideoPlayBtn>().m_IsPlaying = false;
- m_Video.transform.GetComponent<VideoPlayBtn>().PlayVideo();
- setScale = true;
- }
- private MediaPlayer MediaPlayer;
- private bool setScale;
- protected override void OnAwake()
- {
- base.OnAwake();
- // m_VideoCtr = transform.Find("Screen/Video").GetComponent<Navigator.VideoControl>();
- m_Video = transform.Find("Screen/AVideo").GetComponent<AVProVideoPlayer>();
- MediaPlayer = transform.Find("Screen/AVideo").GetComponent<MediaPlayer>();
- HideCollider();
- }
- private void Update()
- {
- if((MediaPlayer.Info.GetVideoHeight()!=0 || MediaPlayer.Info.GetVideoWidth()!=0) && setScale )
- {
- float temp = (float)MediaPlayer.Info.GetVideoHeight() / (float)MediaPlayer.Info.GetVideoWidth();
- MediaPlayer.transform.GetComponent<RectTransform>().sizeDelta = new Vector2(56,56*temp);
- setScale = false;
- }
- }
- public override void SetData(MaterialObjValue value, int updateTime)
- {
- base.SetData(value, updateTime);
- if (!GameManager.Instance.IsRuning)
- {
- DownloadManager.Instance.AddDownloadData(Data);
- }
- else
- {
- if (File.Exists(Data.localSavePath))
- {
- // m_VideoCtr.VideoURL = Data.localSavePath;
- m_Video.SetUrl(Data.localSavePath);
- }
- else
- {
- // m_VideoCtr.VideoURL = null;
- m_Video.SetUrl(null);
- }
- }
- }
- public void SetData(string url)
- {
- Debug.Log(url);
- //if(m_VideoCtr ==null)
- // m_VideoCtr = transform.Find("Screen/Video").GetComponent<Navigator.VideoControl>();
- //m_VideoCtr.VideoURL = url;
- if (m_Video == null)
- m_Video = transform.Find("Screen/AVideo").GetComponent<AVProVideoPlayer>();
- m_Video.SetUrl(url);
- }
- public override void HideCollider()
- {
- base.HideCollider();
- }
- }
|