UE4制作便攜小工具—批量添加前綴(CPP)
在之前的代碼小改一下就行~
就是要加的前綴把對象名和在一塊然后重命名就好~
頭文件
CPP文件
往后的不用看了,因為有某些限制不然發(fā)不出來
// Fill out your copyright notice in the Description page of Project Settings. #include "AddTopName.h" #include <EditorUtilityLibrary.h> void UAddTopName::ThePrefixAdded(FString Prefix) { ? //防呆操作 ? if(Prefix.IsEmpty()) ? { ? ? ?return; ? } ? //獲得選中資產(chǎn) ? TArray<UObject*>SelecteObjects = UEditorUtilityLibrary::GetSelectedAssets(); ? //計數(shù) ? uint32 Counter = 0; ? for(UObject* SelecteObject : SelecteObjects) ? { ? ? ?if(ensure(SelecteObject)) ? ? ?{ ? ? ? ? //獲取對象名 ? ? ? ? FString AssetName = SelecteObject->GetName(); ? ? ? ? //重命名資產(chǎn) ? ? ? ? FString NewName = Prefix + AssetName; ? ? ? ? UEditorUtilityLibrary::RenameAsset(SelecteObject,NewName); ? ? ? ? Counter++; ? ? ? ? ? ? ?} ? } ? GiveFeedback(TEXT("ThePrefixAdded"),Counter); } #pragma region Hellper void UAddTopName::PrintToScreen(FString Message, FColor Color) { ? if(ensure(GEngine)) ? { ? ? ?GEngine->AddOnScreenDebugMessage(-1,2.5f,Color,Message); ? } } void UAddTopName::GiveFeedback(FString Method, uint32 Counter) { ? FString Message = FString("No matching files found"); ? FColor Color = Counter > 0 ? FColor::Green : FColor::Red; ? if(Counter>0) ? { ? ? ?Message = Method.AppendChar(' '); ? ? ?Message.AppendInt(Counter); ? ? ?Message.Append(Counter == 1 ? TEXT("file") : TEXT("files")); ? } ? PrintToScreen(Message,Color); } #pragma endregion