Синтаксис:
Используется csharp
GameObject mes = PhotonNetwork.Instantiate("Messanger", Vector3.zero, Quaternion.identity, 0);
myPhotonView = mes.GetComponent<PhotonView>();
DontDestroyOnLoad(mes);
myPhotonView = mes.GetComponent<PhotonView>();
DontDestroyOnLoad(mes);
Изначально он имеет, к примеру, ID = 1001. При подключении второго клиент его ID меняется на 2001, при чем подключенный клиент как раз и управляет этим ID (галочка Controlled locally стоит в инспекторе). А при подключении 3 клиента у двух предыдущих ID вновь меняется, при чем на одинаковый - 3001. И у последнего подключенного клиента не активна Controlled locally.
Из-за всех этих смен ID и не контролируемой смене владельцев PhotonView, я не могу пересылать сообщения между клиентами. В чем проблема, и как правильно настроить подключение новых клиентов? (просматривал туториал MarcoPolo, но почему-то там ID у клиентов не меняются).
Вот код создания\подключения к облаку:
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class main_menu : Photon.MonoBehaviour {
public GUIStyle style1;
public GUIStyle style2;
private PhotonView myPhotonView;
private string Login = "log";
private string Password = "pas";
void Start () {
PhotonNetwork.ConnectUsingSettings("0.1");
}
// Update is called once per frame
void Update () {
}
void OnJoinedRoom()
{
GameObject mes = PhotonNetwork.Instantiate("Messanger", Vector3.zero, Quaternion.identity, 0);
myPhotonView =mes.GetComponent<PhotonView>();
DontDestroyOnLoad(monster);
}
void OnGUI()
{
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
Login = GUI.TextField (new Rect ((Screen.width)/2-75,(Screen.height)/2-100, 150, 30), Login);
Password = GUI.TextField (new Rect ((Screen.width)/2-75,(Screen.height)/2-60, 150, 30), Password);
string ToServer = Login+" "+Password;
if (GUI.Button (new Rect ((Screen.width)/2-75,(Screen.height)/2-20, 150, 36), " Войти в игру", style1)) {
myPhotonView.RPC("Login", PhotonTargets.All,ToServer);
}
if (GUI.Button (new Rect ((Screen.width)-155,(Screen.height)-41, 150, 36), " Выход" ,style1)) {
Application.Quit();
}
}
void OnJoinedLobby()
{
Debug.Log("JoinRandom");
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed()
{
PhotonNetwork.CreateRoom(null);
}
}
using System.Collections;
public class main_menu : Photon.MonoBehaviour {
public GUIStyle style1;
public GUIStyle style2;
private PhotonView myPhotonView;
private string Login = "log";
private string Password = "pas";
void Start () {
PhotonNetwork.ConnectUsingSettings("0.1");
}
// Update is called once per frame
void Update () {
}
void OnJoinedRoom()
{
GameObject mes = PhotonNetwork.Instantiate("Messanger", Vector3.zero, Quaternion.identity, 0);
myPhotonView =mes.GetComponent<PhotonView>();
DontDestroyOnLoad(monster);
}
void OnGUI()
{
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
Login = GUI.TextField (new Rect ((Screen.width)/2-75,(Screen.height)/2-100, 150, 30), Login);
Password = GUI.TextField (new Rect ((Screen.width)/2-75,(Screen.height)/2-60, 150, 30), Password);
string ToServer = Login+" "+Password;
if (GUI.Button (new Rect ((Screen.width)/2-75,(Screen.height)/2-20, 150, 36), " Войти в игру", style1)) {
myPhotonView.RPC("Login", PhotonTargets.All,ToServer);
}
if (GUI.Button (new Rect ((Screen.width)-155,(Screen.height)-41, 150, 36), " Выход" ,style1)) {
Application.Quit();
}
}
void OnJoinedLobby()
{
Debug.Log("JoinRandom");
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed()
{
PhotonNetwork.CreateRoom(null);
}
}
На Messanger'e висит скрипт ReceiveMessage:
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class ReceiveMessage : Photon.MonoBehaviour {
private static PhotonView ScenePhotonView;
private bool loged=false;
public string Nick;
public string[] usrs;
// Use this for initialization
void Start () {
ScenePhotonView = this.GetComponent<PhotonView>();
}
// Update is called once per frame
void Update () {
}
//далее идут различные RPC ф-ции
using System.Collections;
public class ReceiveMessage : Photon.MonoBehaviour {
private static PhotonView ScenePhotonView;
private bool loged=false;
public string Nick;
public string[] usrs;
// Use this for initialization
void Start () {
ScenePhotonView = this.GetComponent<PhotonView>();
}
// Update is called once per frame
void Update () {
}
//далее идут различные RPC ф-ции