微信登录

Operation双向 - 客请求 - XXRequest PE + 例子

作用:客户端服务器双向传输

格式

BaseRequest基类有3个:Common.Operation码、DefaultRequest请求、OnOperationResponse 处理
Unity指定common.Operation码
重写2个:DefaultRequest请求、OnOperationResponse 处理

例子

Script—Request—新建RegisterRequest.cs

  1. RegisterRequest.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using ExitGames.Client.Photon;
  5. using Common;
  6. //登录请求
  7. public class LoginRequest : Request {
  8. [HideInInspector]//因为这个是从panel代码传过来的所以隐藏Unity里的拖拉
  9. public string Username;
  10. [HideInInspector]//因为这个是从panel代码传过来的所以隐藏Unity里的拖拉
  11. public string Password;
  12. private LoginPanel loginPanel;
  13. //override重写Start()方法
  14. public override void Start()
  15. {
  16. base.Start();//调用一下,因为会有事情做
  17. loginPanel = GetComponent<LoginPanel>();//对loginPanel赋值
  18. }
  19. //Photon登录
  20. public override void DefaultRequest()
  21. {
  22. Dictionary<byte,object> data = new Dictionary<byte,object>();//字典
  23. data.Add((byte)ParameterCode.Username, Username);//插入字典
  24. data.Add((byte)ParameterCode.Password, Password);//插入字典
  25. PhotonEngine.Peer.OpCustom((byte)OpCode, data, true);//Photon登录
  26. }
  27. //判断、回应
  28. public override void OnOperationResponse(OperationResponse operationResponse)
  29. {
  30. Debug.Log("登录成功的验证码0为成功,1为错误失败。响应码为:"+operationResponse.ReturnCode);//返回响应码
  31. ReturnCode returnCode = (ReturnCode)operationResponse.ReturnCode;//获得响应码
  32. if (returnCode == ReturnCode.Success)
  33. {
  34. PhotonEngine.username = Username;//保存名字到服务器
  35. }
  36. loginPanel.OnLoginResponse(returnCode);
  37. }
  38. }
Operation双向 - 客请求 - XXRequest PE + 例子