
作用:客户端服务器双向传输
BaseRequest基类有3个:Common.Operation码、DefaultRequest请求、OnOperationResponse 处理
Unity指定common.Operation码
重写2个:DefaultRequest请求、OnOperationResponse 处理
Script—Request—新建RegisterRequest.cs
RegisterRequest.cs
using System.Collections;using System.Collections.Generic;using UnityEngine;using ExitGames.Client.Photon;using Common;//登录请求public class LoginRequest : Request {[HideInInspector]//因为这个是从panel代码传过来的所以隐藏Unity里的拖拉public string Username;[HideInInspector]//因为这个是从panel代码传过来的所以隐藏Unity里的拖拉public string Password;private LoginPanel loginPanel;//override重写Start()方法public override void Start(){base.Start();//调用一下,因为会有事情做loginPanel = GetComponent<LoginPanel>();//对loginPanel赋值}//Photon登录public override void DefaultRequest(){Dictionary<byte,object> data = new Dictionary<byte,object>();//字典data.Add((byte)ParameterCode.Username, Username);//插入字典data.Add((byte)ParameterCode.Password, Password);//插入字典PhotonEngine.Peer.OpCustom((byte)OpCode, data, true);//Photon登录}//判断、回应public override void OnOperationResponse(OperationResponse operationResponse){Debug.Log("登录成功的验证码0为成功,1为错误失败。响应码为:"+operationResponse.ReturnCode);//返回响应码ReturnCode returnCode = (ReturnCode)operationResponse.ReturnCode;//获得响应码if (returnCode == ReturnCode.Success){PhotonEngine.username = Username;//保存名字到服务器}loginPanel.OnLoginResponse(returnCode);}}