UNITY之PureMvc
来源:互联网 发布:淘宝卖假货美妆店铺 编辑:程序博客网 时间:2024/06/05 16:32
using System.Collections;
public class Test : MonoBehaviour {
void Start(){
new TestFacade (gameObject);
}
}
using UnityEngine;
using System.Collections;
using PureMVC.Patterns;
public class TestFacade : Facade {
public TestFacade(GameObject canvas){
//给TestCommand注册拦截LevelUp通知
RegisterCommand (NotificationConstant.LevelUp,typeof(TestCommand));
//注册中介和代理
RegisterMediator (new TestMediator(canvas));
RegisterProxy (new TestProxy ());
}
}
using UnityEngine;
using System.Collections;
using PureMVC.Patterns;
public class TestCommand : SimpleCommand {
public new const string NAME="TestCommand";
//只对LevelUp通知拦截,由TestFacade注册的
public override void Execute (PureMVC.Interfaces.INotification notification)
{
TestProxy proxy = (TestProxy)Facade.RetrieveProxy (TestProxy.NAME);
proxy.ChangeLevel (1);
}
}
using UnityEngine;
using System.Collections;
using PureMVC.Patterns;
using UnityEngine.UI;
using System.Collections.Generic;
public class TestMediator : Mediator {
public new const string NAME="TestMediator";
//View
private Text levelText;
private Button levelButton;
public TestMediator(GameObject root):base(NAME){
levelText = GameUtility.GetChildComponent<Text> (root, "Text/LevelText");
levelButton = GameUtility.GetChildComponent<Button> (root,"LevelUpButton");
//给Button添加Onclick操作处理
levelButton.onClick.AddListener (OnClickLevelUpButton);
}
public void OnClickLevelUpButton(){
//发送LevelUp通知,由TestCommand拦截并执行Excute方法
SendNotification (NotificationConstant.LevelUp);
}
//添加感兴趣的通知,只要有通知发出就会拿遍历list去匹配,
//匹配到则调用下面的HandleNotification函数
//进行处理通知
public override System.Collections.Generic.IList<string> ListNotificationInterests ()
{
IList<string> list = new List<string> ();
list.Add (NotificationConstant.LevelChange);
return list;
}
//处理通知
public override void HandleNotification (PureMVC.Interfaces.INotification notification)
{
Debug.Log (notification.Name+" "+NotificationConstant.LevelChange);
//对相应的通知做相应的处理
switch (notification.Name) {
//对LevelChange通知处理过程
case NotificationConstant.LevelChange:
CharacterInfo ci = notification.Body as CharacterInfo;
Debug.Log (ci.Level);
levelText.text = ci.Level.ToString ();
break;
default:
break;
}
}
}
using UnityEngine;
using System.Collections;
using PureMVC.Patterns;
public class TestProxy : Proxy {
public new const string NAME="TestProxy";
public CharacterInfo Data{ get; set;}
public TestProxy():base(NAME){
Data = new CharacterInfo ();
}
//执行ChangeLevel操作,并发送LevelChange通知
//由TestMediator对每个通知进行监测,若在感兴趣的通知里
//则拦截
public void ChangeLevel(int change){
Data.Level += change;
SendNotification (NotificationConstant.LevelChange, Data);
}
}
- UNITY之PureMvc
- UNITY之PureMvc基础知识
- [Unity框架]PureMVC基础
- 在Unity使用PureMVC
- [Unity框架]PureMVC基础
- [Unity]PureMVC框架解读(上)
- [Unity]PureMVC框架解读(下)
- PureMVC之通信
- 游戏框架之puremvc
- Unity3D架构之PureMVC
- puremvc
- pureMVC
- pureMVC
- puremvc
- pureMVC
- PureMVC
- PureMVC
- AS3 PureMVC之核心层
- 简单的js二级联动
- Query中ajax的使用与缓存问题的解决方法
- c++(17)一、二两章回顾
- 文章标题
- Androidstudio目录详解
- UNITY之PureMvc
- my 3 c
- js的string的一些方法的记忆。
- 路径
- Spring 实现定时作业
- 你想成为Spark高手吗?只要这6个阶段!
- Android中使用DES加密算法
- [Leetcode] Frog Jump
- 分布式缓存--EhCache