public override string TransformType(ITypeInfo type) { var result = base.TransformType(type); var nativeType = type.Native; if (nativeType == typeof(string)) { result = "FString"; } else if (nativeType == typeof(Vector3 <float>) || nativeType == typeof(Vector3 <double>)) { result = "FVector"; } else if (nativeType == typeof(Vector2 <float>) || nativeType == typeof(Vector2 <double>)) { result = "FVector2D"; } else if (nativeType == typeof(Vector4 <float>) || nativeType == typeof(Vector4 <double>)) { result = "FVector4"; } else if (nativeType == typeof(Quaternion <float>) || nativeType == typeof(Quaternion <double>)) { result = "FQuat"; } else if (nativeType == typeof(Rotation <float>) || nativeType == typeof(Rotation <double>)) { result = "FRotator"; } else if (nativeType == typeof(Box <float>) || nativeType == typeof(Box <double>)) { result = "FBox"; } else if (nativeType == typeof(Rect <float>) || nativeType == typeof(Rect <double>)) { result = "FBox2D"; } else { result = NameTransformer.TransformName(type, type.Name, NameContext.Type); } result = result.Trim(); if (string.IsNullOrEmpty(result)) { throw new NotSupportedException($"Type {type.GetPath()} not resolved in {nameof(UnrealTypeTransformer)}."); } return(result); }
public override string Print(CXXFileType fileType) { base.Print(fileType); var sb = new StringBuilder(); if (fileType == CXXFileType.Declaration) { var isForBlueprint = true; if (isForBlueprint) { sb.AppendLine($"UCLASS(BlueprintType)"); } sb.AppendLine($"class {PrintAPI()} {NameTransformer.TransformName(Info, Info.Name, NameContext.Type)}"); var baseClassName = "UObject"; sb.AppendLine($": public {baseClassName}", 1); sb.OpenBracket(); if (isForBlueprint) { sb.AppendLine($"GENERATED_BODY()", 1); sb.AppendEmptyLine(); } sb.AppendLine($"public:"); Info.Properties.ForEach(o => { sb.Append(PropertyPrinter.Print((UnrealPropertyInfo)o, CXXFileType.Declaration)); sb.AppendEmptyLine(); }); sb.RemoveLastLine(); sb.CloseBracketWithSemicolon(); } return(sb.ToString()); }
public string Print(CXXFunctionInfo info, CXXFileType fileType) { var sb = new StringBuilder(); var returnTypeStr = TypeTransformer.TransformType(info.Type); var parameterStr = PrintParameters(info, fileType); info.ForAttribute <AsyncAttribute>(attr => { parameterStr += $", std::function<void({(info.Type.Native != typeof(void) ? returnTypeStr : string.Empty)})> Callback"; returnTypeStr = "void"; }); sb.AppendLine($"{(info.IsStatic ? "static " : string.Empty)}{returnTypeStr} {NameTransformer.TransformName(info, info.Name, NameContext.Method)}({parameterStr})", 1); return(sb.ToString()); }
public string Print(IMemberInfo info, CXXFileType fileType) { var sb = new StringBuilder(); sb.Append($"{(info.Mutability == Mutability.Immutable ? "const " : string.Empty)}{TypeTransformer.TransformType(info.Type)}{(info.Type.TypeType == TypeType.Reference ? "*" : "&")} {NameTransformer.TransformName(info, info.Name, NameContext.Parameter)}"); return(sb.ToString()); }
public string Print(CXXPropertyInfo info, CXXFileType fileType) { var sb = new StringBuilder(); sb.AppendLine($"{(info.IsStatic ? "static " : string.Empty)}{TypeTransformer.TransformType(info)} {NameTransformer.TransformName(info, info.Name, NameContext.Property)};", 1); return(sb.ToString()); }