/// <summary> /// 序列化Proto /// </summary> public static byte[] SerializeProtoData(byte protoID, ProtoBase obj) { byte[] result = null; if (obj == null) { result = new byte[Connection.PACKER_OFFSET]; } else { byte[] src = SerializeUtil.Serialize(obj); if (src != null) { result = new byte[src.Length + Connection.PACKER_OFFSET]; System.Array.Copy(src, 0, result, Connection.PACKER_OFFSET, src.Length); } else { Debug.LogError("proto错误:" + protoID); return(result); } } result[0] = Connection.PACKER_HEAD; result[1] = protoID; return(result); }
public void send(ProtoBase proto) { string protoName = proto.GetType().Name; Debug.LogError("send proto :" + protoName); send(Encode(proto)); }
public void ArenaMatchS2C(ProtoBase proto) { m__arena__match__s2c p = proto as m__arena__match__s2c; SceneController.Instance.EnterSceneC2S(); GameApp.Instance.gameObject.AddComponent <LockStepMgr> (); }
public void SendMsg(int clientID, byte protoID, ProtoBase obj) { byte[] data = Util.SerializeProtoData(protoID, obj); if (data == null) { return; } host.SendMsg(clientID, data); }
public void Broadcast(byte protoID, ProtoBase obj) { byte[] data = Util.SerializeProtoData(protoID, obj); if (data == null) { return; } host.SendMsg(data); }
public void LoginS2C(ProtoBase proto) { Debug.Log("角色登陆返回"); m__role__login__s2c p = proto as m__role__login__s2c; RoleMgr.Instance.RoleId = p.role_info.id; SceneMgr.Instance.Init(); MainMenuView.Instance.Init(); }
public void Recycle(ProtoRecycleType type, ProtoBase proto) { Stack <ProtoBase> stack; if (!pool.TryGetValue(type, out stack)) { stack = new Stack <ProtoBase>(); stack.Push(proto); } stack.Push(proto); }
/// <summary> /// 发送数据 /// </summary> public void SendData(byte protoID, ProtoBase obj, ProtoType msgType) { #if UNITY_EDITOR sendSampler.Begin(); #endif byte[] data = Util.SerializeProtoData(protoID, obj); Send(data, msgType); #if UNITY_EDITOR sendSampler.End(); #endif }
public void RolesS2C(ProtoBase proto) { Debug.Log("roles s2c "); Object original = Resources.Load("Prefabs/hero"); m__scene__roles__s2c p = proto as m__scene__roles__s2c; for (int i = 0; i < p.roles.Count; i++) { Object copyObject = GameObject.Instantiate(original); copyObject.name = copyObject.name.Replace("(Clone)", "_" + p.roles[i].name); } }
public void SyncActionS2C(ProtoBase proto) { Debug.Log("sync s2c!"); m__action__sync__s2c p = proto as m__action__sync__s2c; IAction a = BinarySerialization.DeserializeObject <IAction> (p.action); LockStepMgr.Instance.SyncAction(p.turn_id, p.role_id, a); m__action__confirm__c2s p1 = new m__action__confirm__c2s(); p1.role_id = RoleMgr.Instance.RoleId; p1.turn_id = p.turn_id; NetMgr.Instance.send(p1); }
private byte[] Encode(ProtoBase proto) { _sendBuffer.Reset(); proto.write(_sendBuffer); int BigLen = IPAddress.HostToNetworkOrder(_sendBuffer.Length); byte[] lenBytes = BitConverter.GetBytes(BigLen); byte[] sendBytes = new byte[_sendBuffer.Length + 4]; Array.Copy(lenBytes, sendBytes, lenBytes.Length); Array.Copy(_sendBuffer.Buff, 0, sendBytes, 4, _sendBuffer.Length); return(sendBytes); }
public ProtoBase GetProto(int uiProtoID) { Type kProtoType; m_DicProtoType.TryGetValue(uiProtoID, out kProtoType); if (kProtoType != null) { ProtoBase kProto = null; kProto = Activator.CreateInstance(kProtoType) as ProtoBase; return(kProto); } else { return(null); } }
public void AccountLoginS2C(ProtoBase proto) { Debug.Log("角色列表返回"); m__role__list__s2c p = proto as m__role__list__s2c; if (p.role_list.Count == 0) { // 创建角色 RoleController.Instance.CreateRoleC2S(acc); } else { // 登陆角色 RoleController.Instance.LoginC2S(p.role_list [0].id); } }
public EnumDescriptor(DescriptorPool pool, ProtoBase parent, EnumDescriptorProto def) { Define = def; base.Init(pool, parent); for (int i = 0; i < def.value.Count; i++) { var fieldDef = def.value[i]; var fieldD = new EnumValueDescriptor(this, fieldDef); _fieldByName.Add(fieldDef.name, fieldD); _fieldByNumber.Add(fieldDef.number, fieldD); } }
static int get_FullName(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); ProtoBase obj = (ProtoBase)o; string ret = obj.FullName; LuaDLL.lua_pushstring(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index FullName on a nil value" : e.Message)); } }
static int get_Pool(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); ProtoBase obj = (ProtoBase)o; DescriptorPool ret = obj.Pool; ToLua.PushObject(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index Pool on a nil value" : e.Message)); } }
public T Get <T>(ProtoRecycleType type) where T : ProtoBase, new() { Stack <ProtoBase> stack; T result = default(T); if (pool.TryGetValue(type, out stack)) { ProtoBase p = null; p = stack.Pop(); if (p != null) { result = p as T; } } return(result); }
protected void Init(DescriptorPool pool, ProtoBase parent) { _parent = parent; Pool = pool; var nameList = new List <string>(); // 放入自己 nameList.Add(GetRawName()); // 从今到古依次存入父级名字 var p = this; while (p != null) { if (p._parent == null) { break; } p = p._parent; nameList.Add(p.GetRawName()); } var sb = new StringBuilder(); // 逆向建成.分割的字符串 for (int i = nameList.Count - 1; i >= 0; i--) { sb.Append(nameList[i]); if (i >= 1) { sb.Append("."); } } FullName = sb.ToString(); }
static int _CreateProtoBase(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 0) { ProtoBase obj = new ProtoBase(); ToLua.PushObject(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: ProtoBase.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public Descriptor(DescriptorPool pool, ProtoBase parent, DescriptorProto def) { Define = def; base.Init(pool, parent); // 字段 for (int i = 0; i < def.field.Count; i++) { var fieldDef = def.field[i]; var fieldD = new FieldDescriptor(this, fieldDef); _fieldByName.Add(fieldDef.name, fieldD); _fieldByFieldNumber.Add(fieldD.Number, fieldD); } // 内嵌消息 for (int i = 0; i < def.nested_type.Count; i++) { var nestedDef = def.nested_type[i]; var msgD = new Descriptor(pool, this, nestedDef); _nestedMsg.Add(nestedDef.name, msgD); } // 内嵌枚举 for (int i = 0; i < def.enum_type.Count; i++) { var nestedDef = def.enum_type[i]; var enumD = new EnumDescriptor(pool, this, nestedDef); _nestedEnum.Add(nestedDef.name, enumD); } }
public FileDescriptor(DescriptorPool pool, ProtoBase parent, FileDescriptorProto def) { Define = def; base.Init(pool, parent); }
public InfoSkill(ProtoBase proto) : base(proto) { m_proto_skill = (proto as ProtoSkill); }
public InfoCreature(ProtoBase proto) : base(proto) { m_proto_ac = (proto as ProtoCreature); }
public void LoginS2C(ProtoBase proto) { Debug.Log("logn s2c "); SceneManager.LoadScene("battle"); }
public InfoBase(ProtoBase proto) { m_proto = proto; }
protected void Send(byte protoID, ProtoBase obj, ProtoType msgType) { Connection.GetInstance().SendData(protoID, obj, msgType); }
public void send(ProtoBase proto) { net.send(proto); }
public static byte[] Serialize(ProtoBase proto) { return(proto.Serialize()); }
public void ConfirmActionS2C(ProtoBase proto) { Debug.Log("confirm action s2c!"); }