VC++ for Unreal Engine[edit]

define[edit]

MY[edit]

#define  MYPROJECT_API  DLLEXPORT

FName[edit]

FName _name = ......;
UE_LOG(LogTemp, Log, TEXT("==> %s"), *_name.ToString());

FString[edit]

FString _str = ......;
UE_LOG(LogTemp, Log, TEXT("==> %s"), *_str);
FString TestHUDString = FString(TEXT("This is my test FString."));
char* 変換[edit]
FSTring _name = ....;
FString mpath = FString(TEXT("/Game/OBJ/")) + _name;
UE_LOG(LogTemp, Log, TEXT("material = %s"), *mpath);
::remove(TCHAR_TO_ANSI (*mpath));

Log[edit]

UE_LOG(LogTemp, Log, TEXT("material = %s"), *(CreatedObject->GetName()));

オブジェクトの中心[edit]

FVector center1 = mesh->GetBounds().GetSphere().Center;
FVector center2 = mesh->GetBoundingBox().GetCenter();

雑メモ[edit]

Actor[edit]

AActor* act = Cast<AActor>(CreatedObject);
act->SetActorLocation(...);

Subsystem[edit]

#include "Subsystems/EditorAssetSubsystem.h"
#include <Subsystems/AssetEditorSubsystem.h>
#include <Subsystems/ActorEditorContextSubsystem.h>
#include <Toolkits/AssetEditorModeUILayer.h>
#include <TransformMeshesTool.h>

UStaticMeshEditorSubsystem* me = GEditor->GetEditorSubsystem<UStaticMeshEditorSubsystem>();
UEditorActorSubsystem* ea = GEditor->GetEditorSubsystem<UEditorActorSubsystem>();
UActorEditorContextSubsystem* ac = GEditor->GetEditorSubsystem<UActorEditorContextSubsystem>();
UAssetEditorSubsystem* ae = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>();
UAssetEditorUISubsystem* ui = GEditor->GetEditorSubsystem<UAssetEditorUISubsystem>();
UEditorAssetSubsystem* aa = GEditor->GetEditorSubsystem<UEditorAssetSubsystem>();
雑コード[edit]
// Fill out your copyright notice in the Description page of Project Settings.

