HowToUsePlugin.md

Table of Contents

Installation Instructions

1. Import Unity Package

Import the DiarkisUnityPlugin.unitypackage into your target project.

2. Configure Connection Information

Select Assets/Diarkis/Prefabs/DiarkisNetworkManager and display the DiarkisNetworkManager script in the Inspector.

Next, click on the item labeled Transport to display its contents, and configure the connection information to Diarkis as follows:

Setting ItemRoleExample Input

HttpHost

Value of EndPoint URL

asia-northeast1.diarkis.io/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

ClientKey

Value of Client Key

XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX (Can be empty)

3. Place the Prefab in the Scene

Place the configured DiarkisNetworkManager prefab into the scene.

Ensure that AutoStartConnect is checked (it is on by default), and click the play button at the top of the editor.

This will automatically initiate the connection to the Diarkis server.

How to Use the Plugin

Setting Up the DiarkisNetworkManager Prefab

DiarkisNetworkManager is a crucial class responsible for the connection to Diarkis and must be placed in the scene.

The main settings are as follows:

Setting ItemRole

Transport.HttpHost

Value of EndPoint URL

Transport.ClientKey

Value of Client Key

Transport.AutoRetryTimes

Number of retry attempts in case of connection failure

AutoStartConnect

Whether to automatically start connection to Diarkis server

IsWaitDisconnectOnAppQuit

Whether to wait for the disconnection process to complete when the app is closed

WaitDisconnectTime

Maximum time to wait for the above process. If exceeded, the app will forcibly close

Requesting Network Connection & Disconnection

To connect (or disconnect) to the Diarkis network, call the functions through DiarkisNetworkManager.

// Sample code for network connection & disconnection
public void Connect(string httpHost, string clientKey)
{
    DiarkisNetworkManager.Instance.Connect(httpHost, clientKey);
}

public void Disconnect()
{
    DiarkisNetworkManager.Instance.Disconnect();
}

Receiving Network Connection & Disconnection Responses

Responses from the server can be received as events.

First, add a component that triggers events to the scene.

Add an appropriate GameObject to the scene and attach the DiarkisCoreEventCallback component to it.

This component allows you to register functions, which will be triggered in response to event occurrences.

Create a class to register functions as follows:

using UnityEngine;

public class SampleScript : MonoBehaviour
{
    // Function to receive OnNetworkConnect event
    public void ReceiveOnNetworkConnectEvent(bool reconnected)
    {
        Debug.Log("Connected to the network.");
    }

    // Function to receive OnNetworkDisconnect event
    public void ReceiveOnNetworkDisconnectEvent(bool reconnecting)
    {
        Debug.Log("Disconnected from the network.");
    }
}

Attach this script to an appropriate GameObject, and register the functions you want to be called upon event occurrence to DiarkisCoreEventCallback.

In this way, you can receive responses from the server.

Utilizing Various Modules

Diarkis includes the following modules:

Module NameCorresponding Event Component

Room

Assets\Diarkis\Runtime\Extension\MonoBehaviour\Callbacks\Modules\DiarkisRoomEventCallback.cs

Group

Assets\Diarkis\Runtime\Extension\MonoBehaviour\Callbacks\Modules\DiarkisGroupEventCallback.cs

Field

Assets\Diarkis\Runtime\Extension\MonoBehaviour\Callbacks\Modules\DiarkisFieldEventCallback.cs

MatchMaker

Assets\Diarkis\Runtime\Extension\MonoBehaviour\Callbacks\Modules\DiarkisMatchMakerEventCallback.cs

P2P

Assets\Diarkis\Runtime\Extension\MonoBehaviour\Callbacks\Modules\DiarkisP2PEventCallback.cs

To send data, call the corresponding functions of each module.

To receive data, place the corresponding event components in the scene and register functions to them.

As an example, let's create a new room using the Room module.

Sending Requests from the Room Module

The following code uses the Room module to create a new room.

// Sample code to create a new room
public void CreateRoom(ushort maxMembers, bool allowEmpty, bool join, ushort ttl, uint interval)
{
    DiarkisNetworkManager.Instance.Modules.Room.Create(maxMembers, allowEmpty, join, ttl, interval);
}

