using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Kill.Network; using Kill.Managers; namespace Kill.UI.Pages { public class VideoUIItem : MonoBehaviour { public Text timeText; public Image videoImage; public Text data; /// 视频项:未下载时显示下载按钮(prefab 内挂载) public Button downloadButton; /// 视频项:已下载时显示播放按钮(prefab 内挂载) public Button playButton; /// 下载进度条底色(显示/隐藏用) public Image loadingImage; /// 亮色进度条(loadingImage 的子物体,Image type=Filled,进度填充到它身上) public Image fillLoadingImage; public string videoUrl; bool isVideo = false; private Image FillBar => fillLoadingImage != null ? fillLoadingImage : loadingImage; /// 显示/隐藏下载进度条,开始时归零;下载中隐藏 下载/播放 按钮,完成后由 RefreshButtons 恢复 public void ShowDownloading(bool show) { if (loadingImage != null) loadingImage.gameObject.SetActive(show); var bar = FillBar; if (show && bar != null) bar.fillAmount = 0f; // 下载期间收起 下载/播放 按钮,只留进度条 if (downloadButton != null) downloadButton.gameObject.SetActive(false); if (playButton != null) playButton.gameObject.SetActive(false); } /// 用下载进度刷新亮色条 fillAmount(0~1),并在完成时隐藏底色 public void UpdateDownloadProgress(bool done, Kill.Network.DownloadProgress progress) { if (done) { if (loadingImage != null) loadingImage.gameObject.SetActive(false); return; } var bar = FillBar; if (bar == null) return; float pct = progress != null ? progress.ProgressPercentage : 0f; bar.fillAmount = Mathf.Clamp01(pct / 100f); } public void Init(DateTime time,string path="",float angle=0,float dis=0) { timeText.text = time.ToString("yyyy-MM-dd HH:mm:ss"); if(path!="") { videoImage.gameObject.SetActive(true); //NetworkCtrl.Instance.LoadImageToUIImageAsync(path, videoImage); data.text=""; } else { int type=DataManager.Instance.userInfo.unit_system; string disStr=""; if(type==0) { disStr=dis.ToString("f1")+"m"; } else { int lensFt=Mathf.RoundToInt((float)(dis * 3.28084)); disStr=lensFt+"ft"; } videoImage.gameObject.SetActive(false); data.text=$"{angle}° {disStr}"; } } /// /// 视频项专用:绑定 url 与 下载/播放 两个按钮的回调 /// /// 视频源 url(.mp4 或 .h264) /// 点下载按钮 /// 点播放按钮 public void SetupVideo(string url, UnityEngine.Events.UnityAction onDownload, UnityEngine.Events.UnityAction onPlay) { videoUrl = url; isVideo = true; if (downloadButton != null) { downloadButton.onClick.RemoveAllListeners(); downloadButton.onClick.AddListener(onDownload); } if (playButton != null) { playButton.onClick.RemoveAllListeners(); playButton.onClick.AddListener(onPlay); } RefreshButtons(); } /// /// 根据下载状态刷新按钮显示:未下载显下载、已下载显播放;非视频项隐藏两个按钮 /// public void RefreshButtons() { if (downloadButton == null || playButton == null) return; if (!isVideo) { downloadButton.gameObject.SetActive(false); playButton.gameObject.SetActive(false); return; } bool cached = Kill.Video.VideoCacheManager.IsCached(videoUrl); downloadButton.gameObject.SetActive(!cached); playButton.gameObject.SetActive(cached); } } }