using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.IO; public class VideoItem : MonoBehaviour { public Text RoomName; public Text Creator; public Text Name; public Text RecoedTime; public Button PlayButton; public Button DelectButton; public VideoData videoData; public Transform VideoRawImage; private Transform TipText; public Transform DelectPanel; // Start is called before the first frame update void Start() { PlayButton.onClick.AddListener(PlayButtonClick); DelectButton.onClick.AddListener(DelectButtonClick); VideoRawImage = GetComponentInParent().transform.Find("VideoRawImagePanel"); TipText= GetComponentInParent().transform.Find("TipText"); DelectPanel= GetComponentInParent().transform.Find("DelectPanel"); } void PlayButtonClick() { if (File.Exists(videoData.Url)) { VideoRawImage.GetComponentInChildren().Url = videoData.Url; VideoRawImage.gameObject.SetActive(true); } else { TipText.gameObject.SetActive(true); StartCoroutine(closeTip()); } } void DelectButtonClick() { DelectPanel.GetComponent().VideoItem = this.gameObject; DelectPanel.gameObject.SetActive(true); } public void Set(VideoData data) { videoData = data; RoomName.text = data.RoomName; Creator.text = data.Creator; Name.text = data.Name; RecoedTime.text = data.RecoedTime; string path = data.Url.Replace(".mp4",".png"); GetSprit(path); } IEnumerator closeTip() { yield return new WaitForSeconds(1f); TipText.gameObject.SetActive(false); } private void GetSprit(string path) { StartCoroutine(Load(path)); } IEnumerator Load(string path) { Debug.Log(path); WWW www = new WWW(path); yield return www; if (!string.IsNullOrEmpty(www.error)) { Debug.Log(www.error); } else { if (www.isDone) { Texture2D tex = www.texture; GetComponent().sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero); } } } }