PhotonServer(4)
unity客户端搭建
创建UnityClient工程
导入Photon3Unity3D.dll到Plugin文件夹

创建PhotonEngine.cs 与服务段交互
using System.Collections;
using System.Collections.Generic;
using ExitGames.Client.Photon;
using UnityEngine;
using UnityEngine.UI;
public class PhotonEngine : MonoBehaviour,IPhotonPeerListener
{
public static PhotonPeer Peer
{
get { return peer; }
}
private static PhotonEngine Instance;
private static PhotonPeer peer = null;
void Awake()
{
if (Instance==null)
{
Instance = this;
DontDestroyOnLoad(this.gameObject);
}
else if (Instance!=this)
{
Destroy(this.gameObject );
return;
}
}
//void CallConnect()
//{
//}
// Start is called before the first frame update
void Start()
{
//通过listener接受服务段响应
peer = new PhotonPeer(this, ConnectionProtocol.Udp);
peer.Connect("127.0.0.1:5055", "MyGame1");
//peer.OpCustom()
}
// Update is called once per frame
void Update()
{
peer.Service();
}
void OnDestroy()
{
if (peer!=null&&peer.PeerState==PeerStateValue.Disconnected)
{
peer.Disconnect();
}
}
public void DebugReturn(DebugLevel level, string message)
{
//throw new System.NotImplementedException();
}
public void OnEvent(EventData eventData)
{
//throw new System.NotImplementedException();
}
public void OnOperationResponse(OperationResponse operationResponse)
{
//throw new System.NotImplementedException();
}
public void OnStatusChanged(StatusCode statusCode)
{
//throw new System.NotImplementedException();
Debug.Log(statusCode);
}
}


浙公网安备 33010602011771号