Sample of Chat(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
Open the project and you will see the above.
When executed, a screen will be drawn with only a text input field and a submit button at the bottom of the screen.
Try typing “test” and sending it.
Then the date and time of the submission and the message will be displayed.
Try again, this time typing “test2” and submitting.
The list will also reflect the posted message.
Project Description
Note the hierarchy of the scene.
Canvas/ChatWindow
Gs2ChatRoomContext.
Specifies the chat room to be handled by the node under this GameObject.
This sample specifies a room named room-0001 in the namespace chat-0001.
Canvas/ChatWindow/Messages/…/Content
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.
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
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
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.
It can be added from the context menu here.
Specify the content of the message to be posted in Category and Metadata to activate prefabrication.
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.