Receiving Responses from the Room Module

First, attach the DiarkisRoomEventCallback to an appropriate GameObject placed in the scene.

Then, create a class to receive events as follows:

using UnityEngine;

public class SampleScript : MonoBehaviour
{
    // Function to receive OnRoomCreate event
    public void ReceiveOnRoomCreateEvent(bool success, string roomId, uint roomCreatedTime)
    {
        if (success)
        {
            Debug.Log($"The room creation was succeeded. roomID={roomId}");
        }
        else
        {
            Debug.Log("The room creation was failed.");
        }
    }
}

Finally, place this script in the scene and register the function to DiarkisRoomEventCallback's OnRoomCreate.

This allows you to receive the results when Room.Create is called.

While the Room module has been taken as an example here, the usage of other modules is similar.

Feature Reference

Core Features

Namespace

Diarkis

Class Name

DiarkisNetworkManger

Access Method

DiarkisNetworkManger.Instance

Interface Representing Events

IDiarkisCoreEvent

Event Component for Unity

DiarkisCoreEventCallback

Property List (Core)

PropertyRole

UID

UID that uniquely identifies this client

Modules

Various modules (Room, Group, Field...)

Method List (Core)

MethodRole

IsConnected

Whether the network is connected

Connect

Connect to the network

Disconnect

Disconnect from the network

Event List (Core)

EventRole

OnNetworkConnect

Connected to the network

OnNetworkDisconnect

Disconnected from the network

OnNetworkException

Exception occurred during communication

OnNetworkOffline

Preparing to shut down the server

OnApplicationWantsToQuit

Trying to close the application

Room Features

Namespace

Diarkis.Modules

Class Name

DiarkisRoom

Access Method

DiarkisNetworkManger.Instance.Modules.Room

Interface Representing Events

IDiarkisRoomEvent

Event Component for Unity

DiarkisRoomEventCallback

Property List (Room)

PropertyRole

IsJoined

Whether joined in Room

RoomID

Room ID

OwnerUID

UID of the room owner

MemberUIDs

UIDs of the members (including oneself & room owner)

Method List (Room)

MethodRole

Create

Create a room

Join

Join a room

JoinRandom

Join a room randomly

Leave

Leave a room

GetOwnerID

Get the ID of the room owner

GetMemberIDs

Get the IDs of the room members

Broadcast

Send data to the entire room

BroadcastTo

Send data to a specified room

MessageTo

Send data to a specified member

SyncObjects

Get the current state of objects

UpdateObject

Add, update, or delete an object

UpdateProperties

Update the properties of a room

GetProperties

Get the properties of a room

IncrProperty

Increment the value of a room property

GetNumberOfMembers

Get information about the number of members in the room

Register

Register a room

FindRoomByType

Search for a room

Reserve

Reserve a room

CancelReservation

Cancel room reservation

Migrate

Migrate a room

Move

Move a room

SendChatMessage

Send a chat message

GetChatLog

Get the chat log

StartP2PSync

Get the connection addresses of each client to switch to P2P connection

Event List (Room)

EventTypeCorresponding MethodRole

OnRoomCreate

Response

Create

-

OnRoomJoin

Response

Join

-

OnRoomLeave

Response

Leave

-

OnRoomMemberJoin

Push

-

A member joined

OnRoomMemberLeave

Push

-

A member left

OnRoomMemberBroadcast

Push

Broadcast, BroadcastTo

-

OnRoomMemberMessage

Push

MessageTo

-

OnRoomUpdateProperties

Response

UpdateProperties

-

OnRoomGetProperties

Response

GetProperties

-

OnRoomGetOwnerID

Response

GetOwnerID

-

OnRoomIncrProperty

Response

IncrProperty

-

OnRoomIncrPropertySync

Push

IncrProperty

-

OnRoomGetMemberIDs

Response

GetMemberIDs

-

OnRoomRegister

Response

Register

-

OnRoomFindRoomsByType

Response

FindRoomByType

-

OnRoomReserve

Response

Reserve

-

OnRoomCancelReservation

Response

CancelReservation

