static internal TypeInformation ParseTypeFields(Mono.Cecil.TypeDefinition type, bool onlyFieldWithGhostField = true)
        {
            bool isBuffer      = CecilExtensions.IsBufferElementData(type);
            bool isCommandData = CecilExtensions.IsICommandData(type);
            var  root          = new TypeInformation(type);

            if (isBuffer)
            {
                root.AttributeMask &= ~(TypeAttribute.AttributeFlags.InterpolatedAndExtrapolated);
            }

            if (!type.HasFields)
            {
                return(root);
            }
            foreach (var field in type.Fields)
            {
                if (!field.IsPublic || field.IsStatic)
                {
                    continue;
                }

                var ghostField = CecilExtensions.GetGhostFieldAttribute(type, field);
                if (!onlyFieldWithGhostField && isCommandData &&
                    field.HasAttributeOnMemberOImplementedInterfaces <DontSerializeForCommand>())
                {
                    continue;
                }
                if (!onlyFieldWithGhostField || (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;
                }

                var ghostField = CecilExtensions.GetGhostFieldAttribute(type, prop);
                if (!onlyFieldWithGhostField && isCommandData &&
                    prop.HasAttributeOnMemberOImplementedInterfaces <DontSerializeForCommand>())
                {
                    continue;
                }

                if (!onlyFieldWithGhostField || (ghostField != null && ghostField.SendData))
                {
                    root.Add(ParseTypeField(prop, prop.PropertyType, ghostField, TypeAttribute.Empty(), root.AttributeMask));
                }
            }


            return(root);
        }
Esempio n. 2
0
        TypeInformation ParseTypeFields(Mono.Cecil.TypeDefinition type, bool onlyFieldWithGhostField = true)
        {
            var root = new TypeInformation(type);

            if (!type.HasFields)
            {
                return(root);
            }

            foreach (var field in type.Fields)
            {
                if (!field.IsPublic || field.IsStatic)
                {
                    continue;
                }

                if (!onlyFieldWithGhostField || CecilExtensions.HasGhostFieldAttribute(type, field))
                {
                    if (!CecilExtensions.HasGhostFieldAttribute(type, field) || CecilExtensions.GetGhostFieldAttribute(type, field).SendData)
                    {
                        root.Add(ParseTypeField(type, field, TypeAttribute.Empty()));
                    }
                }
            }
            return(root);
        }
        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);
        }
Esempio n. 4
0
 public TypeInformation(Mono.Cecil.TypeDefinition type)
 {
     Type      = type;
     Fields    = new List <TypeInformation>();
     Attribute = TypeAttribute.Empty();
 }
Esempio n. 5
0
 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",
             }
         },
     });
 }