Unity

Installation

The Unity SDK can be installed by opening the Unity Package Manager (Window->Package Manager) and clicking the + on the top left and selecting 'Add package from git URL...'

You then enter the GitHub URL of the PP Unity SDK repository, which is: https://github.com/Planetary-Processing/unity-sdk.git

And click 'Add' to add the package.

Components

The Unity SDK provides two new components which can be added to GameObjects. These are PPMaster and PPEntity. These can be accessed in the 'Add Component' menu of any Gameobject under the PP heading.

PPMaster represents the main connection point to PP's servers and performs the heavy lifting and orchestration of the SDK. You must have a GameObject in your game which has the master component.

PPEntity represents a server-side entity in the game world. You are required to, for every type of entity you wish to display in the Unity client, create a Prefab containing the PPEntity component.

By default, entities' GameObjects will be moved to their server-side position, you can disable this per entity type by un-ticking 'Use Server Position' in the entity component's inspector window. Here you also need to set the entity's type, which must match the server-side type that this Prefab represents.

Please note that the player type is only for players other than the one connecting with this client. You need to create a separate GameObject (not in a prefab) for the local player which also contains a PPEntity component.

You need to add the entity Prefabs to the Prefabs field in the PPMaster inspector window. Here you will also need to set a reference to the local player GameObject and also, the Planetary Processing game ID.

API

Below is a reference of the API available within Unity's C# environment.

Components

The PPEntity and PPMaster components expose various public methods which can be accessed within MonoBehaviour scripts by getting a reference to the component like so:

PPMaster master = GetComponent<PPMaster>();
PPEntity entity = GetComponent<PPEntity>();

PPMaster

PPMaster exposes the following methods:

MethodParametersReturn TypeDescription

Init(username, password)

username: string password: string

None

Connect to and authenticate with the Planetary Processing servers.

Join()

None

None

Spawn the player into the world.

Message(msg)

msg: Dictionary<string, dynamic>

None

Send a message to the player entity on the server, to be handled by the message function on the server side API.

GetEntity(uuid)

uuid: string

Entity

Get Entity details by UUID.

GetEntities()

None

List<Entity>

Get a list of all Entities that this client can see.

PPEntity

PPEntity exposes the following methods:

MethodParametersReturn TypeDescription

GetServerPosition()

None

Vector3

Get the server-side position of this entity. Particularly useful if you are not using the 'Use Server Position' feature. NOTE: Planetary Processing uses 'y' for depth in 3 dimensional games, and 'z' for height, the Unity SDK automatically swaps these.

GetServerData()

None

Dictionary<string, dynamic>

Get the server-side data of this entity.

GetUUID()

None

string

Get this entity's UUID.

Types

Entity

FieldTypeDescription

id

string

UUID of the entity.

x

double

X coordinate in world units.

y

double

Y coordinate in world units.

data

Dictionary<string, dynamic>

Data of the entity (.Data field on the server side API).

type

string

Type of the entity.

Last updated