Guest User

ue4 FFastArraySerializer and FFastArraySerializerItem

a guest
Sep 11th, 2022
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. USTRUCT(BlueprintType)
  2. struct INVENTORYSYSTEM_API FInventoryItem : public FFastArraySerializerItem
  3. {
  4.  
  5. GENERATED_USTRUCT_BODY()
  6.  
  7. public:
  8.  
  9. UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "FInventoryItem")
  10. int32 Amount;
  11.  
  12. UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "FInventoryItem")
  13. int32 MaxAmount;
  14.  
  15. UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "FInventoryItem")
  16. bool bCanStack = false;
  17.  
  18. UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "FInventoryItem")
  19. UInventoryItemAsset* ItemAsset = nullptr;
  20.  
  21. // Item property key value pairs for dynamic properties
  22. UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Inventory System", DisplayName = "Dynamic Item Properties")
  23. FItemPropertyArray ItemProperties;
  24.  
  25. void PreReplicatedRemove(const struct FInventoryArray& InArraySerializer);
  26. void PostReplicatedAdd(const struct FInventoryArray& InArraySerializer);
  27. void PostReplicatedChange(const struct FInventoryArray& InArraySerializer);
  28.  
  29. FInventoryItem();
  30.  
  31. FInventoryItem(int32 NewAmount, int32 NewMaxAmount, bool bNewCanStack, UInventoryItemAsset* NewItemAsset);
  32.  
  33. friend bool operator== (const FInventoryItem& First, const FInventoryItem& Other)
  34. {
  35. return (First.ItemAsset == Other.ItemAsset && First.ItemProperties.Properties == Other.ItemProperties.Properties);
  36. }
  37.  
  38. friend bool operator!= (const FInventoryItem& First, const FInventoryItem& Other)
  39. {
  40. return (First.ItemAsset != Other.ItemAsset || First.ItemProperties.Properties != Other.ItemProperties.Properties);
  41. }
  42.  
  43. friend bool operator>= (const FInventoryItem& First, const FInventoryItem& Other)
  44. {
  45. return (First.Amount >= Other.Amount);
  46. }
  47.  
  48. friend bool operator<= (const FInventoryItem& First, const FInventoryItem& Other)
  49. {
  50. return (First.Amount <= Other.Amount);
  51. }
  52.  
  53. friend bool operator> (const FInventoryItem& First, const FInventoryItem& Other)
  54. {
  55. return (First.Amount > Other.Amount);
  56. }
  57.  
  58. friend bool operator< (const FInventoryItem& First, const FInventoryItem& Other)
  59. {
  60. return (First.Amount < Other.Amount);
  61. }
  62. };
  63.  
  64.  
  65. USTRUCT(BlueprintType)
  66. struct FInventoryArray : public FFastArraySerializer
  67. {
  68. GENERATED_USTRUCT_BODY()
  69.  
  70. UPROPERTY(BlueprintReadWrite, EditAnywhere)
  71. TArray< FInventoryItem > Items;
  72.  
  73. bool NetDeltaSerialize(FNetDeltaSerializeInfo & DeltaParms);
  74.  
  75. FInventoryArrayChangedDelegate InventoryArrayChangedDelegate;
  76. };
  77.  
  78. template<>
  79. struct TStructOpsTypeTraits< FInventoryArray > : public TStructOpsTypeTraitsBase2< FInventoryArray >
  80. {
  81. enum
  82. {
  83. WithNetDeltaSerializer = true,
  84. };
  85. };
Add Comment
Please, Sign In to add comment