[TWLFramework] Message

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
/*
消息体
直接遍历
key访问 message[key]
send()
remove()
add()
构造函数参数=》sender type(name) content
*/

public class Message : IEnumerable<KeyValuePair<string, object>>
{
private Dictionary<string, object> dictDatas = null;

public string Name { get; private set; }
public object Sender { get; private set; }
public object Content { get; private set; }
//索引器 实现
public object this[string key]
{
get
{
if (dictDatas == null || !dictDatas.ContainsKey(key))
{
return null;
}
return dictDatas[key];
}
set
{
if (dictDatas == null)
{
dictDatas = new Dictionary<string, object>();
}
if (dictDatas.ContainsKey(key))
{
dictDatas[key] = value;
}
else {
dictDatas.Add(key, value);
}
}
}

#region 继承ienumerator 实现
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
{
if (dictDatas == null)
{
yield break;
}
foreach (KeyValuePair<string, object> kvp in dictDatas)
{
yield return kvp;
}
}

IEnumerator IEnumerable.GetEnumerator()
{
return dictDatas.GetEnumerator();
}
#endregion

#region 构造函数
public Message(string name, object sender)
{
Name = name;
Sender = sender;
Content = null;
}
public Message(string name, object sender, object content)
{
Name = name;
Sender = sender;
Content = content;
}
public Message(string name, object sender, object content, params object[] dictParams)
{
Name = name;
Sender = sender;
Content = content;
if (dictParams.GetType() == typeof(Dictionary<string, object>))
{
foreach (object item in dictParams)
{
foreach (KeyValuePair<string, object> kvp in item as Dictionary<string, object>)
{
//dictDatas[kvp.Key] = kvp.Value 可能dict为空 报错
this[kvp.Key] = kvp.Value;
}
}
}
}
public Message(Message message)
{
Name = message.Name;
Sender = message.Sender;
Content = message.Content;
foreach (KeyValuePair<string, object> kvp in message.dictDatas)
{
this[kvp.Key] = kvp.Value;
}
}
#endregion

//add remove
public void Add(string key, object value)
{
this[key] = value;
}
public void Remove(string key)
{
if (dictDatas != null && dictDatas.ContainsKey(key))
{
dictDatas.Remove(key);
}
}

//send
public void Send()
{
MessageCenter.Instance.SendMessage(this);
}

}

时间: 2025-01-14 18:55:05

[TWLFramework] Message的相关文章

Handler和Message详解

Android开发中Handler的经典总结 当应用程序启动时,Android首先会开启一个主线程(也就是UI线程),主线程为管理界面中的UI控件,进行事件分发. 一.Handler的定义: 主要接受子线程发送的数据, 并用此数据配合主线程更新UI. 解释:当应用程序启动时,Android首先会开启一个主线程 (也就是UI线程) , 主线程为管理界面中的UI控件, 进行事件分发, 比如说, 你要是点击一个 Button ,Android会分发事件到Button上,来响应你的操作.  如果此时需要

“intel_rapl: no valid rapl domains” message upon boot blacklist.conf -1

"intel_rapl: no valid rapl domains" message upon boot I install fresh Ubuntu 14. 04 server under ESXI 5.1.0.During my installation I did not get any erorrs or strange things. My problem is when I boot machine at console screen I get messages lik

hdu 4661 Message Passing(树形DP&amp;组合数学)

Message Passing Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1187    Accepted Submission(s): 423 Problem Description There are n people numbered from 1 to n. Each people have a unique mes

HDU 4300 Clairewd’s message

Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important messages and she was preparing for sending it to ykwd. They had agreed that each letter of these messages would be transfered to a

Long Long Message(后缀数组)

Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 30427   Accepted: 12337 Case Time Limit: 1000MS Description The little cat is majoring in physics in the capital of Byterland. A piece of sad news comes to him these days

解决LLDB模式下出现message sent to deallocated instance错误

本文在源文的基础上做整理:http://www.devdiv.com/home.php?mod=space&uid=50901&do=blog&id=50856 Xcode版本7.1 IOS版本9.1 公司之前开发的一个APP,在使用环境中IOS版本升级到9.0以后,某个操作会导致程序闪退. Xcode代码中提示错误: 1 Thread 1: Program received signal:"EXC_BAD_ACCESS" 这样的提示意味着对已经释放的对象发送消

webapi &lt;Message&gt;已拒绝为此请求授权。&lt;/Message&gt;

原有的调用base.OnAuthorization(actionContext); 换成下面这个 /// <summary> /// 鉴权 /// </summary> /// <param name="actionContext"></param> public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContex

[Angular] Scrolling the Message List To the Bottom Automatically Using OnChanges

Let's say the message list can Input (messages) from parent component, and what we want to do is when there are new message, we will scroll message list to the bottom to show the lastest message. import {Component, Input, ViewChild, OnChanges, Simple

Android Message Handling Mechanism

转自:http://solarex.github.io/blog/2015/09/22/android-message-handling-mechanism/ Android is a message driven, message driven several elements: The message says: Message Message queue: MessageQueue The news cycle, remove the message processing for circ