IMR Course_9
https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/intro
=> Tackle what is the most relevant to your app
Server
Connect to Photon Server in a certain Region
<20 CCU free
Join Lobby
Open, List and Join rooms
-Random Matchmaking
Join Room
It's time to take the product live - the end if the build phase but the beginning of being in market.
# CHAPTER 2
public class NetworkManager : MonoBehaviourPunCallbacks
{
private string gameVersion = "0.1";
public void JoinServer()
{
PhotonNetwork.AutomaticallySyncScene = true;
PhotonNetwork.NickName = GeneralSettings.myNickname;
PhotonNetwork.GameVersion = gameVersion;
PhotonNetwork.ConnectUsingSettings();
Debug.Log("Connecting...");
}
public override void OnConnectedToMaster()
{
base.OnConnectedToMaster();
Debug.Log("Connected to master!");
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
base.OnJoinedLobby();
}
public override void OnDisconnected(DisconnectCause cause)
{
OnConnectionFailed?.Invoke(cause.ToString());
Debug.LogWarningFormat("Disconnected with reason {0}", cause);
}
public void JoinRoom()
{
PhotonNetwork.JoinRoom(GeneralSettings.roomCode);
}
public override void OnJoinedRoom()
{
Debug.Log("Joined room!");
//Change to game scene
PhotonNetwork.LoadScene("MainScene");
}
public override void OnJoinRoomFailed(short returnCode, string message)
{
Debug.LogWarning("Room join failed " + message);
Debug.Log("Creating room...");
PhotonNetwork.CreateRoom(GeneralSettings.roomCode, new RoomOptions { MaxPlayers = 33, IsOpen = true, IsVisible = true }, TypedLobby.Default);
}
}
# PRESENTING CODE
# PRESENTING CODE
1. Make a prefab with PhotonView component on GameObject
2. Store prefab inside Resources/
3. PhotonNetwork.Instantiate("path-in-resources"); - who does that is the OWNER
** photonView.IsMine
# PRESENTING CODE
- Communication between PhotonViews
RpcTarget.All / RpcTarget.Others / by User Id
private void OnWeaponOutChanged(int val)
{
photonView.RPC("NetworkedChangeWeaponState", RpcTarget.All, val);
}
[PunRPC]
private void NetworkedChangeWeaponState(int val)
{
....
}# PRESENTING CODE
- photon view custom Stream Buffers
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(x);
stream.SendNext(y);
stream.SendNext(z);
}
else
{
x = (int)stream.ReceiveNext();
y = (int)stream.ReceiveNext();
z = (int)stream.ReceiveNext();
}
}# PRESENTING CODE
Room Props, Player Props
public void SetPlayerTeam(string teamString)
{
if (!playerProperties.ContainsKey("team"))
{
playerProperties.Add("team", teamString);
}
playerProperties["team"] = teamString;
PhotonNetwork.LocalPlayer.SetCustomProperties(playerProperties);
}# PRESENTING CODE