-

OnRoomGetNumberOfMembers

Response

GetNumberOfMembers

-

OnRoomChatSyncResponse

Response

SendChatMessage

-

OnRoomChatSync

Push

SendChatMessage

-

OnRoomChatLog

Response

GetChatLog

-

OnRoomStartP2PSync

Push

StartP2PSync

-

OnRoomObjectSync

Response

SyncObjects

-

OnRoomObjectUpdate

Push

UpdateObject

-

OnRoomOwnerChange

Push

-

Owner changed

Group Features

Namespace

Diarkis.Modules

Class Name

DiarkisGroup

Access Method

DiarkisNetworkManger.Instance.Modules.Group

Interface Representing Events

IDiarkisGroupEvent

Event Component for Unity

DiarkisGroupEventCallback

Property List (Group)

PropertyRole

GroupIDs

List of IDs of the groups joined

IsJoined

Whether joined in a group

Method List (Group)

MethodRole

Create

Create a group

Join

Join a group

JoinRandom

Join a group randomly

Leave

Leave a group

BroadcastTo

Send data to a group

Event List (Group)

EventTypeCorresponding MethodRole

OnGroupCreate

Response

Create

-

OnGroupJoin

Response

Join

-

OnGroupLeave

Response

Leave

-

OnGroupMemberJoin

Push

-

A member joined

OnGroupMemberLeave

Push

-

A member left

OnGroupMemberBroadcast

Push

BroadcastTo

-

Field Features

Namespace

Diarkis.Modules

Class Name

DiarkisField

Access Method

DiarkisNetworkManger.Instance.Modules.Field

Interface Representing Events

IDiarkisFieldEvent

Event Component for Unity

DiarkisFieldEventCallback

Property List (Field)

PropertyRole

-

-

Method List (Field)

MethodRole

SyncInit

Initialize synchronization

Sync

Send data to sync

Disappear

Leave the Field

Event List (Field)

EventTypeCorresponding MethodRole

OnFieldResponseSyncInit

Response

SyncInit

-

OnFieldSync

Push

Sync

-

OnFieldDisappear

Push

Disappear

Someone disappeared from view

MatchMaker Features

Namespace

Diarkis.Modules

Class Name

DiarkisMatchMaker

Access Method

DiarkisNetworkManger.Instance.Modules.MatchMaker

Interface Representing Events

IDiarkisMatchMakerEvent

Event Component for Unity

DiarkisMatchMakerEventCallback

Property List (MatchMaker)

PropertyRole

RoomID

ID of the matched room

Method List (MatchMaker)

MethodRole

IsTeamMatchmaking

Whether it is team matchmaking

HostMatchmaking

Host matchmaking

HostTeamMatchmaking

Host team matchmaking

ClearMatchmaking

Clear matchmaking

DisbandMatchmaking

Disband matchmaking

Kick

Kick a member

ClaimReservedMatchmaking

Claim a reserved room

JoinMatchmakingFromResult

Join a matchmaking from result

LeaveMatchmaking

Leave matchmaking

Sync

Send data

NotifyMatchmakingCompletion

Notify completion of matchmaking

P2PAddressSync

Get address information for P2P

SetMaxMatchMembers

Set the number of members for matchmaking

Search

Start matchmaking search

TeamSearch

Start team matchmaking search

Commit

Instruct to commit to team matchmaking

StartBackfill

-

Event List (MatchMaker)

EventTypeCorresponding MethodRole

OnMatchMakerKickResponse

Response

Kick

-

OnMatchMakerHostMatchmakingResponse

Response

HostMatchmaking

-

OnMatchMakerHostTeamMatchmakingResponse

Response

HostTeamMatchmaking

-

OnMatchMakerAbortMatchmakingResponse

Response

ClearMatchmaking

-

OnMatchMakerDisbandMatchmaking

Push

DisbandMatchmaking

-

OnMatchMakerMemberLeave

Push

-

A member left

OnMatchMakerMemberJoin

Push

-

A member joined

OnMatchMakerMemberSync

Push

Sync

-

OnMatchMakerJoinResponse

Response

ClaimReservedMatch

Last updated