Time spent: approximately 2 hours
I downloaded the free PUN asset.
Migrating from UNET, I duplicated my UNET scene to be on the safe side. Then I created a Multiplayer object with PUN and UNET network controllers. Looks like this:
- Multiplayer
- PUN
- UNET
I'm curious to see whether I can create a hybrid setup, so that I can 'easily' switch between solutions.
The quick start doc proved to be out of date but error messages are clear and the APIs look well structured so I quickly got a connection up and running.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class PUNNetworkController : MonoBehaviour { | |
void Start(){ PhotonNetwork.ConnectUsingSettings("v4.2"); } | |
void OnJoinLobby(){ StartGame (); } | |
void OnConnectedToMaster(){ StartGame (); } | |
void StartGame(){ PhotonNetwork.JoinRandomRoom(); } | |
void OnPhotonRandomJoinFailed(){ PhotonNetwork.CreateRoom("MyMatch"); } | |
void OnPhotonCreateGameFailed(){ Debug.LogError ("Create game failed"); } | |
void OnJoinedRoom(){ Debug.Log ("Room joined; ready to start the game"); } | |
} |
Note - Photon also provide a Unity client SDK for their 'Realtime' service. Don't confuse these two, notably when browsing APIs and docs.
The next step obviously is to setup a player object. Like in UNET and other similar APIs this is done via network instantiation. Here the quick start let me down a bit so I used the Paladin Studios tutorial instead.
It's kind of funny to see how my network controller is looking more and more like UNET's NetworkManager.
Easy state Sync
I wanted to replicate my initial setup with UNET so I went to shop for the TransformView. With a PhotonView and a (configured) TransformView on my Avatar, I hope to get position and rotation in sync.
No comments:
Post a Comment