#include "MyEditorSubsystem.h"
#include "Subsystems/EditorAssetSubsystem.h"
void UMyEditorSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
	Super::Initialize(Collection);
	//static FName ImporterRulesAppliedName = FName(TEXT("importer_rules_applied"));
	//static FString TrueString = FString(TEXT("True"));

	//SetImportedAssetTagAction = NewObject<UIRActionSetAssetTags>();
	//SetImportedAssetTagAction->AssetTags.Add(ImporterRulesAppliedName, TrueString);
	//CheckImportedAssetTagAction = NewObject<UIRQueryCheckAssetTag>();
	//CheckImportedAssetTagAction->AssetTagKey = ImporterRulesAppliedName;
	//CheckImportedAssetTagAction->AssetTagValue = TrueString;

	if (GEditor == NULL) return;
	UImportSubsystem* ImportSubsystem = GEditor->GetEditorSubsystem<UImportSubsystem>();
	
	if (ImportSubsystem!=NULL)
	{
		OnAssetPostImportHandle = ImportSubsystem->OnAssetPostImport.AddUObject(this, &UMyEditorSubsystem::OnAssetPostImport);

		/*
		ImportSubsystem->OnAssetPostImport.AddLambda([this](UFactory* Factory, UObject* CreatedObject)
			{
				//UE_LOG(LogTemp, Log, TEXT("UMyEditorSubsystem::Deinitialize()"));
				//UE_LOG(LogTemp, Log, TEXT("================================================"));
			
				if (Factory != NULL) {
					FName _name = Factory->GetFName();
					UE_LOG(LogTemp, Log, TEXT("==> %s"), *_name.ToString());
				}
				else {
					//UE_LOG(LogTemp, Log, TEXT("Factory is NULL"))
				}

				//UMaterialEditorMeshComponent* xxx = (UMaterialEditorMeshComponent*)CreatedObject;
				//xxx->Set
				UEditorAssetSubsystem* EditorAssetSubsystem = GEditor->GetEditorSubsystem<UEditorAssetSubsystem>();

				if (CreatedObject != NULL) {
					FString _name = CreatedObject->GetName();
					//UE_LOG(LogTemp, Log, TEXT("SSS> %s"), *_name);
					if (_name.Find(FString(TEXT("MATERIAL_"))) == 0) {
						UE_LOG(LogTemp, Log, TEXT("GGGGGGGGGGGGGGGGGGGGGGGG> %s"), *_name);
						//UMaterialInstanceDynamic* material = (UMaterialInstanceDynamic*)CreatedObject;
						//UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NULL, CreatedObject);
						//CreatedObject = ma
						//material->SetVectorParameterValue(FName(TEXT("BaseColor")), FLinearColor(1.0f, 0.0f, 0.0f));
						//UMaterialInstance* material = (UMaterialInstance*)CreatedObject;
						//*CreatedObject = *material;
						//UMaterialInstance* material = (UMaterialInstance*)CreatedObject;

						//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("diffuse_color")), TEXT("{R:1.0, G:0.0, B:0.0}"));
						//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("base_color")), TEXT("{R:1.0, G:0.0, B:0.0}"));
						//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("BaseColor")), TEXT("{R:1.0, G:0.0, B:0.0}"));
						//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("DiffuseColor")), TEXT("{R:1.0, G:0.0, B:0.0}"));
						
						//FString _tag;
						//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "BaseColor");
						//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
						//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "Color");
						//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
						//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "DiffuseColor");
						//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
						//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "base_color");
						//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
						//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "diffuse_color");
						//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
					
						
						//CreatedObject->Modify();

						//UMaterial* material = (UMaterial*)CreatedObject;
						//material->Set
						

						//UMaterialInstanceDynamic* material = Cast<UMaterialInstanceDynamic>(CreatedObject);
						//UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NULL, CreatedObject);
						//material->SetVectorParameterValue(FName(TEXT("Base Color")), FLinearColor(1.0f, 0.0f, 0.0f));


						//UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NULL, CreatedObject);


			
	
						//material->Modify();
						
						//material->SetVectorParameterValue(FName(TEXT("Base Color")), FLinearColor(1.0f, 0.0f, 0.0f));

						//CreatedObject->Modify();
						
						
						//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("diffuse_color")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
						//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("Input DiffuseColor")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
						//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("Input DiffuseColor (Vector3)")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
						//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("base_color")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
						//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("BaseColor")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
						
						//TMap<FName, FString> _maps = EditorAssetSubsystem->GetMetadataTagValues(material);
						//for (auto& aaa : _maps) {
						//	UE_LOG(LogTemp, Log, TEXT("xxxxxxxxxxxxxxx> %s  %s"), *(aaa.Key).ToString(), *aaa.Value);
						//}
					}
				}
				//UE_LOG(LogTemp, Log, TEXT("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));
				
				

				//check(IsValid(CheckImportedAssetTagAction) && IsValid(SetImportedAssetTagAction));
				//const bool bIsReimport = CheckImportedAssetTagAction->Test(Factory, CreatedObject);
				//UImporterRulesDeveloperSettings* DeveloperSettings = GetMutableDefault<UImporterRulesDeveloperSettings>();
				//check(IsValid(DeveloperSettings));
				for (auto RulesIt = DeveloperSettings->RegisteredRules.CreateIterator(); RulesIt; ++RulesIt)
				{
					if (CreatedObject->IsA(RulesIt.Key()))
					{
						for (const auto Rule : RulesIt.Value().Rules)
						{
							if (!bIsReimport || Rule->bApplyOnReimport)
							{
								Rule->Apply(Factory, CreatedObject);
							}
						}
					}
				}
			}
		);*/
	}
}



