HowToReplicatePosition.md

This document explains how to synchronize the position of a GameObject using the Diarkis plugin.

Contents

1. Project Setup

First, create a new Unity project.

Next, import the DiarkisUnityPlugin.unitypackage (for details, please refer to HowToUsePlugin.md).

Finally, set the connection information for Diarkis in the DiarkisNetworkManager prefab and place it in the scene.

The setup is now complete.

2. Adding Assets

Here, we will explain the steps for synchronizing a character using Unity's standard assets. For example, this description assumes the use of "Third Person Character Controller" from the Unity Asset Store. Please replace it with the asset you are using as appropriate.

Download and Import Third Person Character Controller from the Package Manager.

Click the Import button in Import Unity Package to import.

Create a Sample folder under Assets > Diarkis for sample work and create the following three folders.

Use the background data that comes with the Third Person Character Controller. Copy the file from Assets > StarterAssets > ThirdPersonController > Scenes > Playground to Assets > Diarkis > Sample > Scenes, and rename it to DiarkisSampleScene.

2. Automatic Room Creation

To synchronize positions, you need to be in some sort of room (Room).

To simplify the explanation, we will use Room.JoinRandom to automatically create a room when the scene is played.

We have prepared sample code in the HowToReplicatePostion_SampleCode folder for this document's explanation. You can overwrite copy the included Scripts folder to Assets > Diarkis > Sample > Scripts for use.

  1. Right-click to open the context menu, create an empty GameObject with Create Empty, and rename it to SceneManager.

  2. Drag and drop Diarkis > Sample > Scripts > Game > DiarkisSampleGameManager.cs to attach it.

  1. Similarly, create an object called CoreEvent.

  2. Drag and drop Diarkis > Runtime > Extension > MonoBehaviour > Callbacks > DiarkisCoreEventCallback.cs to attach it.

  3. Specify SceneManager's DiarkisSampleGameManager.OnNetworkConnect in On Network Connect.

  1. Similarly, create an object called RoomEvent.

  2. Drag and drop Diarkis > Runtime > Extension > MonoBehaviour > Replication > Room > DiarkisRoomRepManager.cs to attach it.

  3. Specify the various callbacks (OnRoomCreate, OnRoomJoin, OnRoomLeave, OnRoomMemberJoin, OnRoomMemberLeave).

  1. Select SceneManager.

  2. Attach RoomEvent to Room Rep Manager.

DiarkisRoomRepManager is a class that inherits from DiarkisRoomEventCallback. It not only handles Room events as-is but also adds various convenient functions for replication.

3. Creating Character Prefabs

Next, create the character that the player will control.

  1. Copy PlayerArmature from Assets > StarterAssets > ThirdPersonController > Prefabs to Assets > Diarkis > Sample > Prefabs, and rename it to DiarkisPlayerArmature.

For characters you want to synchronize positions with, you need to have them inherit from DiarkisGameObject and correctly implement the following three functions.

4. Spawn Settings

  1. Specify where the character will be generated. Create PlayerSpawnPoint and specify the Position where the character will spawn.

  1. Attach DiarkisPlayerArmature to RoomEvent's PlayerPrefab.

  2. Attach PlayerSpawnPoint to RoomEvent's AutoSpawnTransform.

  1. Remove PlayerArmature from DiarkisSampleScene.

  1. By playing it, the position of remote characters from other clients will be synchronized.

Last updated