Skip to content

Commit

Permalink
将网络管理器进行解耦,交给Command处理。
Browse files Browse the repository at this point in the history
  • Loading branch information
jarjin committed Jul 9, 2015
1 parent f1d39f8 commit 5ea975d
Show file tree
Hide file tree
Showing 17 changed files with 288 additions and 420 deletions.
11 changes: 4 additions & 7 deletions Assets/Scripts/ConstDefine/NotiConst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@

public class NotiConst
{
public const string START_UP = "StartUp"; //启动框架
public const string INIT_LUA = "InitLua"; //初始化Lua
public const string RES_UPDATE = "ResUpdate"; //资源更新
public const string RES_EXTRACT = "ResExract"; //资源解压

public const string SEND_INFO = "sendInfo"; //发送信息
public const string RETURN_SEND_INFO = "returnSendInfo"; //发送信息(返回)
public const string START_UP = "StartUp"; //启动框架
public const string DISPATCH_MESSAGE = "DispatchMessage"; //派发信息

public const string RETURN_SEND_INFO = "returnSendInfo"; //发送信息(返回)
public const string SEND_PRIVATE_INFO = "sendPrivateInfo";//发送私聊信息

public const string RETURN_PUBLIC_INFO = "returnPublicInfo"; //返回世界聊天信息
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Controller/Boostraps/BootstrapCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class BootstrapCommands : SimpleCommand {
/// </summary>
/// <param name="notification"></param>
public override void Execute(INotification notification) {
//-----------------关联命令-----------------------
Facade.RegisterCommand(NotiConst.DISPATCH_MESSAGE, typeof(SocketCommand));

//-----------------初始化管理器-----------------------
Facade.AddManager(ManagerName.Lua, new LuaScriptMgr());

Expand Down
4 changes: 1 addition & 3 deletions Assets/Scripts/Controller/Boostraps/BootstrapModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
using PureMVC.Patterns;
using PureMVC.Interfaces;

/**
* 注册Command ,建立 Command 与Notification 之间的映射
*/
public class BootstrapModels : SimpleCommand {

public override void Execute(INotification notification) {
Facade.RegisterProxy(new SocketProxy());
}
}
19 changes: 19 additions & 0 deletions Assets/Scripts/Controller/Command/SocketCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using UnityEngine;
using System.Collections;
using PureMVC.Patterns;
using PureMVC.Interfaces;
using System.Collections.Generic;
using SimpleFramework;

public class SocketCommand : SimpleCommand {

public override void Execute(INotification notification) {
object body = notification.Body;
if (body == null) return;

KeyValuePair<int, ByteBuffer> message = (KeyValuePair<int, ByteBuffer>)body;
switch (message.Key) {
default: Util.CallMethod("Network", "OnSocket", message.Key, message.Value); break;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Assets/Scripts/Controller/Command/StartUpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ protected override void InitializeMacroCommand() {
EditorApplication.isPlaying = false;
return;
}
//BootstrapCommands
AddSubCommand(typeof(BootstrapCommands));

//BootstrapModels
AddSubCommand(typeof(BootstrapModels));

//BootstrapCommands
AddSubCommand(typeof(BootstrapCommands));

//BootstrapViewMediators
AddSubCommand(typeof(BootstrapViewMediators));
}
Expand Down
2 changes: 0 additions & 2 deletions Assets/Scripts/Manager/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ void Init() {
ZipConstants.DefaultCodePage = 65001;
Screen.sleepTimeout = SleepTimeout.NeverSleep;
Application.targetFrameRate = AppConst.GameFrameRate;

//facade.SendNotification("");
}

/// <summary>
Expand Down
19 changes: 14 additions & 5 deletions Assets/Scripts/Manager/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@

namespace SimpleFramework.Manager {
public class NetworkManager : BehaviourBase {
private static Queue<KeyValuePair<int, ByteBuffer>> sEvents = new Queue<KeyValuePair<int, ByteBuffer>>();
private SocketProxy socket;
static Queue<KeyValuePair<int, ByteBuffer>> sEvents = new Queue<KeyValuePair<int, ByteBuffer>>();

SocketProxy SocketClient {
get {
if (socket == null)
socket = facade.RetrieveProxy(SocketProxy.NAME) as SocketProxy;
return socket;
}
}

void Awake() {
Init();
}

void Init() {
Util.Add<SocketClient>(gameObject);
}

public void OnInit() {
Expand All @@ -36,13 +44,14 @@ public static void AddEvent(int _event, ByteBuffer data) {
sEvents.Enqueue(new KeyValuePair<int, ByteBuffer>(_event, data));
}

/// <summary>
/// 交给Command,这里不想关心发给谁。
/// </summary>
void Update() {
if (sEvents.Count > 0) {
while (sEvents.Count > 0) {
KeyValuePair<int, ByteBuffer> _event = sEvents.Dequeue();
switch (_event.Key) {
default: CallMethod("OnSocket", _event.Key, _event.Value); break;
}
facade.SendNotification(NotiConst.DISPATCH_MESSAGE, _event);
}
}
}
Expand Down
42 changes: 0 additions & 42 deletions Assets/Scripts/Module/ChatMediator.cs

This file was deleted.

10 changes: 0 additions & 10 deletions Assets/Scripts/Module/ChatMediator.cs.meta

This file was deleted.

33 changes: 0 additions & 33 deletions Assets/Scripts/Module/ChatProxy.cs

This file was deleted.

10 changes: 0 additions & 10 deletions Assets/Scripts/Module/ChatProxy.cs.meta

This file was deleted.

41 changes: 0 additions & 41 deletions Assets/Scripts/Module/ChatWindow.cs

This file was deleted.

Loading

0 comments on commit 5ea975d

Please sign in to comment.