Exemplo n.º 1
0
    /// <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);
    }
Exemplo n.º 2
0
        public void send(ProtoBase proto)
        {
            string protoName = proto.GetType().Name;

            Debug.LogError("send proto :" + protoName);
            send(Encode(proto));
        }
Exemplo n.º 3
0
    public void ArenaMatchS2C(ProtoBase proto)
    {
        m__arena__match__s2c p = proto as m__arena__match__s2c;

        SceneController.Instance.EnterSceneC2S();
        GameApp.Instance.gameObject.AddComponent <LockStepMgr> ();
    }
Exemplo n.º 4
0
 public void SendMsg(int clientID, byte protoID, ProtoBase obj)
 {
     byte[] data = Util.SerializeProtoData(protoID, obj);
     if (data == null)
     {
         return;
     }
     host.SendMsg(clientID, data);
 }
Exemplo n.º 5
0
 public void Broadcast(byte protoID, ProtoBase obj)
 {
     byte[] data = Util.SerializeProtoData(protoID, obj);
     if (data == null)
     {
         return;
     }
     host.SendMsg(data);
 }
Exemplo n.º 6
0
    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();
    }
Exemplo n.º 7
0
    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);
    }
Exemplo n.º 8
0
    /// <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
    }
Exemplo n.º 9
0
    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);
        }
    }
Exemplo n.º 10
0
    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);
    }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
            }
        }
Exemplo n.º 13
0
    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);
        }
    }
Exemplo n.º 14
0
    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);
        }
    }
Exemplo n.º 15
0
    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));
        }
    }
Exemplo n.º 16
0
    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));
        }
    }
Exemplo n.º 17
0
    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);
    }
Exemplo n.º 18
0
    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();
    }
Exemplo n.º 19
0
    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));
        }
    }
Exemplo n.º 20
0
    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);
        }
    }
Exemplo n.º 21
0
    public FileDescriptor(DescriptorPool pool, ProtoBase parent, FileDescriptorProto def)
    {
        Define = def;

        base.Init(pool, parent);
    }
Exemplo n.º 22
0
 public InfoSkill(ProtoBase proto) : base(proto)
 {
     m_proto_skill = (proto as ProtoSkill);
 }
Exemplo n.º 23
0
 public InfoSkill(ProtoBase proto)
     : base(proto)
 {
     m_proto_skill = (proto as ProtoSkill);
 }
Exemplo n.º 24
0
 public InfoCreature(ProtoBase proto)
     : base(proto)
 {
     m_proto_ac = (proto as ProtoCreature);
 }
Exemplo n.º 25
0
 public void LoginS2C(ProtoBase proto)
 {
     Debug.Log("logn s2c ");
     SceneManager.LoadScene("battle");
 }
Exemplo n.º 26
0
 public InfoBase(ProtoBase proto)
 {
     m_proto = proto;
 }
Exemplo n.º 27
0
 protected void Send(byte protoID, ProtoBase obj, ProtoType msgType)
 {
     Connection.GetInstance().SendData(protoID, obj, msgType);
 }
Exemplo n.º 28
0
 public void send(ProtoBase proto)
 {
     net.send(proto);
 }
Exemplo n.º 29
0
 public InfoCreature(ProtoBase proto) : base(proto)
 {
     m_proto_ac = (proto as ProtoCreature);
 }
Exemplo n.º 30
0
 public static byte[] Serialize(ProtoBase proto)
 {
     return(proto.Serialize());
 }
Exemplo n.º 31
0
 public void ConfirmActionS2C(ProtoBase proto)
 {
     Debug.Log("confirm action s2c!");
 }
Exemplo n.º 32
0
 public InfoBase(ProtoBase proto)
 {
     m_proto = proto;
 }