コード例 #1
0
        protected override void WriteCore(ResourceWriter writer)
        {
            writer.WriteInt32(Count);

            foreach (var property in Values)
            {
                writer.WriteInt32(( int )property.ValueType);
                writer.WriteStringWithHash(Version, property.Name);

                switch (property.ValueType)
                {
                case UserPropertyValueType.Int:
                    writer.WriteInt32(4);
                    writer.WriteInt32(property.GetValue <int>());
                    break;

                case UserPropertyValueType.Float:
                    writer.WriteInt32(4);
                    writer.WriteSingle(property.GetValue <float>());
                    break;

                case UserPropertyValueType.Bool:
                    writer.WriteInt32(1);
                    writer.WriteBoolean(property.GetValue <bool>());
                    break;

                case UserPropertyValueType.String:
                {
                    var value = property.GetValue <string>();
                    writer.WriteInt32(value.Length + 1);
                    writer.WriteStringRaw(value);
                }
                break;

                case UserPropertyValueType.ByteVector3:
                    writer.WriteInt32(3);
                    writer.WriteByteVector3(property.GetValue <ByteVector3>());
                    break;

                case UserPropertyValueType.ByteVector4:
                    writer.WriteInt32(4);
                    writer.WriteByteVector4(property.GetValue <ByteVector4>());
                    break;

                case UserPropertyValueType.Vector3:
                    writer.WriteInt32(12);
                    writer.WriteVector3(property.GetValue <Vector3>());
                    break;

                case UserPropertyValueType.Vector4:
                    writer.WriteInt32(16);
                    writer.WriteVector4(property.GetValue <Vector4>());
                    break;

                case UserPropertyValueType.ByteArray:
                {
                    var value = property.GetValue <byte[]>();
                    writer.WriteInt32(value.Length);
                    writer.WriteBytes(value);
                }
                break;

                default:
                    throw new InvalidOperationException($"Unknown node property type: {property.ValueType}");
                }
            }
        }