HowToUsePlugin.md

Table of Contents

Installation Instructions

1. Import Unity Package

Import the DiarkisUnityPlugin.unitypackage into the target project.

2. Configure Connection Information

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

Then, click on the item labeled Transport to show its contents and configure the connection information with Diarkis as follows:

3. Place the Prefab in the Scene

Place the configured DiarkisNetworkManager prefab into the scene.

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

This will automatically start the connection to the Diarkis server.

How to Use the Plugin

How to Configure DiarkisNetworkManager Prefab

DiarkisNetworkManager is a crucial class for connecting with Diarkis and must be placed in the scene.

Important configuration items include:

Request to Connect & Disconnect from the Network

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

// Sample code for connecting & disconnecting to the network
public void Connect(string httpHost, string clientKey)
{
    DiarkisNetworkManager.Instance.Connect(httpHost, clientKey);
}

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

Receive Responses for Network Connect & Disconnect

You can receive responses from the server as events.

First, add a component to the scene to trigger events.

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

You can register functions with this component, which will trigger in response to events.

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 desired function to be called during an event in DiarkisCoreEventCallback.

Thus, you can receive responses from the server.

Use Various Modules

Diarkis contains the following modules:

To send data, call the corresponding functions of various modules.

To receive data, place a corresponding event component in the scene and register functions with it.

Here is an example of how to create a new room using the Room module.

Send Requests via Room Module

The following code creates a new room using the Room module.

// 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);
}

Receive Responses from Room Module

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

Next, 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 in OnRoomCreate of DiarkisRoomEventCallback.

This way, you can receive the result when calling Room.Create.

Here, the Room module was taken as an example, but the usage is similar for other modules.

Reference for Each Feature

Core Features

List of Properties (Core)

List of Methods (Core)

List of Events (Core)

List of Properties (Room)

List of Methods (Room)

List of Events (Room)

List of Properties (Group)

List of Methods (Group)

List of Events (Group)

List of Properties (Field)

List of Methods (Field)

List of Events (Field)

List of Properties (MatchMaker)

List of Methods (MatchMaker)

List of Events (MatchMaker)

List of Properties (P2P)

List of Methods (P2P)

List of Events (P2P)

Last updated