using SuperScrollView; using UnityEngine; using UnityEngine.UI; using UniRx; public class XLogUIView : UIView { public LoopListView2 XLogLoopListView; public Toggle Log; public Text LogsText; public Toggle Warning; public Text WarningsText; public Toggle Error; public Text ErrorsText; public Button ClearButton; public Button CloseButton; bool isOtherColor = false; private XLogPresenter presenter; public override UIViewType ViewType { get { return UIViewType.Normal; } } private void Awake() { // 初始化ScrollView XLogLoopListView.InitListView(0, OnGetItemByIndex); // 关闭按钮 CloseButton.OnClickAsObservable() .Subscribe(x => Hide()) .AddTo(this); // 清空按钮 ClearButton.OnClickAsObservable() .Subscribe(x => { presenter.ClearLogs(); XLogLoopListView.RefreshAllShownItem(); }) .AddTo(this); // Log筛选 Log.OnValueChangedAsObservable() .Subscribe(x => { presenter.ShowLog(x); //XLogLoopListView.RefreshAllShownItem(); }) .AddTo(this); // 警告筛选 Warning.OnValueChangedAsObservable() .Subscribe(x => { presenter.ShowWarning(x); //XLogLoopListView.RefreshAllShownItem(); }) .AddTo(this); // 错误筛选 Error.OnValueChangedAsObservable() .Subscribe(x => { presenter.ShowError(x); //XLogLoopListView.RefreshAllShownItem(); }) .AddTo(this); // 刷新数量 presenter.ShowLogs .ObserveCountChanged() .Subscribe(x => XLogLoopListView.SetListItemCount(x, false)) .AddTo(this); // Log数量 presenter.LogsCount .SubscribeToText(LogsText) .AddTo(this); // 警告数量 presenter.WarningsCount .SubscribeToText(WarningsText) .AddTo(this); // 错误数量 presenter.ErrorsCount .SubscribeToText(ErrorsText) .AddTo(this); } public void SetPresenter(XLogPresenter p) { presenter = p; } private LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index) { if (presenter.ShowLogs.Count == 0) { return null; } //创建Item LoopListViewItem2 item = listView.NewListViewItem("XLogItem"); //获取数据 XLog itemData = presenter.ShowLogs[index]; ////设置是否可见 //RectTransform rt = item.gameObject.GetComponent(); //if (itemData.IsShow) //{ // item.gameObject.SetActive(true); // rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 40f); //获取子页面 XLogItem itemScript = item.GetComponent(); //初始化子页面 if (item.IsInitHandlerCalled == false) { item.IsInitHandlerCalled = true; itemScript.Init(); } //设置Item颜色 isOtherColor = !isOtherColor; if (isOtherColor) { itemScript.Background.color = new Color32(200, 200, 200, 255); } else { itemScript.Background.color = new Color32(255, 255, 255, 255); } //设置子页面数据 itemScript.SetItemData(itemData, index); //} //else //{ // rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 0f); // item.gameObject.SetActive(false); //} return item; } public override void Refresh() { base.Refresh(); XLogLoopListView.SetListItemCount(presenter.ShowLogs.Count); } }