16.MVX框架-MVVM框架-角色面板Panel面板层
16.1 知识点
定义MVVM_RolePanel,这个类继承自BaseUGUIPanel,初始化,找控件刷新界面逻辑大同小异
using System.Collections;
using System.Collections.Generic;
using BaseFramework;
using UnityEngine;
using UnityEngine.UI;
public class MVVM_RolePanel : BaseUGUIPanel
{
//1.找控件
//2.处理逻辑
//3.面板更新
public override void Init()
{
//第一次显示时 更新面板
UpdateInfo(MVVM_PlayerModel.Data);
MVVM_PlayerModel.Data.AddEventListener(UpdateInfo);
}
protected override void OnButtonInitClick(string btnName)
{
base.OnButtonInitClick(btnName);
switch (btnName)
{
case "btnClose":
BaseUGUIManager.Instance.HidePanel<MVVM_RolePanel>();
break;
case "btnLevUp":
MVVM_PlayerModel.Data.LevUp();
break;
}
}
public void UpdateInfo(MVVM_PlayerModel data)
{
GetUIElement<Text>("txtLev").text = "LV." + data.Lev;
GetUIElement<Text>("txtHp").text = data.HP.ToString();
GetUIElement<Text>("txtAtk").text = data.Atk.ToString();
GetUIElement<Text>("txtDef").text = data.Def.ToString();
GetUIElement<Text>("txtCrit").text = data.Crit.ToString();
GetUIElement<Text>("txtMiss").text = data.Miss.ToString();
GetUIElement<Text>("txtLuck").text = data.Luck.ToString();
}
private void OnDestroy()
{
MVVM_PlayerModel.Data.RemoveEventListener(UpdateInfo);
}
}
16.2 知识点代码
using System.Collections;
using System.Collections.Generic;
using BaseFramework;
using UnityEngine;
using UnityEngine.UI;
public class MVVM_RolePanel : BaseUGUIPanel
{
//1.找控件
//2.处理逻辑
//3.面板更新
public override void Init()
{
//第一次显示时 更新面板
UpdateInfo(MVVM_PlayerModel.Data);
MVVM_PlayerModel.Data.AddEventListener(UpdateInfo);
}
protected override void OnButtonInitClick(string btnName)
{
base.OnButtonInitClick(btnName);
switch (btnName)
{
case "btnClose":
BaseUGUIManager.Instance.HidePanel<MVVM_RolePanel>();
break;
case "btnLevUp":
MVVM_PlayerModel.Data.LevUp();
break;
}
}
public void UpdateInfo(MVVM_PlayerModel data)
{
GetUIElement<Text>("txtLev").text = "LV." + data.Lev;
GetUIElement<Text>("txtHp").text = data.HP.ToString();
GetUIElement<Text>("txtAtk").text = data.Atk.ToString();
GetUIElement<Text>("txtDef").text = data.Def.ToString();
GetUIElement<Text>("txtCrit").text = data.Crit.ToString();
GetUIElement<Text>("txtMiss").text = data.Miss.ToString();
GetUIElement<Text>("txtLuck").text = data.Luck.ToString();
}
private void OnDestroy()
{
MVVM_PlayerModel.Data.RemoveEventListener(UpdateInfo);
}
}
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 785293209@qq.com