コード例 #1
0
    /// <summary>
    /// 패킷에서 데이터 읽기 (RPC)
    /// </summary>
    /// <param name="type">파라미터 타입</param>
    public static object ReadObjectPacked(this NetBuffer buff, Type type)
    {
        if (type.IsNullable())
        {
            bool isNull = buff.ReadBoolean();

            if (isNull)
            {
                return(null);
            }
        }

        if (type == typeof(byte))
        {
            return(buff.ReadByte());
        }
        if (type == typeof(sbyte))
        {
            return(buff.ReadSByte());
        }
        if (type == typeof(ushort))
        {
            return(buff.PeekUInt16());
        }
        if (type == typeof(short))
        {
            return(buff.ReadInt16());
        }
        if (type == typeof(int))
        {
            return(buff.ReadInt32());
        }
        if (type == typeof(uint))
        {
            return(buff.ReadUInt32());
        }
        if (type == typeof(long))
        {
            return(buff.ReadInt64());
        }
        if (type == typeof(ulong))
        {
            return(buff.ReadUInt64());
        }
        if (type == typeof(float))
        {
            return(buff.ReadFloat());
        }
        if (type == typeof(double))
        {
            return(buff.ReadDouble());
        }
        if (type == typeof(string))
        {
            return(buff.ReadString());
        }
        if (type == typeof(bool))
        {
            return(buff.PeekBoolean());
        }
        if (type == typeof(Vector3))
        {
            Vector3 v = default(Vector3);
            buff.Read(ref v);
            return(v);
        }
        if (type == typeof(char))
        {
            return(buff.ReadByte());
        }
        if (type.IsEnum)
        {
            return(buff.ReadInt32());
        }


        throw new ArgumentException("BitReader cannot read type " + type.Name);
    }