protected override void EmitInstructionsFor(FieldReference fieldDef) { this.CallDeserializationMethod(fieldDef); TypeReference typeRef = base.TypeOf(fieldDef); if ((!MethodEmitterBase.IsStruct(base.TypeDef) || !UnityEngineTypePredicates.IsUnityEngineValueType(base.TypeDef)) && (MethodEmitterBase.IsStruct(typeRef) || MethodEmitterBase.RequiresAlignment(typeRef))) { this.EmitAlign(); } }
private List <TypeTreeNode> TypeRefToTypeTreeNodes(TypeReference typeRef, string name, int indent, bool isElement) { var align = false; if (!IsStruct(TypeDef) || !UnityEngineTypePredicates.IsUnityEngineValueType(TypeDef)) { if (IsStruct(typeRef) || RequiresAlignment(typeRef)) { align = true; } } var nodes = new List <TypeTreeNode>(); if (typeRef.IsPrimitive) { var primitiveName = typeRef.Name; switch (primitiveName) { case "Boolean": primitiveName = "bool"; break; case "Byte": primitiveName = "UInt8"; break; case "SByte": primitiveName = "SInt8"; break; case "Int16": primitiveName = "SInt16"; break; case "UInt16": primitiveName = "UInt16"; break; case "Int32": primitiveName = "SInt32"; break; case "UInt32": primitiveName = "UInt32"; break; case "Int64": primitiveName = "SInt64"; break; case "UInt64": primitiveName = "UInt64"; break; case "Char": primitiveName = "char"; break; case "Double": primitiveName = "double"; break; case "Single": primitiveName = "float"; break; default: throw new NotSupportedException(); } if (isElement) { align = false; } nodes.Add(new TypeTreeNode(primitiveName, name, indent, align)); } else if (IsSystemString(typeRef)) { Helper.AddString(nodes, name, indent); } else if (IsEnum(typeRef)) { nodes.Add(new TypeTreeNode("SInt32", name, indent, align)); } else if (CecilUtils.IsGenericList(typeRef)) { var elementRef = CecilUtils.ElementTypeOfCollection(typeRef); nodes.Add(new TypeTreeNode(typeRef.Name, name, indent, align)); Helper.AddArray(nodes, indent + 1); nodes.AddRange(TypeRefToTypeTreeNodes(elementRef, "data", indent + 2, true)); } else if (typeRef.IsArray) { var elementRef = typeRef.GetElementType(); nodes.Add(new TypeTreeNode(typeRef.Name, name, indent, align)); Helper.AddArray(nodes, indent + 1); nodes.AddRange(TypeRefToTypeTreeNodes(elementRef, "data", indent + 2, true)); } else if (UnityEngineTypePredicates.IsUnityEngineObject(typeRef)) { Helper.AddPPtr(nodes, typeRef.Name, name, indent); } else if (UnityEngineTypePredicates.IsSerializableUnityClass(typeRef) || UnityEngineTypePredicates.IsSerializableUnityStruct(typeRef)) { switch (typeRef.FullName) { case "UnityEngine.AnimationCurve": Helper.AddAnimationCurve(nodes, name, indent); break; case "UnityEngine.Gradient": Helper.AddGradient(nodes, name, indent); break; case "UnityEngine.GUIStyle": Helper.AddGUIStyle(nodes, name, indent); break; case "UnityEngine.RectOffset": Helper.AddRectOffset(nodes, name, indent); break; case "UnityEngine.Color32": Helper.AddColor32(nodes, name, indent); break; case "UnityEngine.Matrix4x4": Helper.AddMatrix4x4(nodes, name, indent); break; case "UnityEngine.Rendering.SphericalHarmonicsL2": Helper.AddSphericalHarmonicsL2(nodes, name, indent); break; case "UnityEngine.PropertyName": Helper.AddPropertyName(nodes, name, indent); break; } } else { nodes.Add(new TypeTreeNode(typeRef.Name, name, indent, align)); var typeDef = typeRef.Resolve(); var typeDefinitionConverter = new TypeDefinitionConverter(typeDef, Helper, indent + 1); nodes.AddRange(typeDefinitionConverter.ConvertToTypeTreeNodes()); } return(nodes); }