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:

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:

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:

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

Property List (Core)

Method List (Core)

Event List (Core)

Room Features

Property List (Room)

Method List (Room)

Event List (Room)

Group Features

Property List (Group)

Method List (Group)

Event List (Group)

Field Features

Property List (Field)

Method List (Field)

Event List (Field)

MatchMaker Features

Property List (MatchMaker)

Method List (MatchMaker)

Event List (MatchMaker)

最終更新