《Photon》

搭建客户端:

using UnityEngine;
using System.Collections;
using ExitGames.Client.Photon;

public class GameClinet : MonoBehaviour,IPhotonPeerListener {
PhotonPeer peer;
// Use this for initialization
void Start ()
{
peer = new PhotonPeer(this, ConnectionProtocol.Udp);
peer.Connect("127.0.0.1:5055", "Lite");
}

// Update is called once per frame
void Update () {
peer.Service();
}

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)
{
switch(statusCode)
{
case StatusCode.Connect:
Debug.Log("连接成功");
break;
case StatusCode.Disconnect:
Debug.Log("关闭连接");
break;
case StatusCode.ExceptionOnConnect:
Debug.Log("连接异常");
break;

}
}
}

photon客户端的脚本编写

发送消息到服务器:

  :如何实现发送消息函数SendMessage;

  : 如何调用photon服务函数Service;

首先实现的过程是客户端向服务器发送请求然后服务其作出反馈到客户端;

  编写一个sendmessage函数:

void SendMessage()

{

  //调用peer.OpCustom();函数实现从客户端发送消息到服务器

  Dictionary<byte,object> para = new Dictionary<byte,object>();

  para [LiteOpKey.GameId] = 1;

  peer.OpCustom(LiteOpKey.para,true);

}

转载于:https://www.cnblogs.com/ylllove/p/6088376.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值