Beispiel #1
0
 public static void WriteObject(object value, ByteBuffer buffer)
 {
     if (value is Vector3)
     {
         buffer.WriteVector3((Vector3)value);
     }
     else if (value is Quaternion)
     {
         buffer.WriteQuaternion((Quaternion)value);
     }
     else if (value is int)
     {
         buffer.WriteInt((int)value);
     }
     else if (value is float)
     {
         buffer.WriteFloat((float)value);
     }
     else if (value is long)
     {
         buffer.WriteLong((long)value);
     }
     else if (value is bool)
     {
         buffer.WriteBool((bool)value);
     }
     else if (value is string)
     {
         buffer.WriteString((string)value);
     }
     else if (value is NetworkBehaviour)
     {
         NetworkBehaviour net = (NetworkBehaviour)value;
         buffer.WriteLong(net == null ? long.MinValue : net.NetworkId);
     }
     else if (value is byte)
     {
         buffer.WriteByte((byte)value);
     }
     else
     {
         byte[] serial = SerialUtility.Serialize(value);
         buffer.WriteByte((byte)serial.Length);
         buffer.WriteBytes(serial);
     }
 }
Beispiel #2
0
 public static void Query <T>(string data, QueryObjectCallback <T> then, params object[] args)
 {
     Query(data, raw => then((T)SerialUtility.Deserialize(raw)), args);
 }
Beispiel #3
0
 public static object ReadObject(ByteBuffer data, byte dataType)
 {
     if (dataType == ObjectType)
     {
         byte   dataLength = data.ReadByte();
         byte[] fieldData  = data.ReadBytes(dataLength);
         return(SerialUtility.Deserialize(fieldData));
     }
     else
     {
         if (dataType == Vector3Type)
         {
             return(data.ReadVector3());
         }
         else if (dataType == QuaternionType)
         {
             return(data.ReadQuaternion());
         }
         else if (dataType == IntType)
         {
             return(data.ReadInt());
         }
         else if (dataType == FloatType)
         {
             return(data.ReadFloat());
         }
         else if (dataType == LongType)
         {
             return(data.ReadLong());
         }
         else if (dataType == BoolType)
         {
             return(data.ReadBool());
         }
         else if (dataType == StringType)
         {
             return(data.ReadString());
         }
         else if (dataType == BehaviourType)
         {
             long id = data.ReadLong();
             if (id == long.MinValue)
             {
                 return(null);
             }
             if (Side.IsClient)
             {
                 NetworkBehaviour obj = null;
                 ClientRegistry.GetObject(id, out obj);
                 return(obj);
             }
             else
             {
                 ObjectRegistration obj = null;
                 ServerRegistry.GetObject(id, out obj);
                 return(obj.Object);
             }
         }
         else if (dataType == ByteType)
         {
             return(data.ReadByte());
         }
         else
         {
             NetworkBridge.Warn("Invalid serialization type: " + dataType);
             return(null);
         }
     }
 }
Beispiel #4
0
 public object ReadObject()
 {
     return(SerialUtility.Deserialize(ReadBytes(ReadInt())));
 }
Beispiel #5
0
 public void WriteObject(object obj)
 {
     byte[] serial = SerialUtility.Serialize(obj);
     WriteInt(serial.Length);
     WriteBytes(serial);
 }