using System.Collections.Generic; using uMVVM.Sources.Infrastructure; using UnityEngine; using UnityEngine.Serialization; using UnityEngine.UI; namespace Game.MVVM.Model { class HallSceneMallViewStoreData { public MallStoreItem _item; public ScrollRectUpdateView_HallSceneMall _view; public HallSceneMallViewStoreData(MallStoreItem item, ScrollRectUpdateView_HallSceneMall view) { this._item = item; this._view = view; } } public class HallSceneMallView : UnityGuiView { private Dictionary _storeItems = new Dictionary(); private Dictionary _scrollItems = new Dictionary(); public ScrollRectUpdateView_HallSceneMall scrollRectUpdateView; public Transform storeItemParent; public GameObject storeItem; public Button btnBack; protected override void OnInitialize() { base.OnInitialize(); this.storeItem.SetActive(false); btnBack.onClick.AddListener(ClickBack); } private void ClickBack() { BindingContext.OnClickBack?.Invoke(); } public override void OnBindingContextChanged(HallSceneMallViewModel oldValue, HallSceneMallViewModel newValue) { base.OnBindingContextChanged(oldValue, newValue); if (oldValue != null) { oldValue.MallItems.OnValueChanged -= this.MallScrollValueChanged; oldValue.StoreItems.OnValueChanged -= this.MallStoreValueChanged; } if (newValue != null) { newValue.MallItems.OnValueChanged += this.MallScrollValueChanged; newValue.StoreItems.OnValueChanged += this.MallStoreValueChanged; } } private void MallStoreValueChanged(List oldvalue, List newvalue) { BindingContext.StoreItems.Value = newvalue; foreach (var o in this._storeItems.Keys) { GameObject.Destroy(this._storeItems[o]._view.gameObject); GameObject.Destroy(o); } this._storeItems.Clear(); foreach (var mallStoreItem in newvalue) { var instantiate = GameObject.Instantiate(this.storeItem, this.storeItemParent); instantiate.name = mallStoreItem.name; instantiate.SetActive(true); var itemView = instantiate.GetComponent(); itemView.BindingContext = new MallStoreItemViewModel(); itemView.BindingContext.InitData(mallStoreItem); itemView.BindingContext.OnClickTog += OnClickStoreTog; var rectUpdateView = GameObject.Instantiate(this.scrollRectUpdateView, this.scrollRectUpdateView.transform.parent); rectUpdateView.name = mallStoreItem.name; var objects = mallStoreItem.data as List; rectUpdateView.createItemFinish += CreateScrollItemFinish; rectUpdateView.resetAction += ResetScrollItemFinish; rectUpdateView.RefreshInitData(objects); this._storeItems.Add(instantiate, new HallSceneMallViewStoreData(mallStoreItem, rectUpdateView)); } } private void OnClickStoreTog(bool arg1, string arg2, GameObject arg3) { var data = this._storeItems[arg3]; data._view.gameObject.SetActive(arg1); } private void ResetScrollItemFinish(object arg1) { var view = arg1 as ScrollRectUpdateView_HallSceneMall; // 请求服务器获取最新的数据 Debug.Log("--请求服务器获取最新的数据"); // List list = new List(); // view.RefreshInitData(list); } private void CreateScrollItemFinish(GameObject arg1, object arg2) { var mallScrollItem = arg2 as MallScrollItem; var itemView = arg1.GetComponent(); itemView.BindingContext = new MallScrollItemViewModel(); itemView.BindingContext.InitData(mallScrollItem); itemView.BindingContext.OnClickBuy += OnClickBuy; } private void OnClickBuy(string arg1, object arg2) { Debug.Log($"点击了{arg1}"); } private void MallScrollValueChanged(List oldvalue, List newvalue) { } } }