Beispiel #1
0
 private object ReadPrimitive(SerializedPrimitive value)
 {
     return(value.Value);
 }
Beispiel #2
0
            private SerializedPrimitive DeserializePrimitive(BinaryReader reader)
            {
                var value = new SerializedPrimitive(DeserializeDefaults(reader));
                var type  = Type.GetType(value.Type);

                if (type == typeof(bool))
                {
                    value.Value = reader.ReadBoolean();
                }
                else if (type == typeof(byte))
                {
                    value.Value = reader.ReadByte();
                }
                else if (type == typeof(char))
                {
                    value.Value = reader.ReadChar();
                }
                else if (type == typeof(decimal))
                {
                    value.Value = reader.ReadDecimal();
                }
                else if (type == typeof(double))
                {
                    value.Value = reader.ReadDouble();
                }
                else if (type == typeof(float))
                {
                    value.Value = reader.ReadSingle();
                }
                else if (type == typeof(int))
                {
                    value.Value = reader.ReadInt32();
                }
                else if (type == typeof(long))
                {
                    value.Value = reader.ReadInt64();
                }
                else if (type == typeof(sbyte))
                {
                    value.Value = reader.ReadSByte();
                }
                else if (type == typeof(short))
                {
                    value.Value = reader.ReadInt16();
                }
                else if (type == typeof(string))
                {
                    value.Value = reader.ReadString();
                }
                else if (type == typeof(uint))
                {
                    value.Value = reader.ReadUInt32();
                }
                else if (type == typeof(ulong))
                {
                    value.Value = reader.ReadUInt64();
                }
                else if (type == typeof(ushort))
                {
                    value.Value = reader.ReadUInt16();
                }
                else
                {
                    Debug.LogErrorFormat("Found an unknown primitive: {0}", type.Name);
                }

                return(value);
            }
            private void WritePrimitive(BinaryWriter writer, SerializedPrimitive obj)
            {
                WriteDefaults(writer, obj);

                var type = Type.GetType(obj.Type);

                if (type == typeof(bool))
                {
                    writer.Write((bool)obj.Value);
                }
                else if (type == typeof(byte))
                {
                    writer.Write((byte)obj.Value);
                }
                else if (type == typeof(char))
                {
                    writer.Write((char)obj.Value);
                }
                else if (type == typeof(decimal))
                {
                    writer.Write((decimal)obj.Value);
                }
                else if (type == typeof(double))
                {
                    writer.Write((double)obj.Value);
                }
                else if (type == typeof(float))
                {
                    writer.Write((float)obj.Value);
                }
                else if (type == typeof(int))
                {
                    writer.Write((int)obj.Value);
                }
                else if (type == typeof(long))
                {
                    writer.Write((long)obj.Value);
                }
                else if (type == typeof(sbyte))
                {
                    writer.Write((sbyte)obj.Value);
                }
                else if (type == typeof(short))
                {
                    writer.Write((short)obj.Value);
                }
                else if (type == typeof(string))
                {
                    writer.Write(obj.IsNull ? "" : (string)obj.Value);
                }
                else if (type == typeof(uint))
                {
                    writer.Write((uint)obj.Value);
                }
                else if (type == typeof(ulong))
                {
                    writer.Write((ulong)obj.Value);
                }
                else if (type == typeof(ushort))
                {
                    writer.Write((ushort)obj.Value);
                }
                else
                {
                    UnityEngine.Debug.LogErrorFormat("Found an unknown primitive: {0}", type.Name);
                }
            }