static internal TypeInformation ParseVariantTypeFields(Mono.Cecil.TypeDefinition variantType, Mono.Cecil.TypeReference typeReference) { var type = typeReference.Resolve(); var root = new TypeInformation(type); if (!variantType.HasFields) { return(root); } foreach (var field in variantType.Fields) { if (!field.IsPublic || field.IsStatic) { continue; } if (type.Fields.FirstOrDefault(f => f.Name == field.Name) == null) { UnityEngine.Debug.LogError($"Variant {variantType.Name}. field {field.Name} not present in original type {type.Name}"); continue; } //Avoid use ghost fields modifiers for the variant type. passing null prevent that var ghostField = CecilExtensions.GetGhostFieldAttribute(null, field); if (ghostField != null && ghostField.SendData) { root.Add(ParseTypeField(field, field.FieldType, ghostField, TypeAttribute.Empty(), root.AttributeMask)); } } foreach (var prop in type.Properties) { if (prop.GetMethod == null || !prop.GetMethod.IsPublic || prop.GetMethod.IsStatic) { continue; } if (prop.SetMethod == null || !prop.SetMethod.IsPublic || prop.SetMethod.IsStatic) { continue; } if (type.Properties.FirstOrDefault(f => f.Name == prop.Name) == null) { UnityEngine.Debug.LogError($"Variant {variantType.Name}. field {prop.Name} not present in original type {type.Name}"); continue; } var ghostField = CecilExtensions.GetGhostFieldAttribute(type, prop); if (ghostField != null && ghostField.SendData) { root.Add(ParseTypeField(prop, prop.PropertyType, ghostField, TypeAttribute.Empty(), root.AttributeMask)); } } return(root); }
public TypeInformation(Mono.Cecil.TypeReference parentType, Mono.Cecil.FieldDefinition fieldInfo, TypeAttribute inheritedAttribute, string parent = null) { FieldInfo = fieldInfo; Type = fieldInfo.FieldType; Fields = new List <TypeInformation>(); Attribute = inheritedAttribute; ParseAttribute(CecilExtensions.GetGhostFieldAttribute(parentType, fieldInfo)); Parent = string.IsNullOrEmpty(parent) ? "" : parent; }
public TypeDescription(Mono.Cecil.TypeReference typeReference, TypeAttribute attribute) { TypeFullName = typeReference.FullName.Replace("/", "+"); if (!typeReference.IsPrimitive && typeReference.Resolve().IsEnum) { Key = typeof(Enum).FullName; } else { Key = TypeFullName; } Attribute = attribute; }
static void FillSubFields(FieldInfo field, GhostFieldAttribute attr, List <GhostFieldModifier> fieldsList, string parentPrefix = "") { var typeAttribute = new TypeAttribute { composite = attr.Composite, smoothing = (uint)attr.Smoothing, quantization = attr.Quantization, maxSmoothingDist = attr.MaxSmoothingDistance, subtype = attr.SubType }; if (!field.FieldType.IsValueType) { return; } if (field.FieldType.IsPrimitive || field.FieldType.IsEnum) { if (CodeGenTypes.Registry.CanGenerateType(new TypeDescription(field.FieldType, typeAttribute))) { fieldsList.Add(new GhostFieldModifier { name = parentPrefix + field.Name, attribute = attr }); } return; } if (CodeGenTypes.Registry.CanGenerateType(new TypeDescription(field.FieldType, typeAttribute))) { fieldsList.Add(new GhostFieldModifier { name = parentPrefix + field.Name, attribute = attr }); return; } foreach (var f in field.FieldType.GetFields(BindingFlags.Instance | BindingFlags.Public)) { var attributes = f.GetCustomAttributes <GhostFieldAttribute>().ToArray(); if (attributes.Length > 0 && !attributes[0].SendData) { continue; } FillSubFields(f, attr, fieldsList, $"{parentPrefix+field.Name}."); } }
public void RegisterType(Type type, TypeAttribute attribute, TypeTemplate template) { Templates.Add(new TypeDescription(type, attribute), template); }
public TypeInformation(Mono.Cecil.TypeDefinition type) { Type = type; Fields = new List <TypeInformation>(); Attribute = TypeAttribute.Empty(); }
public TypeDescription(Type type, TypeAttribute attribute) { TypeFullName = type.FullName; Key = !type.IsEnum ? type.FullName : typeof(Enum).FullName; Attribute = attribute; }
static private TypeInformation ParseTypeField(Mono.Cecil.IMemberDefinition fieldInfo, Mono.Cecil.TypeReference fieldType, GhostFieldAttribute ghostField, TypeAttribute inheritedAttribute, TypeAttribute.AttributeFlags inheriteAttributedMask, string parent = "") { var information = new TypeInformation(fieldInfo, fieldType, ghostField, inheritedAttribute, inheriteAttributedMask, parent); //blittable also contains bool, but does not contains enums if (fieldType.IsBlittable()) { return(information); } var fieldDef = fieldType.Resolve(); if (fieldDef.IsEnum) { return(information); } if (!fieldDef.IsStruct()) { return(default);
private static TypeRegistry.CodeGenType[] GetDefaultTypes() { return(new[] { new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(int), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueInt.cs" } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(uint), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueUInt.cs" } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(short), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueInt.cs" } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(ushort), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueUInt.cs" } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(byte), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueUInt.cs" } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(sbyte), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueInt.cs" } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(Enum), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueInt.cs" } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(bool), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueUInt.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueBool.cs", } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float), TypeAttribute.Specialized(TypeAttribute.AttributeFlags.Quantized | TypeAttribute.AttributeFlags.Interpolated)), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat.cs", SupportsQuantization = true, SupportCommand = false } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float), TypeAttribute.Specialized(TypeAttribute.AttributeFlags.Quantized)), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat.cs", SupportsQuantization = true, SupportCommand = false } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloatUnquantized.cs", } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float), TypeAttribute.Specialized(TypeAttribute.AttributeFlags.Interpolated)), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloatUnquantized.cs", SupportCommand = false } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float2), TypeAttribute.Specialized(TypeAttribute.AttributeFlags.Quantized)), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat2.cs", SupportsQuantization = true, Composite = true, SupportCommand = false } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float2), TypeAttribute.Specialized(TypeAttribute.AttributeFlags.Quantized | TypeAttribute.AttributeFlags.Interpolated)), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat2.cs", SupportsQuantization = true, Composite = true, SupportCommand = false } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float2), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloatUnquantized.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat2Unquantized.cs", Composite = true } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float2), TypeAttribute.Specialized(TypeAttribute.AttributeFlags.Interpolated)), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloatUnquantized.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat2Unquantized.cs", Composite = true, SupportCommand = false } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float3), TypeAttribute.Specialized(TypeAttribute.AttributeFlags.Quantized)), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat3.cs", SupportsQuantization = true, Composite = true, SupportCommand = false } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float3), TypeAttribute.Specialized(TypeAttribute.AttributeFlags.Quantized | TypeAttribute.AttributeFlags.Interpolated)), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat3.cs", SupportsQuantization = true, Composite = true, SupportCommand = false } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float3), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloatUnquantized.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat3Unquantized.cs", Composite = true } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float3), TypeAttribute.Specialized(TypeAttribute.AttributeFlags.Interpolated)), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloatUnquantized.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat3Unquantized.cs", Composite = true, SupportCommand = false } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float4), TypeAttribute.Specialized(TypeAttribute.AttributeFlags.Quantized)), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat4.cs", SupportsQuantization = true, Composite = true, SupportCommand = false } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float4), TypeAttribute.Specialized(TypeAttribute.AttributeFlags.Quantized | TypeAttribute.AttributeFlags.Interpolated)), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat4.cs", SupportsQuantization = true, Composite = true, SupportCommand = false } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float4), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloatUnquantized.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat4Unquantized.cs", Composite = true } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(float4), TypeAttribute.Specialized(TypeAttribute.AttributeFlags.Interpolated)), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloatUnquantized.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFloat4Unquantized.cs", Composite = true, SupportCommand = false } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(quaternion), TypeAttribute.Specialized(TypeAttribute.AttributeFlags.Quantized)), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueQuaternion.cs", SupportsQuantization = true, SupportCommand = false } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(quaternion), TypeAttribute.Specialized(TypeAttribute.AttributeFlags.Quantized | TypeAttribute.AttributeFlags.Interpolated)), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueQuaternion.cs", SupportsQuantization = true, SupportCommand = false } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(quaternion), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueQuaternionUnquantized.cs" } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(quaternion), TypeAttribute.Specialized(TypeAttribute.AttributeFlags.Interpolated)), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueQuaternionUnquantized.cs", SupportCommand = false } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(Entity), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueEntity.cs", SupportCommand = true } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(FixedString32), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFixedString32.cs", } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(FixedString64), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFixedString32.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFixedString64.cs", } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(FixedString128), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFixedString32.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFixedString128.cs", } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(FixedString512), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFixedString32.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFixedString512.cs", } }, new TypeRegistry.CodeGenType { description = new TypeDescription(typeof(FixedString4096), TypeAttribute.Empty()), template = new TypeTemplate { TemplatePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFixedString32.cs", TemplateOverridePath = $"{TypeRegistry.k_TemplateRootPath}/GhostSnapshotValueFixedString4096.cs", } }, }); }
TypeInformation ParseTypeField(Mono.Cecil.TypeReference typeDefinition, Mono.Cecil.FieldDefinition fieldInfo, TypeAttribute inheritedAttribute, string parent = "") { var information = new TypeInformation(typeDefinition, fieldInfo, inheritedAttribute, parent); //blittable also contains bool, but does not contains enums if (fieldInfo.FieldType.IsBlittable()) { return(information); } var fieldTypeDef = fieldInfo.FieldType.Resolve(); if (fieldTypeDef.IsEnum) { return(information); } if (!fieldTypeDef.IsStruct()) { return(default);