UMVCSL5——角色面板View和Mediator

本章大部分知识已在上一章讲过,这里不再阐述相同内容

View

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using UnityEngine;
using UnityEngine.UI;

public class NewRoleView : MonoBehaviour
{
public Text txtLev;
public Text txtHp;
public Text txtAtk;
public Text txtDef;
public Text txtCrit;
public Text txtMiss;
public Text txtLuck;

public Button btnClose;
public Button btnLevUp;

public void UpdateInfo(PlayerDataObject data)
{
txtLev.text = "LV." + data.lev.ToString();
txtHp.text = data.hp.ToString();
txtAtk.text = data.atk.ToString();
txtDef.text = data.def.ToString();
txtCrit.text = data.crit.ToString();
txtMiss.text = data.miss.ToString();
txtLuck.text = data.luck.ToString();
}
}

Mediator

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using PureMVC.Interfaces;
using PureMVC.Patterns.Mediator;

public class NewRoleViewMediator : Mediator
{
public static new string NAME = "NewRoleViewMediator";

public NewRoleViewMediator() : base(NAME)
{

}

public override string[] ListNotificationInterests()
{
return new string[] { PureNotification.UPDATE_PLAYER_INFO };
//如果要监听别的通知,就在字符串数组后面在添加通知名即可
}

public override void HandleNotification(INotification notification)
{
switch (notification.Name)
{
case PureNotification.UPDATE_PLAYER_INFO:
(ViewComponent as NewRoleView).UpdateInfo( notification.Body as PlayerDataObject );
break;
}
}
}