Advertisement
Guest User

Set Property

a guest
Jun 20th, 2016
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.18 KB | None | 0 0
  1. Here is My Structs...
  2.  
  3.  
  4.     USTRUCT(BlueprintType)
  5.     struct FsPropertyValues : public FTableRowBase
  6.     {
  7.         GENERATED_USTRUCT_BODY();
  8.    
  9.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  10.             AActor* Actor;
  11.    
  12.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  13.             UActorComponent* ActorComponent;
  14.    
  15.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  16.             UProperty* Property;
  17.    
  18.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  19.             FString PropertyType = "";
  20.    
  21.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  22.             bool Value_Bool = false;
  23.    
  24.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  25.             FString Value_Enum = "";
  26.    
  27.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  28.             uint8 Value_Byte = 0;
  29.    
  30.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  31.             float Value_Float = 0;
  32.    
  33.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  34.             int32 Value_Int = 0;
  35.    
  36.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  37.             FString Value_String = "";
  38.    
  39.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  40.             FName Value_Name = "";
  41.    
  42.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  43.             FText Value_Text;
  44.    
  45.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  46.             FVector Value_Vector = FVector::FVector(0, 0, 0);
  47.    
  48.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  49.             FVector2D Value_Vector2D = FVector2D::FVector2D(0, 0);
  50.    
  51.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  52.             FRotator Value_Rotator = FRotator::FRotator(0, 0, 0);
  53.    
  54.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  55.             FTransform Value_Transform = FTransform::FTransform();
  56.    
  57.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  58.             FColor Value_Color = FColor::FColor(0, 0, 0, 0);
  59.    
  60.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  61.             FLinearColor Value_LinearColor = FLinearColor::FLinearColor(0, 0, 0, 0);
  62.    
  63.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  64.             int32 xIndex = 0;
  65.     };
  66.    
  67.     USTRUCT(BlueprintType)
  68.     struct FsDataTable_Properties : public FTableRowBase
  69.     {
  70.         GENERATED_USTRUCT_BODY();
  71.    
  72.     public:
  73.    
  74.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  75.             FString Actor;
  76.    
  77.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  78.             FString ActorComponent;
  79.    
  80.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  81.             FString Category;
  82.    
  83.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  84.             FString SubCategory;
  85.    
  86.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  87.             FString DisplayName;
  88.    
  89.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  90.             bool VisibleProperty = true;
  91.    
  92.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  93.             float UIMin = 0;
  94.    
  95.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  96.             float UIMax = 0;
  97.    
  98.         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CosmicIllusion")
  99.             FString EditCondition = "";
  100.     };
  101.  
  102.  
  103.  
  104. Here My Functions to Locate Property and Set Value
  105.  
  106.  
  107.     public:
  108.    
  109.         UFUNCTION(BlueprintCallable, Category = "CosmicIllusion|HUD", CustomThunk)
  110.             static void SetHUDProperty(FsPropertyValues PropertyValue);
  111.    
  112.         DECLARE_FUNCTION(execSetHUDProperty)
  113.         {
  114.             PARAM_PASSED_BY_VAL(PropertyValue, UStrProperty, FsPropertyValues);
  115.    
  116.             P_FINISH;
  117.    
  118.             if (UMaterialBillboardComponent* xNullComponent = Cast<UMaterialBillboardComponent>(PropertyValue.ActorComponent)) { FindProperty(false, PropertyValue.Actor, PropertyValue); }
  119.             else { FindProperty(true, PropertyValue.ActorComponent, PropertyValue); }
  120.         }
  121.    
  122.         void SetPropertyInObject(bool isActorComponent, bool isActorStruct, UProperty* FindProperty, FsPropertyValues PropertyValue, void* GetValuePtr)
  123.         {
  124.    
  125.     #if WITH_EDITOR
  126.             if (isActorComponent) { PropertyValue.ActorComponent->PreEditChange(FindProperty); }
  127.             else { PropertyValue.Actor->PreEditChange(FindProperty); }
  128.     #endif
  129.             void* ValuePtr = GetValuePtr;
  130.    
  131.             if (UStructProperty* StructProperty = Cast<UStructProperty>(PropertyValue.Property))
  132.             {
  133.                 if (isActorStruct && isActorComponent) { ValuePtr = PropertyValue.ActorComponent; }
  134.                 else if (isActorStruct && !isActorComponent) { ValuePtr = PropertyValue.Actor; }
  135.    
  136.                 if (FindProperty && PropertyValue.PropertyType == "FVector") {
  137.                     *StructProperty->ContainerPtrToValuePtr<FVector>(ValuePtr) = PropertyValue.Value_Vector;
  138.                 }
  139.                 else if (FindProperty && PropertyValue.PropertyType == "FVector2D") {
  140.                     *StructProperty->ContainerPtrToValuePtr<FVector2D>(ValuePtr) = PropertyValue.Value_Vector2D;
  141.                 }
  142.                 else if (FindProperty && PropertyValue.PropertyType == "FRotator") {
  143.                     *StructProperty->ContainerPtrToValuePtr<FRotator>(ValuePtr) = PropertyValue.Value_Rotator;
  144.                 }
  145.                 else if (FindProperty && PropertyValue.PropertyType == "FTransform") {
  146.                     *StructProperty->ContainerPtrToValuePtr<FTransform>(ValuePtr) = PropertyValue.Value_Transform;
  147.                 }
  148.                 else if (FindProperty && PropertyValue.PropertyType == "FColor") {
  149.                     *StructProperty->ContainerPtrToValuePtr<FColor>(ValuePtr) = PropertyValue.Value_Color;
  150.                 }
  151.                 else if (FindProperty && PropertyValue.PropertyType == "FLinearColor") {
  152.                     *StructProperty->ContainerPtrToValuePtr<FLinearColor>(ValuePtr) = PropertyValue.Value_LinearColor;
  153.                 }
  154.             }
  155.    
  156.             else if (UFloatProperty* SetProperty = Cast<UFloatProperty>(FindProperty)) { SetProperty->SetFloatingPointPropertyValue(ValuePtr, PropertyValue.Value_Float); }
  157.    
  158.             else if (UByteProperty* SetProperty = Cast<UByteProperty>(FindProperty)) { SetProperty->SetPropertyValue_InContainer(ValuePtr, PropertyValue.Value_Byte); }
  159.             else if (UInt8Property* SetProperty = Cast<UInt8Property>(FindProperty)) { SetProperty->SetPropertyValue_InContainer(ValuePtr, PropertyValue.Value_Int); }
  160.             else if (UUInt32Property* SetProperty = Cast<UUInt32Property>(FindProperty)) { SetProperty->SetPropertyValue_InContainer(ValuePtr, PropertyValue.Value_Int); }
  161.             else if (UUInt64Property* SetProperty = Cast<UUInt64Property>(FindProperty)) { SetProperty->SetPropertyValue_InContainer(ValuePtr, PropertyValue.Value_Int); }
  162.             else if (UInt16Property* SetProperty = Cast<UInt16Property>(FindProperty)) { SetProperty->SetPropertyValue_InContainer(ValuePtr, PropertyValue.Value_Int); }
  163.             else if (UInt64Property* SetProperty = Cast<UInt64Property>(FindProperty)) { SetProperty->SetPropertyValue_InContainer(ValuePtr, PropertyValue.Value_Int); }
  164.    
  165.             else if (UBoolProperty* SetProperty = Cast<UBoolProperty>(FindProperty)) { SetProperty->SetPropertyValue_InContainer(ValuePtr, PropertyValue.Value_Bool); }
  166.             else if (UIntProperty* SetProperty = Cast<UIntProperty>(FindProperty)) { SetProperty->SetPropertyValue_InContainer(ValuePtr, PropertyValue.Value_Int); }
  167.    
  168.             else if (UStrProperty* SetProperty = Cast<UStrProperty>(FindProperty)) { SetProperty->SetPropertyValue_InContainer(ValuePtr, PropertyValue.Value_String); }
  169.             else if (UTextProperty* SetProperty = Cast<UTextProperty>(FindProperty)) { SetProperty->SetPropertyValue_InContainer(ValuePtr, PropertyValue.Value_Text); }
  170.             else if (UNameProperty* SetProperty = Cast<UNameProperty>(FindProperty)) { SetProperty->SetPropertyValue_InContainer(ValuePtr, PropertyValue.Value_Name); }
  171.    
  172.     #if WITH_EDITOR
  173.             if (isActorComponent) { PropertyValue.ActorComponent->PostEditChange(); }
  174.             else { PropertyValue.Actor->PostEditChange(); }
  175.     #endif
  176.         }
  177.    
  178.         template <typename ObjClass> void FindProperty(bool isActorComponent, ObjClass Object, FsPropertyValues FsPropertyValue)
  179.         {
  180.             for (TFieldIterator<UProperty> Prop(Object->GetClass()); Prop; ++Prop)
  181.             {
  182.                 UProperty* RootProperty = *Prop;
  183.                 if (UStructProperty* StructProperty = ExactCast<UStructProperty>(RootProperty)) {
  184.                     void* ValuePtr = StructProperty->ContainerPtrToValuePtr<void>(Object);
  185.                     IterateThroughStructProperty(isActorComponent, StructProperty, ValuePtr, FsPropertyValue);
  186.                 }
  187.                 else
  188.                 {
  189.                     void* ValuePtr = RootProperty->ContainerPtrToValuePtr<void>(Object);
  190.                     if (ParseProperty(isActorComponent, false, RootProperty, NULL, ValuePtr, FsPropertyValue, false)) { break; return; }
  191.                 }
  192.             }
  193.         }
  194.    
  195.         void IterateThroughStructProperty(bool isActorComponent, UStructProperty* StructProperty, void* StructPtr, FsPropertyValues PropertyValue)
  196.         {
  197.             UScriptStruct* Struct = StructProperty->Struct;
  198.             for (TFieldIterator<UProperty> It(Struct); It; ++It)
  199.             {
  200.                 if (PropertyValue.Property->GetName() == StructProperty->GetName())
  201.                 {
  202.                     UProperty* FindProperty = Cast<UProperty>(StructProperty);
  203.                     if (ParseProperty(isActorComponent, true, FindProperty, StructProperty, StructPtr, PropertyValue, true)) { break; return; }
  204.                 }
  205.                 else
  206.                 {
  207.                     UProperty* FindProperty = Struct->FindPropertyByName(PropertyValue.Property->GetFName());
  208.                     if (FindProperty)
  209.                     {
  210.                         if (ParseProperty(isActorComponent, false, FindProperty, StructProperty, StructPtr, PropertyValue, true)) { break; return; }
  211.                     }
  212.                     else
  213.                     {
  214.                         UProperty* Property = *It;
  215.                         for (int32 ArrayIndex = 0; ArrayIndex < Property->ArrayDim; ArrayIndex++)
  216.                         {
  217.                             void* ValuePtr = Property->ContainerPtrToValuePtr<void>(StructPtr, ArrayIndex);
  218.    
  219.                             if (ParseProperty(isActorComponent, false, Property, StructProperty, ValuePtr, PropertyValue, false)) { break; return; }
  220.                         }
  221.                     }
  222.                 }
  223.             }
  224.         }
  225.    
  226.         bool ParseProperty(bool isActorComponent, bool isActorStruct, UProperty* Property, UStructProperty* StructProperty, void* ValuePtr, FsPropertyValues PropertyValue, bool isFinded)
  227.         {
  228.             if (isFinded || Property->GetName() == PropertyValue.Property->GetName())
  229.             {
  230.                 SetPropertyInObject(isActorComponent, isActorStruct, Property, PropertyValue, ValuePtr);
  231.                 return true;
  232.             }
  233.             else if (UArrayProperty* ArrayProperty = Cast<UArrayProperty>(Property)) { FScriptArrayHelper Helper(ArrayProperty, ValuePtr); for (int32 i = 0, n = Helper.Num(); i < n; ++i) { ParseProperty(isActorComponent, isActorStruct, ArrayProperty->Inner, StructProperty, Helper.GetRawPtr(i), PropertyValue, false); } }
  234.             else if (UStructProperty* xStructProperty = Cast<UStructProperty>(Property)) { IterateThroughStructProperty(isActorComponent, xStructProperty, ValuePtr, PropertyValue); }
  235.    
  236.             return false;
  237.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement