Download LyraStarterGame/Source/LyraGame/Teams/LyraTeamDisplayAsset.cpp from Alexhas2/unitysamples: direct link, hf CLI and curl.
- Browser
- Download file 3.25 kB
-
https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Source/LyraGame/Teams/LyraTeamDisplayAsset.cpp
- Command line
-
hf download hf://datasets/Alexhas2/unitysamples/LyraStarterGame/Source/LyraGame/Teams/LyraTeamDisplayAsset.cpp
-
curl -L -o LyraTeamDisplayAsset.cpp https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Source/LyraGame/Teams/LyraTeamDisplayAsset.cpp
3.25 kB
| // Copyright Epic Games, Inc. All Rights Reserved. | |
| void ULyraTeamDisplayAsset::ApplyToMaterial(UMaterialInstanceDynamic* Material) | |
| { | |
| if (Material) | |
| { | |
| for (const auto& KVP : ScalarParameters) | |
| { | |
| Material->SetScalarParameterValue(KVP.Key, KVP.Value); | |
| } | |
| for (const auto& KVP : ColorParameters) | |
| { | |
| Material->SetVectorParameterValue(KVP.Key, FVector(KVP.Value)); | |
| } | |
| for (const auto& KVP : TextureParameters) | |
| { | |
| Material->SetTextureParameterValue(KVP.Key, KVP.Value); | |
| } | |
| } | |
| } | |
| void ULyraTeamDisplayAsset::ApplyToMeshComponent(UMeshComponent* MeshComponent) | |
| { | |
| if (MeshComponent) | |
| { | |
| for (const auto& KVP : ScalarParameters) | |
| { | |
| MeshComponent->SetScalarParameterValueOnMaterials(KVP.Key, KVP.Value); | |
| } | |
| for (const auto& KVP : ColorParameters) | |
| { | |
| MeshComponent->SetVectorParameterValueOnMaterials(KVP.Key, FVector(KVP.Value)); | |
| } | |
| const TArray<UMaterialInterface*> MaterialInterfaces = MeshComponent->GetMaterials(); | |
| for (int32 MaterialIndex = 0; MaterialIndex < MaterialInterfaces.Num(); ++MaterialIndex) | |
| { | |
| if (UMaterialInterface* MaterialInterface = MaterialInterfaces[MaterialIndex]) | |
| { | |
| UMaterialInstanceDynamic* DynamicMaterial = Cast<UMaterialInstanceDynamic>(MaterialInterface); | |
| if (!DynamicMaterial) | |
| { | |
| DynamicMaterial = MeshComponent->CreateAndSetMaterialInstanceDynamic(MaterialIndex); | |
| } | |
| for (const auto& KVP : TextureParameters) | |
| { | |
| DynamicMaterial->SetTextureParameterValue(KVP.Key, KVP.Value); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| void ULyraTeamDisplayAsset::ApplyToNiagaraComponent(UNiagaraComponent* NiagaraComponent) | |
| { | |
| if (NiagaraComponent) | |
| { | |
| for (const auto& KVP : ScalarParameters) | |
| { | |
| NiagaraComponent->SetVariableFloat(KVP.Key, KVP.Value); | |
| } | |
| for (const auto& KVP : ColorParameters) | |
| { | |
| NiagaraComponent->SetVariableLinearColor(KVP.Key, KVP.Value); | |
| } | |
| for (const auto& KVP : TextureParameters) | |
| { | |
| UTexture* Texture = KVP.Value; | |
| NiagaraComponent->SetVariableTexture(KVP.Key, Texture); | |
| } | |
| } | |
| } | |
| void ULyraTeamDisplayAsset::ApplyToActor(AActor* TargetActor, bool bIncludeChildActors) | |
| { | |
| if (TargetActor != nullptr) | |
| { | |
| TargetActor->ForEachComponent(bIncludeChildActors, [this](UActorComponent* InComponent) | |
| { | |
| if (UMeshComponent* MeshComponent = Cast<UMeshComponent>(InComponent)) | |
| { | |
| ApplyToMeshComponent(MeshComponent); | |
| } | |
| else if (UNiagaraComponent* NiagaraComponent = Cast<UNiagaraComponent>(InComponent)) | |
| { | |
| ApplyToNiagaraComponent(NiagaraComponent); | |
| } | |
| }); | |
| } | |
| } | |
| void ULyraTeamDisplayAsset::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) | |
| { | |
| Super::PostEditChangeProperty(PropertyChangedEvent); | |
| for (ULyraTeamSubsystem* TeamSubsystem : TObjectRange<ULyraTeamSubsystem>()) | |
| { | |
| TeamSubsystem->NotifyTeamDisplayAssetModified(this); | |
| } | |
| } | |