Sample of Inventory(GS2 UIKit for Unity)
Implement the inventory functionality.
Repository
https://github.com/gs2io/gs2-uikit-for-unity-sample/tree/main/Inventory
GS2-Deploy template
Project Description
Open the project and you will see the above.
Once executed, you will see the inventory capacity usage in the upper right corner and the inventory operation buttons at the bottom.
Click on “Acquire Potion.”
You will then obtain 10 potions, and the potions will appear at the top of the screen. Likewise, next click on “Acquire Ether” to obtain ether.
![img_4.png].
The ether will be added next to the potion. Incidentally, the amount used in the upper right inventory is also reduced to 2/10.
Next, the maximum stack of potions is set to 99, so we click “Acquire Potion” 9 more times to have 100 potions.
As you can see, the potions are now separated into two stacks and the inventory usage is now 3/10.
Items can be consumed by clicking on the potion or ether icons. Let’s click on a stack of 99 potions.
Items can be consumed by explicitly specifying the stack, in which case there is no process of packing 98 stacked potions and 1 stacked potion.
Next, let’s click on the 1 stacked potion.
As you can see, the total number of stacks is now 2 and the inventory consumption is now 2/10.
Project Description
Note the hierarchy of the scene.
Canvas/InventoryWindow
Gs2InventoryOwnInventoryContext
Specifies the inventory (standard) of GS2-Inventory to be handled by the node under this GameObject.
This time, we specify an inventory named Bag in the namespace inventory-0001 of GS2-Inventory.
Canvas/InventoryWindow/Capacity
Gs2InventoryInventoryEnabler
InventoryCapacityText GameObject is enabled when the inventory specified in Gs2InventoryOwnInventoryContext is finished loading.
Canvas/InventoryWindow/Capacity/InventoryCapacityText
Gs2InventoryInventoryLabel.
Current Inventory Usage/ Current Inventory Maximum Capacity is specified in Format. The formatted text is called back to OnUpdate(String), from which the value is reflected in the Text component.
Canvas/InventoryWindow/Inventory/…/Content
Gs2InventoryOwnItemSetListFetcher
Gets the list of items in the namespace specified by Gs2InventoryOwnInventoryContext.
Gs2InventoryOwnItemSetList
Generates the items obtained by Gs2InventoryOwnItemSetListFetcher by assigning them to the specified prefab. Maximum Items specifies the maximum number of prefabs to be generated.
In this case, Item in the child node is specified as a prefab. If a GameObject specified as a prefab exists in the scene, the GameObject will be disabled and the number of GameObjects specified in Maximum Items will be created in addition to the GameObjects specified as prefabs.
Canvas/InventoryWindow/Inventory/…/Content/Item
Gs2InventoryOwnItemSetContext
Specifies the item to be handled by the node under this GameObject. The content of the context is assigned by Gs2InventoryOwnItemSetList.
Gs2InventoryOwnItemModelFetcher
Gets the item model specified by Gs2InventoryOwnItemSetContext.
Gs2InventoryOwnItemSetFetcher
Gets the item specified by Gs2InventoryOwnItemSetContext.
Canvas/InventoryWindow/Inventory/…/Content/Item/Icon
Gs2InventoryItemModelNameEnabler
Switches the GameObject to be enabled by the name of the assigned item model. For Potion, PotionImage is enabled; for Ether, EnterImage is enabled. As a result, the item icon changes depending on the type of item to be listed.
Canvas/InventoryWindow/Inventory/…/Content/Item/Name
Gs2InventoryItemModelLabel
Formats the contents of the assigned item model in the format specified by Format. The formatted text is called back to OnUpdate(String), from which the value is reflected in the Text component.
Canvas/InventoryWindow/Inventory/…/Content/Item/Count
Gs2InventoryItemSetLabel.
Formats the contents of the assigned itemset in the format specified by Format. The formatted text is called back to OnUpdate(String), from which the value is reflected in the Text component.
Canvas/InventoryWindow/Inventory/…/Content/Item/Use/Gs2InventoryItemSetConsumeAction
You can add a prefab from this context menu.
Gs2InventoryItemSetConsumeAction.
Consume Count allows you to specify the quantity to consume.
By activating the prefab, the item specified in Gs2InventoryOwnItemSetContext will be consumed.
Canvas/InventoryWindow/Input/Acquire Potion
Gs2ExchangeRateModelContext
Set the GS2-Exchange exchange rate at which GS2-Inventory Potion is obtained.
Here we specify an exchange rate named Potion in the GS2-Exchange namespace named exchange-0001.
Canvas/InventoryWindow/Input/Acquire Potion/Gs2ExchangeExchangeAction
Gs2ExchangeExchangeExchangeAction.
Count allows you to specify the quantity to be exchanged.
By enabling prefabrication, the exchange specified in Gs2ExchangeRateModelContext will be executed.
Canvas/InventoryWindow/Input/Acquire Ether
Gs2ExchangeRateModelContext
Set the exchange rate for GS2-Exchange to obtain Ether for GS2-Inventory.
Here we specify an exchange rate named Potion in the GS2-Exchange namespace named exchange-0001.
Canvas/InventoryWindow/Input/Acquire Ether/Gs2ExchangeExchangeAction
Gs2ExchangeExchangeExchangeAction.
Count allows you to specify the quantity to be exchanged.
By enabling prefabrication, the exchange specified in Gs2ExchangeRateModelContext will be executed.
Process/Gs2AutoLogin
A prefab is set up to perform the login process.
sample of Account, please refer to the explanation there.