| New file |
| | |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using System; |
| | | |
| | | public class LuaGameNetPackBase |
| | | { |
| | | public ushort cmd = 0; |
| | | |
| | | List<byte> sendBytes = new List<byte>(); |
| | | Action writeBytesAction; |
| | | |
| | | public void RegistWriteToBytes(Action action) |
| | | { |
| | | |
| | | } |
| | | |
| | | public void WriteIntsBytes(uint value, LuaGameNetSystem.NetDataType type) |
| | | { |
| | | |
| | | } |
| | | |
| | | public void Send() |
| | | { |
| | | sendBytes.AddRange(BitConverter.GetBytes(cmd)); |
| | | |
| | | if (writeBytesAction != null) |
| | | { |
| | | writeBytesAction(); |
| | | } |
| | | |
| | | GameNetSystem.Instance.SendInfo(sendBytes.ToArray()); |
| | | } |
| | | |
| | | |
| | | int readIndex = 0; |
| | | public uint TransUintBytes(byte[] value, LuaGameNetSystem.NetDataType type) |
| | | { |
| | | readIndex += 4; |
| | | return BitConverter.ToUInt32(value, readIndex); |
| | | } |
| | | |
| | | public ushort TransUshortBytes(byte[] value, LuaGameNetSystem.NetDataType type) |
| | | { |
| | | readIndex += 2; |
| | | return BitConverter.ToUInt16(value, readIndex); |
| | | } |
| | | |
| | | public byte TransByteBytes(byte[] value, LuaGameNetSystem.NetDataType type) |
| | | { |
| | | readIndex += 1; |
| | | return value[readIndex]; |
| | | } |
| | | |
| | | // public uint[] TransVShortsBytes(byte[] value, LuaGameNetSystem.NetDataType type, int length) |
| | | // { |
| | | // |
| | | // |
| | | // } |
| | | |
| | | } |
| | | |
| | | public class LuaGameNetSystem |
| | | { |
| | | |
| | | public static LuaGameNetPackBase New() |
| | | { |
| | | return new LuaGameNetPackBase(); |
| | | } |
| | | |
| | | public enum NetDataType |
| | | { |
| | | BYTE, |
| | | WORD, |
| | | DWORD, |
| | | Chars, |
| | | Int, |
| | | Double |
| | | } |
| | | |
| | | } |