Sample of Chat(GS2 UIKit for Unity)

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

Implement text chat functionality.

Repository

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

GS2-Deploy template

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

Project Description

img.png

Open the project and you will see the above.

img_12.png

When executed, a screen will be drawn with only a text input field and a submit button at the bottom of the screen.

img_13.png

Try typing “test” and sending it.

img_14.png

Then the date and time of the submission and the message will be displayed.

img_15.png

Try again, this time typing “test2” and submitting.

img_16.png

The list will also reflect the posted message.

Project Description

img_1.png

Note the hierarchy of the scene.

Canvas/ChatWindow

img_2.png

Gs2ChatRoomContext.

Specifies the chat room to be handled by the node under this GameObject.

img_4.png img_3.png

This sample specifies a room named room-0001 in the namespace chat-0001.

Canvas/ChatWindow/Messages/…/Content

img_5.png

Gs2ChatMessageListFetcher.

Get a list of messages in the room specified by RoomContext.

Gs2ChatMessageList.

Generates a list of messages obtained by Gs2ChatMessageListFetcher by assigning them to the specified prefab. Maximum Items specifies the maximum number of prefabs to be generated.

img_6.png

This time, Message 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/ChatWindow/Messages/…/Content/Message

img_7.png

Gs2ChatMessageContext.

Specifies the message to be handled by the node under this GameObject. The content of the context is assigned by Gs2ChatMessageList.

Gs2ChatMessageFetcher.

Gets the message specified by MessageContext.

Canvas/ChatWindow/Messages/…/Content/Message/Text

img_8.png

Gs2ChatMessageLabel.

Outputs the message content retrieved by Gs2ChatMessageFetcher. This time, the format is specified to be formatted as “{message posting time}:{message posting minute} {message payload}”. The formatted value is specified in Format.

The formatted value is called back by OnUpdate(String), and the value is reflected in the Text component.

Canvas/ChatWindow/Input/Send/Gs2ChatMessagePostAction

Gs2ChatMessagePostAction.

Prefab that executes the process of posting a message.

img_10.png

It can be added from the context menu here.

img_9.png

Specify the content of the message to be posted in Category and Metadata to activate prefabrication.

img_11.png

The prefab is therefore disabled by default and activated when the Send Message button is clicked.

OnPostComplete(EzMessage)

can be used to specify the callback when the message has been successfully sent. Here, the process is set to invalidate itself and initialize the text input field of the chat message.

Process/Gs2AutoLogin

The prefab that executes the login process is set here.

Sample of Account, please refer to the explanation there.

Let’s Challenge

How do I disable the “Send Message button” until the login process is complete? The way to branch by whether the login process is completed is sample of Account. Please think about how it could be done.