Ошибок не происходит но и подключения тоже нету. Сервер Photon настроен правильно в его логах мой сервер(TestServer) запущен.
Код Сервера:
Синтаксис:
Используется csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestServer
{
using Photon.SocketServer;
using Photon.SocketServer.Rpc;
using PhotonHostRuntimeInterfaces;
public class MyPeer : Peer, IOperationHandler
{
public MyPeer(InitRequest initRequest)
: base(initRequest.Protocol, initRequest.PhotonPeer)
{
this.SetCurrentOperationHandler(this);
}
void IOperationHandler.OnDisconnect(PeerBase peer)
{
this.Disconnect();
this.Dispose();
}
void IOperationHandler.OnDisconnectByOtherPeer(PeerBase peer)
{
}
OperationResponse IOperationHandler.OnOperationRequest(PeerBase peer, OperationRequest operationRequest, SendParameters sendParameters)
{
return new OperationResponse(0, operationRequest);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestServer
{
using Photon.SocketServer;
using Photon.SocketServer.Rpc;
using PhotonHostRuntimeInterfaces;
public class MyPeer : Peer, IOperationHandler
{
public MyPeer(InitRequest initRequest)
: base(initRequest.Protocol, initRequest.PhotonPeer)
{
this.SetCurrentOperationHandler(this);
}
void IOperationHandler.OnDisconnect(PeerBase peer)
{
this.Disconnect();
this.Dispose();
}
void IOperationHandler.OnDisconnectByOtherPeer(PeerBase peer)
{
}
OperationResponse IOperationHandler.OnOperationRequest(PeerBase peer, OperationRequest operationRequest, SendParameters sendParameters)
{
return new OperationResponse(0, operationRequest);
}
}
}
Синтаксис:
Используется csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestServer
{
using Photon.SocketServer;
public class MyServer : ApplicationBase //Реализует иентерфейс самого сервера
{
protected override PeerBase CreatePeer(InitRequest initRequest) //создание подключений
{
return new MyPeer(initRequest); //Инициализация создания подключения
}
protected override void Setup()
{
}
protected override void TearDown()
{
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestServer
{
using Photon.SocketServer;
public class MyServer : ApplicationBase //Реализует иентерфейс самого сервера
{
protected override PeerBase CreatePeer(InitRequest initRequest) //создание подключений
{
return new MyPeer(initRequest); //Инициализация создания подключения
}
protected override void Setup()
{
}
protected override void TearDown()
{
}
}
}
Код на Unity
Синтаксис:
Используется csharp
using System.Collections;
using System;
using UnityEngine;
using ExitGames.Client.Photon;
public class Login : MonoBehaviour
{
Game engine;// = new Game();
// Use this for initialization
void Start()
{
Application.runInBackground = true;
engine = new Game();
}
// Update is called once per frame
void Update()
{
try
{
this.engine.Update();
}
catch (Exception e)
{
Debug.Log(e);
}
}
///
/// The on application quit.
///
public void OnApplicationQuit()
{
try
{
this.engine.Disconnect();
}
catch (Exception e)
{
Debug.Log(e);
}
}
public void OnGUI()
{
if (GUI.Button(new Rect(100, 60, 100, 30), "Connect"))
{
PhotonPeer peer = new PhotonPeer(this.engine, false);
try
{
engine.Initialize(peer, "10.40.142.2:5055", "TestServer");
}
catch (Exception e)
{
Debug.Log(e);
}
}
Debug.Log(engine.status);
GUI.Label(new Rect(100, 100, 300, 300), engine.status);
}
}
using System;
using UnityEngine;
using ExitGames.Client.Photon;
public class Login : MonoBehaviour
{
Game engine;// = new Game();
// Use this for initialization
void Start()
{
Application.runInBackground = true;
engine = new Game();
}
// Update is called once per frame
void Update()
{
try
{
this.engine.Update();
}
catch (Exception e)
{
Debug.Log(e);
}
}
///
/// The on application quit.
///
public void OnApplicationQuit()
{
try
{
this.engine.Disconnect();
}
catch (Exception e)
{
Debug.Log(e);
}
}
public void OnGUI()
{
if (GUI.Button(new Rect(100, 60, 100, 30), "Connect"))
{
PhotonPeer peer = new PhotonPeer(this.engine, false);
try
{
engine.Initialize(peer, "10.40.142.2:5055", "TestServer");
}
catch (Exception e)
{
Debug.Log(e);
}
}
Debug.Log(engine.status);
GUI.Label(new Rect(100, 100, 300, 300), engine.status);
}
}
Синтаксис:
Используется csharp
using UnityEngine;
//using System.Collections;
using System;
using ExitGames.Client.Photon;
public class Game : IPhotonPeerListener
{
PhotonPeer peer;
public string status = "disconnected";
public void Initialize(PhotonPeer peer, string serverAddress, string applicationName)
{
this.peer = peer;
Debug.Log("StatusConnect: "+peer.Connect(serverAddress, applicationName).ToString());
Debug.Log("StatusConnect: " + peer.PeerState.ToString());
}
public void Disconnect()
{
if (status != "disconnected")
{
peer.Disconnect();
}
}
public void Update()
{
if (status != "disconnected")
{
peer.Service();
}
}
public void OnStatusChanged(StatusCode statusCode)
{
Debug.Log("OnStatusChanged");
switch (statusCode)
{
case StatusCode.Connect:
{
status = "connected";
break;
}
case StatusCode.Disconnect:
case StatusCode.DisconnectByServer:
case StatusCode.DisconnectByServerLogic:
case StatusCode.DisconnectByServerUserLimit:
case StatusCode.TimeoutDisconnect:
{
status = "Disconinected";
break;
}
default:
{
status = "unexpected";
break;
}
}
}
public void DebugReturn(DebugLevel level, string message)
{
Debug.Log(message);
}
public void OnEvent(EventData eventData)
{
Debug.Log("Event");
throw new NotImplementedException();
}
public void OnOperationResponse(OperationResponse operationResponse)
{
Debug.Log("Response");
throw new NotImplementedException();
}
}
//using System.Collections;
using System;
using ExitGames.Client.Photon;
public class Game : IPhotonPeerListener
{
PhotonPeer peer;
public string status = "disconnected";
public void Initialize(PhotonPeer peer, string serverAddress, string applicationName)
{
this.peer = peer;
Debug.Log("StatusConnect: "+peer.Connect(serverAddress, applicationName).ToString());
Debug.Log("StatusConnect: " + peer.PeerState.ToString());
}
public void Disconnect()
{
if (status != "disconnected")
{
peer.Disconnect();
}
}
public void Update()
{
if (status != "disconnected")
{
peer.Service();
}
}
public void OnStatusChanged(StatusCode statusCode)
{
Debug.Log("OnStatusChanged");
switch (statusCode)
{
case StatusCode.Connect:
{
status = "connected";
break;
}
case StatusCode.Disconnect:
case StatusCode.DisconnectByServer:
case StatusCode.DisconnectByServerLogic:
case StatusCode.DisconnectByServerUserLimit:
case StatusCode.TimeoutDisconnect:
{
status = "Disconinected";
break;
}
default:
{
status = "unexpected";
break;
}
}
}
public void DebugReturn(DebugLevel level, string message)
{
Debug.Log(message);
}
public void OnEvent(EventData eventData)
{
Debug.Log("Event");
throw new NotImplementedException();
}
public void OnOperationResponse(OperationResponse operationResponse)
{
Debug.Log("Response");
throw new NotImplementedException();
}
}
Скрипт с классом Login вешаю на Main Camera
Отображается кнопка и надпись под ней. Но коннекта не происходит. Подскажите в чем проблема, или как посмотреть ошибку.
P.S. Вопрос вроде и по сети и для раздела "Почемучка" так что за размещения его в раздели Сеть просьба не ругать.