void UMyEditorSubsystem::OnAssetPostImport(UFactory* Factory, UObject* CreatedObject)
{
	if (CreatedObject != NULL) {
		FString _namexx = CreatedObject->GetName();
		UE_LOG(LogTemp, Log, TEXT("AAAAAAAAAAAAAAAAAAAAAAAAA> %s"), *_namexx);

		FString _classxx = CreatedObject->GetClass()->GetName(); // Material
		UE_LOG(LogTemp, Log, TEXT("class -=========> %s"), *_classxx);


		if (_classxx.Equals(FString(TEXT("StaticMesh")))) {
			UE_LOG(LogTemp, Log, TEXT("AAAAAAAAAAAAAAAAAAAAAAAAA> %s"), *_namexx);
			UE_LOG(LogTemp, Log, TEXT("class -=========> %s"), *_classxx);

			UStaticMesh* mesh = Cast<UStaticMesh>(CreatedObject);

			
			//CreatedObject->GetAssetRegistryTags(asset);

			//for (auto& aaa : masset) {
				//aaa.ToSt

			/*
			//TArray
			TArray<FStaticMaterial> smat = mesh->GetStaticMaterials();
			int i = 0;
			for (auto& mat : smat) {
				//auto* matif = mesh->GetMaterial(i);
				//FString mname = matif->GetName();
				
				auto matif = mat.MaterialInterface;
				FString mname = matif.GetName();
				UE_LOG(LogTemp, Log, TEXT("material -=========> %d: %s"),i, *mname);

				UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(matif, NULL);
				material->SetVectorParameterValue(FName(TEXT("BaseColor")), FLinearColor(0.0f, 0.0f, 1.0f));
				mesh->SetMaterial(i, material);
				i++;
				//delete &mat;
			}
			//mesh->SetStaticMaterials(smat);
			*/

			int i = 0;
			auto* matif = mesh->GetMaterial(i);
			while (matif != NULL) 
			{
				FString mname = matif->GetName();

				//auto matif = mat.MaterialInterface;
				//FString mname = matif.GetName();
				UE_LOG(LogTemp, Log, TEXT("material -=========> %d: %s"), i, *mname);

				UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(matif, NULL);
				material->SetVectorParameterValue(FName(TEXT("DeffuseColor")), FLinearColor(0.0f, 0.0f, 1.0f));
				material->SetVectorParameterValue(FName(TEXT("base_color")), FLinearColor(0.0f, 0.0f, 1.0f));
				
				//UStaticMeshSocket 
				//mesh->AddSocket()
				//mesh->SetMaterial(i, material);
				i++;
				//delete &mat;
				matif = mesh->GetMaterial(i);
			}









			/*
			//UMaterialInterface* matif = mesh->GetMaterial(0);
			auto* matif = mesh->GetMaterial(0);
			FString mname = matif->GetName();
			UE_LOG(LogTemp, Log, TEXT("material -=========> %s"), *mname);

			UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(matif, NULL);

			material->SetVectorParameterValue(FName(TEXT("BaseColor")), FLinearColor(1.0f, 0.0f, 0.0f));
			//material->SetVectorParameterValue(FName(TEXT("DiffuseColor")), FLinearColor(1.0f, 0.0f, 0.0f));
			//material->SetVectorParameterValue(FName(TEXT("Color")), FLinearColor(1.0f, 0.0f, 0.0f));

			mesh->SetMaterial(0, material);
			*/

		}







		/*

		//UE_LOG(LogTemp, Log, TEXT("SSS> %s"), *_name);
		if (_namexx.Find(FString(TEXT("MATERIAL_"))) == 0) {
			UE_LOG(LogTemp, Log, TEXT("GGGGGGGGGGGGGGGGGGGGGGGG> %s"), *_namexx);

			//UEditorAssetSubsystem* EditorAssetSubsystem = GEditor->GetEditorSubsystem<UEditorAssetSubsystem>();

			

			//UMaterialInstanceDynamic* material = (UMaterialInstanceDynamic*)CreatedObject;
			//UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NULL, CreatedObject);
			//CreatedObject = ma
			//material->SetVectorParameterValue(FName(TEXT("BaseColor")), FLinearColor(1.0f, 0.0f, 0.0f));
			//UMaterialInstance* material = (UMaterialInstance*)CreatedObject;
			//CreatedObject = *material;
			//UMaterialInstance* material = (UMaterialInstance*)CreatedObject;

			//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("diffuse_color")), TEXT("{R:1.0, G:0.0, B:0.0}"));
			//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("base_color")), TEXT("{R:1.0, G:0.0, B:0.0}"));
			//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("BaseColor")), TEXT("{R:1.0, G:0.0, B:0.0}"));
			//EditorAssetSubsystem->SetMetadataTag(CreatedObject, FName(TEXT("DiffuseColor")), TEXT("{R:1.0, G:0.0, B:0.0}"));

			//FString _tag;
			//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "BaseColor");
			//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
			//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "Color");
			//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
			//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "DiffuseColor");
			//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
			//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "base_color");
			//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);
			//_tag = EditorAssetSubsystem->GetMetadataTag(CreatedObject, "diffuse_color");
			//UE_LOG(LogTemp, Log, TEXT("TTTTTTTTTTTTTTTTTTTTTTTTT> %s"), *_tag);


			//CreatedObject->Modify();

			//UMaterial* material = (UMaterial*)CreatedObject;
			//material->Set


			FString _class = CreatedObject->GetClass()->GetName(); // Material
			UE_LOG(LogTemp, Log, TEXT("class -=========> %s"), *_class);
			//material->

			//FMaterialCompiler* xxxx = new FMaterialCompiler();

			UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NULL, CreatedObject);
			material->SetVectorParameterValue(FName(TEXT("Base Color")), FLinearColor(1.0f, 0.0f, 0.0f));


			//FName _sname = CreatedObject->SourceFileTagName();
			FAssetData asset;
			//TArray<UObject::FAssetRegistryTag> masset;
			CreatedObject->GetAssetRegistryTags(asset);
			
			//for (auto& aaa : masset) {
				//aaa.ToSt
			
			//CreatedObject->Ass
			//UE_LOG(LogTemp, Log, TEXT("====================> %s"), *(masset.ToString()));
			
			
			
			//asset.key

			//UE_LOG(LogTemp, Log, TEXT("====================> %s"), *_sname.ToString());



			//FAssetData
			//CreatedObject->GetMate
			//UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NULL, CreatedObject);




			//material->Modify();

			//material->SetVectorParameterValue(FName(TEXT("Base Color")), FLinearColor(1.0f, 0.0f, 0.0f));

			//CreatedObject->Modify();


			//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("diffuse_color")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
			//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("Input DiffuseColor")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
			//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("Input DiffuseColor (Vector3)")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
			//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("base_color")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));
			//EditorAssetSubsystem->SetMetadataTag(material, FName(TEXT("BaseColor")), TEXT("{\"R\":1.0, \"G\":0.0, \"B\":0.0}"));

			//TMap<FName, FString> _maps = EditorAssetSubsystem->GetMetadataTagValues(material);
			//for (auto& aaa : _maps) {
			//	UE_LOG(LogTemp, Log, TEXT("xxxxxxxxxxxxxxx> %s  %s"), *(aaa.Key).ToString(), *aaa.Value);
			//}
		}*/
	}
	//UE_LOG(LogTemp, Log, TEXT("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));

}



void UMyEditorSubsystem::Deinitialize()
{
	if (GEditor!=NULL)
	{
		UImportSubsystem* ImportSubsystem = GEditor->GetEditorSubsystem<UImportSubsystem>();
		if (ImportSubsystem!=NULL)
		{
			ImportSubsystem->OnAssetPostImport.Remove(OnAssetPostImportHandle);
		}
	}
	Super::Deinitialize();
}
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "EditorSubsystem.h"
#include "MyEditorSubsystem.generated.h"

/**
* 
*/
UCLASS(BlueprintType, CollapseCategories)
class MYPROJECT_API UMyEditorSubsystem : public UEditorSubsystem
{
	GENERATED_BODY()

	//const TMap<FName, FString> _maps;

public:
	// Begin UEditorSubsystem Interface
	virtual void Initialize(FSubsystemCollectionBase& Collection) override;
	virtual void Deinitialize() override;
	// End UEditorSubsystem Interface


	FDelegateHandle OnAssetPostImportHandle;

	//UPROPERTY(Transient)
	void OnAssetPostImport(UFactory* Factory, UObject* CreatedObject);
	
};

トップ   新規 ページ一覧 検索 最終更新   ヘルプ   最終更新のRSS