view层:
using UnityEngine;
public class BaseView : MonoBehaviour
{
BaseController _mController;
BaseModel _mModel;
protected void Awake()
{
//new一个Controller,new一个model
_mController = new BaseController();
_mModel = new BaseModel();
//监听model层发来的消息
GlobalEntity.GetInstance().AddListener<int>(EnumManager.message1.m,OnGetMessageM);
}
private void Start()
{
//发消息通知Controller
GlobalEntity.GetInstance().Dispatch(EnumManager.message1.v);
}
private void OnGetMessageM(int arg1)
{
Debug.Log("收到message1.m的值:"+arg1);
}
protected void OnDestroy()
{
//移除model层发来的消息监听
GlobalEntity.GetInstance().RemoveListener<int>(EnumManager.message1.m, OnGetMessageM);
Dispose();
}
public void Dispose()
{
//移除model和Controller
_mController.Dispose();