void FScriptBlueprintCompiler::CreateClassVariablesFromBlueprint()
{
	Super::CreateClassVariablesFromBlueprint();

	UScriptBlueprint* Blueprint = ScriptBlueprint();
	UScriptBlueprintGeneratedClass* NewScripClass = CastChecked<UScriptBlueprintGeneratedClass>(NewClass);
	NewScripClass->ScriptProperties.Empty();

	for (auto& Field : ScriptDefinedFields)
	{
		UClass* InnerType = Field.Class;
		if (Field.Class->IsChildOf(UProperty::StaticClass()))
		{
			FString PinCategory;
			if (Field.Class->IsChildOf(UStrProperty::StaticClass()))
			{
				PinCategory = Schema->PC_String;
			}
			else if (Field.Class->IsChildOf(UFloatProperty::StaticClass()))
			{
				PinCategory = Schema->PC_Float;
			}
			else if (Field.Class->IsChildOf(UIntProperty::StaticClass()))
			{
				PinCategory = Schema->PC_Int;
			}
			else if (Field.Class->IsChildOf(UBoolProperty::StaticClass()))
			{
				PinCategory = Schema->PC_Boolean;
			}
			else if (Field.Class->IsChildOf(UObjectProperty::StaticClass()))
			{
				PinCategory = Schema->PC_Object;
				// @todo: some scripting extensions (that are strongly typed) can handle this better
				InnerType = UObject::StaticClass();
			}
			if (!PinCategory.IsEmpty())
			{
				FEdGraphPinType ScriptPinType(PinCategory, TEXT(""), InnerType, false, false);
				UProperty* ScriptProperty = CreateVariable(Field.Name, ScriptPinType);
				if (ScriptProperty != NULL)
				{
					ScriptProperty->SetMetaData(TEXT("Category"), *Blueprint->GetName());
					ScriptProperty->SetPropertyFlags(CPF_BlueprintVisible | CPF_Edit);
					NewScripClass->ScriptProperties.Add(ScriptProperty);
				}
			}
		}
	}

	CreateScriptContextProperty();
}
コード例 #2
0
	void FKlawrBlueprintCompiler::KlawrCreateClassVariablesFromBlueprint(UKlawrBlueprintGeneratedClass* NewScripClass)
	{
		NewScripClass->ScriptProperties.Empty();
		NewScripClass->GetScriptDefinedFields(ScriptDefinedFields);

		for (auto& Field : ScriptDefinedFields)
		{
			UClass* InnerType = Field.Class;
			if (Field.Class->IsChildOf(UProperty::StaticClass()))
			{
				FString PinCategory;
				if (Field.Class->IsChildOf(UStrProperty::StaticClass()))
				{
					PinCategory = Schema->PC_String;
				}
				else if (Field.Class->IsChildOf(UFloatProperty::StaticClass()))
				{
					PinCategory = Schema->PC_Float;
				}
				else if (Field.Class->IsChildOf(UIntProperty::StaticClass()))
				{
					PinCategory = Schema->PC_Int;
				}
				else if (Field.Class->IsChildOf(UBoolProperty::StaticClass()))
				{
					PinCategory = Schema->PC_Boolean;
				}
				else if (Field.Class->IsChildOf(UObjectProperty::StaticClass()))
				{
					PinCategory = Schema->PC_Object;
					// @todo: some scripting extensions (that are strongly typed) can handle this better

					InnerType = Field.innerClass;
				}
				if (!PinCategory.IsEmpty())
				{
					FEdGraphPinType ScriptPinType(PinCategory, TEXT(""), InnerType, false, false);
					UProperty* ScriptProperty = CreateVariable(Field.Name, ScriptPinType);

					bool hasCategoryMeta = false;
					for (auto meta : Field.metas)
					{
						hasCategoryMeta |= meta.Key == TEXT("Category");
						ScriptProperty->SetMetaData(*meta.Key, *meta.Value);
					}

					if (ScriptProperty != NULL)
					{
						// If no Category meta is provided in the UPROPERTY attribute, generate one out of the class name
						if (!hasCategoryMeta)
						{
							ScriptProperty->SetMetaData(TEXT("Category"), *Blueprint->GetName());
						}
						ScriptProperty->SetPropertyFlags(CPF_BlueprintVisible | CPF_Edit);
						
						if (NewScripClass->GetAdvancedDisplay(*(Field.Name.ToString())))
						{
							ScriptProperty->SetPropertyFlags(CPF_AdvancedDisplay);
						}

						if (NewScripClass->GetSaveGame(*(Field.Name.ToString())))
						{
							ScriptProperty->SetPropertyFlags(CPF_SaveGame);
						}

						NewScripClass->ScriptProperties.Add(ScriptProperty);
					}
				}
			}
		}

		CreateScriptContextProperty();
	}