using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Kill.UI.Components; using Kill.UI; using System.Threading.Tasks; using System; using Kill.Network; using Kill.Managers; using UnityEngine.Video; using System.IO; namespace Kill.UI.Pages { public class VideoPageCtrl : MonoBehaviour { public class Videodata { public string videoUrl; public string coverUrl; public DateTime time; } public class KillData { public DateTime time; public float angle; public float dis; } public Button backBtn; public VerticalScrollLoader scrollLoader; public VideoUIItem videoUIItemPrefab; public Transform content; int totalCount=0; List videoList = new List(); private int currentPage = 1; private bool isLoading = false; private bool hasMoreData = true; public GameObject noTip; void Start() { backBtn.onClick.RemoveAllListeners(); backBtn.onClick.AddListener(Back); UIManager.Instance.RegisterBackAction(Back); ChangeType(0); } public Button[] changeTypeButtons; public void ChangeType(int type) { if(videoList!=null) { foreach(var g in videoList) { Destroy(g); } videoList.Clear(); } videoList=new List(); changeTypeButtons[type].interactable = false; changeTypeButtons[type].transform.Find("选中").gameObject.SetActive(true); changeTypeButtons[1-type].interactable = true; changeTypeButtons[1-type].transform.Find("选中").gameObject.SetActive(false); if (type == 0) { // 设置滚动加载阈值 if (scrollLoader != null) { scrollLoader.onLoadTriggered.AddListener(OnScrollToLoadKill); scrollLoader.ResetLoader(); } currentPage = 1; hasMoreData = true; totalCount=0; GetKillDataList(); } else { // 设置滚动加载阈值 if (scrollLoader != null) { scrollLoader.onLoadTriggered.AddListener(OnScrollToLoadVideo); scrollLoader.ResetLoader(); } currentPage = 1; hasMoreData = true; totalCount=0; GetVideoList(); } } public void Back() { UIManager.Instance.OpenMainPage(UIManager.PageName.homePage); } public async Task GetVideoList() { isLoading = true; LoadingUI.Show(); string url = $"/api/v1/stats/device/videos?device_sn={DataManager.Instance.selectedDevice.ble_mac}&page={currentPage}&page_size=30"; var response = await NetworkCtrl.Instance.Get(url); LoadingUI.Hide(); ResponseCodeHandler.HandleResponse(response, onSuccess: (data) => { if(data.data.total>0) { noTip.SetActive(false); } else { noTip.SetActive(true); } isLoading = false; if (data.data.list != null && data.data.list.Count > 0) { foreach (var item in data.data.list) { Videodata vd = new Videodata() { time = item.record_time, videoUrl = item.video_url, coverUrl=item.cover_url }; CreateVideoItem(vd); totalCount++; } if(totalCount>=data.data.total) { hasMoreData = false; scrollLoader?.SetAllDataLoaded(); } else { hasMoreData = true; scrollLoader?.OnLoadComplete(); } } }, onError: null ); } public async Task GetKillDataList() { isLoading = true; LoadingUI.Show(); string url = $"/api/v1/stats/device/records?device_sn={DataManager.Instance.selectedDevice.ble_mac}&type=1&page={currentPage}&page_size=30"; var response = await NetworkCtrl.Instance.Get(url); LoadingUI.Hide(); ResponseCodeHandler.HandleResponse(response, onSuccess: (data) => { if(data.data.total>0) { noTip.SetActive(false); } else { noTip.SetActive(true); } isLoading = false; if (data.data.records != null && data.data.records.Count > 0) { foreach (var item in data.data.records) { KillData kd = new KillData() { time = item.time, angle = item.angle, dis=item.distance }; CreateKillItem(kd); totalCount++; } Debug.Log(totalCount); if(totalCount>=data.data.total) { hasMoreData = false; scrollLoader?.SetAllDataLoaded(); } else { hasMoreData = true; scrollLoader?.OnLoadComplete(); } } }, onError: null ); } /// /// 滚动到指定位置加载新消息 /// private void OnScrollToLoadKill() { Debug.Log("加载新记录"); if (isLoading || !hasMoreData) return; currentPage++; GetKillDataList(); } private void OnScrollToLoadVideo() { if (isLoading || !hasMoreData) return; currentPage++; GetVideoList(); } /// /// 创建视频UI /// private void CreateVideoItem(Videodata data) { if (videoUIItemPrefab == null || content == null) return; var item = Instantiate(videoUIItemPrefab, content); item.GetComponent().Init(data.time, data.coverUrl); item.GetComponent