Пример #1
0
 void onPointerUp(int dir)
 {
     if (NetScene.getInstance().IsDeath(NetScene.getInstance().MyId))
     {
         return;
     }
     byte[] action  = ByteUtil.IntToBytes2(ActionType.keyboardMove);
     byte[] content = ByteUtil.IntToBytes2(0);
     byte[] send    = ByteUtil.BytesCombine(action, content);
     lastDir = 0;
     Debug.Log("send dir3:");
     NetMgr.GetInstance().Send(Protocol.Update, send);
 }
Пример #2
0
    /// <summary>
    /// 创建发送内容
    /// </summary>
    /// <param name="protocol"></param>
    /// <param name="content"></param>
    /// <returns></returns>
    public static byte[] ConvertByteArrayToSend(int protocol, byte[] content)
    {
        try
        {
            byte[] length = ByteUtil.IntToBytes2(content.Length);
            byte[] cmd    = ByteUtil.IntToBytes2(protocol);

            //byte[] data = new byte[content.Length + 8];
            //Buffer.BlockCopy(length, 0, data, 0, length.Length);//前4位代表内容长度
            //Buffer.BlockCopy(cmd, 0, data, 4, cmd.Length);//中间4位代表协议
            //Buffer.BlockCopy(content, 0, data, 8, content.Length);//内容
            //return data;
            return(ByteUtil.BytesCombine(length, cmd, content));
        }
        catch (Exception e)
        {
            throw (e);
        }
    }
Пример #3
0
 void SyncMove()
 {
     if (data != null &&
         data.GetMove() &&
         data.isMe)
     {
         pass += Time.deltaTime;
         if (pass > sec)
         {
             pass = 0;
             int dir = Random.Range(1, 5);
             dir = validateDir(dir);
             byte[] action  = ByteUtil.IntToBytes2(ActionType.keyboardMove);
             byte[] content = ByteUtil.IntToBytes2(dir);
             byte[] send    = ByteUtil.BytesCombine(action, content);
             //NetMgr.getInstance().send(Protocol.Update, send);
         }
     }
 }
Пример #4
0
    void keyboardMove()
    {
        int dir = 0;

        if (Input.GetKey(KeyCode.D))
        {
            dir = 1;
        }
        else if (Input.GetKey(KeyCode.S))
        {
            dir = 2;
        }
        else if (Input.GetKey(KeyCode.A))
        {
            dir = 3;
        }
        else if (Input.GetKey(KeyCode.W))
        {
            dir = 4;
        }
        //Debug.Log("send dir1");
        if (lastDir == dir)
        {
            return;
        }
        if (NetScene.getInstance().IsDeath(NetScene.getInstance().MyId))
        {
            return;
        }
        //Debug.Log("send dir1:");
        byte[] action  = ByteUtil.IntToBytes2(ActionType.keyboardMove);
        byte[] content = ByteUtil.IntToBytes2(dir);
        byte[] send    = ByteUtil.BytesCombine(action, content);
        lastDir = dir;
        NetMgr.GetInstance().Send(Protocol.Update, send);
    }