128 lines
4.6 KiB
C#
128 lines
4.6 KiB
C#
|
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<HallSceneMallViewModel>
|
||
|
{
|
||
|
private Dictionary<GameObject, HallSceneMallViewStoreData> _storeItems = new Dictionary<GameObject, HallSceneMallViewStoreData>();
|
||
|
private Dictionary<GameObject, MallScrollItem> _scrollItems = new Dictionary<GameObject, MallScrollItem>();
|
||
|
|
||
|
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<MallStoreItem> oldvalue, List<MallStoreItem> 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<MallStoreItemView>();
|
||
|
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<MallScrollItem>;
|
||
|
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<object> list = new List<object>();
|
||
|
// view.RefreshInitData(list);
|
||
|
}
|
||
|
|
||
|
private void CreateScrollItemFinish(GameObject arg1, object arg2)
|
||
|
{
|
||
|
var mallScrollItem = arg2 as MallScrollItem;
|
||
|
var itemView = arg1.GetComponent<MallScrollItemView>();
|
||
|
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<MallScrollItem> oldvalue, List<MallScrollItem> newvalue)
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
}
|