Sample of Inventory(GS2 UIKit for Unity)

sample implementation of GS2-Inventory functionality using GS2 UIKit for Unity

Implement the inventory functionality.

Repository

https://github.com/gs2io/gs2-uikit-for-unity-sample/tree/main/Inventory

GS2-Deploy template

https://github.com/gs2io/gs2-uikit-for-unity-sample/blob/main/Inventory/initialize_inventory_template.yaml

Project Description

img.png

Open the project and you will see the above.

img_1.png

Once executed, you will see the inventory capacity usage in the upper right corner and the inventory operation buttons at the bottom.

img_2.png

Click on “Acquire Potion.”

img_3.png

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.

img_5.png

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.

img_6.png

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.

img_7.png

As you can see, the total number of stacks is now 2 and the inventory consumption is now 2/10.

Project Description

img_8.png

Note the hierarchy of the scene.

Canvas/InventoryWindow

img_9.png

Gs2InventoryOwnInventoryContext

Specifies the inventory (standard) of GS2-Inventory to be handled by the node under this GameObject.

img_11.png img_10.png

This time, we specify an inventory named Bag in the namespace inventory-0001 of GS2-Inventory.

Canvas/InventoryWindow/Capacity

img_12.png

Gs2InventoryInventoryEnabler

InventoryCapacityText GameObject is enabled when the inventory specified in Gs2InventoryOwnInventoryContext is finished loading.

Canvas/InventoryWindow/Capacity/InventoryCapacityText

img_13.png

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

img_15.png

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.

img_14.png

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

img_16.png

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

img_18.png

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

img_19.png

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

img_20.png

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

img_21.png

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

img_22.png

Gs2ExchangeRateModelContext

Set the GS2-Exchange exchange rate at which GS2-Inventory Potion is obtained.

img_24.png img_23.png

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

img_25.png

Set the exchange rate for GS2-Exchange to obtain Ether for GS2-Inventory.

img_27.png img_26.png

Here we specify an exchange rate named Potion in the GS2-Exchange namespace named exchange-0001.

Canvas/InventoryWindow/Input/Acquire Ether/Gs2ExchangeExchangeAction

img_28.png

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.