代码块
代码块语法遵循标准markdown代码,例如:
Unity内需要添加Photon3Unity3D.dll(在unity的Plugin里)
using UnityEngine;
using System.Collections;
using ExitGames.Client.Photon;
using System.Collections.Generic;
public class PhotonServerEngine2 : MonoBehaviour,IPhotonPeerListener {
private PhotonPeer peer;
private bool isConnected = false;
// Use this for initialization
void Start () {
peer = new PhotonPeer(this,ConnectionProtocol.Tcp);
peer.Connect("127.0.0.1:4530", "ChatServer");
}
// Update is called once per frame
void Update () {
peer.Service();
}
void OnGUI()
{
if (isConnected)
{
if (GUILayout.Button("Send a operation."))
{
Dictionary<byte, object> dict = new Dictionary<byte, object>();
dict.Add(1, "username");
dict.Add(2, "password");
peer.OpCustom(1, dict, true);
}
}
}
//主要是输出一些日志信息的
public void DebugReturn(DebugLevel level, string message)
{
Debug.Log(level + ":" + message);
}
public void OnEvent(EventData eventData)
{
}
public void OnOperationResponse(OperationResponse operationResponse)
{
Dictionary<byte, object> dict = operationResponse.Parameters;
object v = null;
dict.TryGetValue(1, out v);
Debug.Log("Get value from server:" + v.ToString()); //unity里输出要用Debug.Log
}
public void OnStatusChanged(StatusCode statusCode)
{
switch (statusCode)
{
case StatusCode.Connect:
isConnected = true;
Debug.Log("Connected success.");
break;
}
}
}