Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MaterialExpressions.h
- //
- // UMaterialExpressionStaticMultipleSwitch
- //
- UMaterialExpressionStaticMultipleSwitch::UMaterialExpressionStaticMultipleSwitch(const FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- // Structure to hold one-time initialization
- struct FConstructorStatics
- {
- FText NAME_Functions;
- FConstructorStatics()
- : NAME_Functions(LOCTEXT("Functions", "Functions"))
- {
- }
- };
- static FConstructorStatics ConstructorStatics;
- MenuCategories.Add(ConstructorStatics.NAME_Functions);
- Inputs.Add(FCustomInput());
- Inputs.Add(FCustomInput());
- Inputs[0].InputName = TEXT("Input1");
- Inputs[1].InputName = TEXT("Input2");
- bCollapsed = false;
- }
- bool UMaterialExpressionStaticMultipleSwitch::IsResultMaterialAttributes(int32 OutputIndex)
- {
- // If there is a loop anywhere in this expression's inputs then we can't risk checking them
- check(OutputIndex == 0);
- if ((!Value.Expression || Value.Expression->ContainsInputLoop()))
- {
- return Value.Expression->IsResultMaterialAttributes(Value.OutputIndex);
- }
- else
- {
- for (int32 i = 0; i < Inputs.Num(); i++)
- {
- if ((!Inputs[i].Input.Expression || Inputs[i].Input.Expression->ContainsInputLoop()))
- {
- return Inputs[i].Input.Expression->IsResultMaterialAttributes(Inputs[i].Input.OutputIndex);
- }
- }
- }
- return false;
- }
- int32 UMaterialExpressionStaticMultipleSwitch::Compile(class FMaterialCompiler* Compiler, int32 OutputIndex, int32 MultiplexIndex)
- {
- int32 iValue = INDEX_NONE;
- if (Value.Expression)
- {
- bool bSucceeded;
- iValue = Compiler->GetStaticIntValue(Value.Compile(Compiler), bSucceeded);
- if (!bSucceeded)
- {
- return INDEX_NONE;
- }
- }
- for (int32 i = 0; i < Inputs.Num(); i++)
- {
- if (iValue == i)
- {
- return Inputs[iValue].Input.Compile(Compiler, MultiplexIndex);
- }
- }
- return INDEX_NONE;
- }
- void UMaterialExpressionStaticMultipleSwitch::GetCaption(TArray<FString>& OutCaptions) const
- {
- OutCaptions.Add(FString(TEXT("Multiple Switch")));
- }
- const TArray<FExpressionInput*> UMaterialExpressionStaticMultipleSwitch::GetInputs()
- {
- TArray<FExpressionInput*> OutInputs;
- OutInputs.Add(&Value);
- for (int32 i = 0; i < Inputs.Num(); i++)
- {
- OutInputs.Add(&Inputs[i].Input);
- }
- return OutInputs;
- }
- FExpressionInput* UMaterialExpressionStaticMultipleSwitch::GetInput(int32 InputIndex)
- {
- if (InputIndex == 0)
- {
- return &Value;
- }
- return &Inputs[InputIndex - 1].Input;
- }
- FString UMaterialExpressionStaticMultipleSwitch::GetInputName(int32 InputIndex) const
- {
- if (InputIndex == 0)
- {
- return TEXT("Value");
- }
- if (InputIndex < Inputs.Num())
- {
- return Inputs[InputIndex - 1].InputName;
- }
- return TEXT("");
- }
- #if WITH_EDITOR
- uint32 UMaterialExpressionStaticMultipleSwitch::GetInputType(int32 InputIndex)
- {
- if (InputIndex == 0)
- {
- return MCT_Float;
- }
- else
- {
- return MCT_Unknown;
- }
- }
- #endif
- #if WITH_EDITOR
- void UMaterialExpressionStaticMultipleSwitch::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
- {
- // strip any spaces from input name
- UProperty* PropertyThatChanged = PropertyChangedEvent.Property;
- if (PropertyThatChanged && PropertyThatChanged->GetFName() == FName(TEXT("InputName")))
- {
- for (int32 i = 0; i<Inputs.Num(); i++)
- {
- Inputs[i].InputName.ReplaceInline(TEXT(" "), TEXT(""));
- }
- }
- if (PropertyChangedEvent.MemberProperty)
- {
- const FName PropertyName = PropertyChangedEvent.MemberProperty->GetFName();
- if (PropertyName == GET_MEMBER_NAME_CHECKED(UMaterialExpressionCustom, Inputs))
- {
- if (GraphNode)
- {
- GraphNode->ReconstructNode();
- }
- }
- }
- Super::PostEditChangeProperty(PropertyChangedEvent);
- }
- #endif // WITH_EDITOR
Advertisement
Add Comment
Please, Sign In to add comment