65 lines
2.3 KiB
C#
65 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using uMVVM.Sources.Infrastructure;
|
|
using UnityEngine;
|
|
|
|
namespace Game.MVVM.Model
|
|
{
|
|
public class HallSceneMainMenuView : UnityGuiView<HallSceneMainMenuViewModel>
|
|
{
|
|
public Transform parentTrans;
|
|
public MenuItemView itemView;
|
|
|
|
[SerializeField] private List<GameObject> _listGo = new List<GameObject>();
|
|
|
|
protected override void OnInitialize()
|
|
{
|
|
base.OnInitialize();
|
|
this.itemView.gameObject.SetActive(false);
|
|
}
|
|
|
|
public override void OnBindingContextChanged(HallSceneMainMenuViewModel oldValue, HallSceneMainMenuViewModel newValue)
|
|
{
|
|
base.OnBindingContextChanged(oldValue, newValue);
|
|
|
|
if (oldValue != null)
|
|
oldValue.MenuItems.OnValueChanged -= this.OnMenuItemsValueChanged;
|
|
|
|
if (newValue != null)
|
|
newValue.MenuItems.OnValueChanged += this.OnMenuItemsValueChanged;
|
|
}
|
|
|
|
private void OnMenuItemsValueChanged(List<MenuItem> oldvalue, List<MenuItem> newvalue)
|
|
{
|
|
var viewGo = this.itemView.gameObject;
|
|
|
|
if (this._listGo.Count > 0)
|
|
foreach (var o in this._listGo)
|
|
{
|
|
GameObject.Destroy(o);
|
|
}
|
|
|
|
for (var i = 0; i < newvalue.Count; i++)
|
|
{
|
|
var menuItem = newvalue[i];
|
|
var instantiate = GameObject.Instantiate(viewGo, this.parentTrans);
|
|
instantiate.transform.localScale = Vector3.one;
|
|
instantiate.name = menuItem.menuName;
|
|
instantiate.SetActive(true);
|
|
this._listGo.Add(instantiate);
|
|
|
|
var menuItemView = instantiate.GetComponent<MenuItemView>();
|
|
menuItemView.BindingContext = new MenuItemViewModel() { ParentViewModel = this.BindingContext };
|
|
menuItemView.BindingContext.InitData(menuItem);
|
|
menuItemView.Reveal();
|
|
menuItemView.BindingContext.OnClick += this.OnClickButton;
|
|
}
|
|
}
|
|
|
|
public void OnClickButton(string id, string name)
|
|
{
|
|
Debug.Log($"点击了 {id} name is {name}");
|
|
EventManager.Instance.FireNow(this, new HallSceneClickMenuEventArgs(id, name));
|
|
}
|
|
}
|
|
} |