Example #1
0
    public static void SendPkgToServer <T>(ENUM_CMD cmdID, T obj, Action <object> callback = null)
    {
        //Debug.Log("SendPkgToServer,cmd=" + cmdID);
        if (IsSingle && LocalServer.ProcessRequest(cmdID, obj, callback))
        {
            return;
        }

        byte[]      data   = Serialize(obj);
        int         length = data.Length;
        List <byte> bytes  = new List <byte>();

        bytes.AddRange(BitConverter.GetBytes((ushort)cmdID));
        bytes.AddRange(BitConverter.GetBytes((uint)length));
        bytes.AddRange(data);
        _message.Enqueue(bytes.ToArray());

        if (callback != null)
        {
            if (!callbackDict.ContainsKey(cmdID))
            {
                callbackDict[cmdID] = new List <NetworkCallback>();
            }
            callbackDict[cmdID].Add(new NetworkCallback {
                func = callback, isDelete = true
            });
        }
    }