微信登录

配置 - Common公共码code 服务器~客户端

作用:服务器和Unity共用的请求响应码

新建Common类

解决方案资源管理器—解决方案“MyGameServer”—右键—添加—新建项—类库
命名为:

  1. 解决方案“MyGameServer”里
  2. MyGameServer并排
  3. common

MyGameServer引入

解决方案资源管理器—MyGameServer—引用—右键—添加引用—项目—解决方案—common—确定
common.dll就可以和MyGameServer一起生成在:
C:\Photon-OnPremise-Server-SDK_v4-0-29-11263\deploy\MyGameServer\bin

Unity引入

新生成的common.cs复制到Unity的Assest-pulgins

创建以下文件

  1. EventCode.cs-------------------#单向事件码
  2. OperationCode.cs--------------#双向事件码
  3. ParameterCode.cs-------------#数据参数接收码
  4. PlayerData.cs-------------------#玩家数据
  5. ReturnCode.cs------------------#返回码
  6. Vector3Data.cs------------------#位置数据

EventCode.cs—————————-#单向事件码

  1. namespace Common
  2. {
  3. public enum EventCode:byte //区分服务器向客户端发送的事件的类型
  4. {
  5. NewPlayer,//新的玩家
  6. SyncPosition//打包位置信息
  7. }
  8. }

OperationCode.cs———————#双向事件码

  1. namespace Common
  2. {
  3. public enum OperationCode:byte //区分请求和响应的类型
  4. {
  5. Login,
  6. Register,
  7. Default,
  8. SyncPosition,
  9. SyncPlayer
  10. }
  11. }

ParameterCode.cs——————-#数据参数接收码

  1. namespace Common
  2. {
  3. public enum ParameterCode:byte //区分传送数据的时候,参数的类型
  4. {
  5. Username,
  6. Password,
  7. Position,
  8. X,Y,Z,
  9. UsernameList,
  10. PlayerDataList
  11. }
  12. }

PlayerData.cs—————————-#玩家数据

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Common
  6. {
  7. [Serializable]
  8. public class PlayerData
  9. {
  10. public Vector3Data Pos { get; set; }
  11. public string Username { get; set; }
  12. }
  13. }

ReturnCode.cs—————————#返回码

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Common
  6. {
  7. public enum ReturnCode:short
  8. {
  9. Success,
  10. Failed
  11. }
  12. }

Vector3Data.cs—————————#位置数据

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //接收方向
  6. namespace Common
  7. {
  8. [Serializable]
  9. public class Vector3Data
  10. {
  11. public float x { get; set; }
  12. public float y { get; set; }
  13. public float z { get; set; }
  14. }
  15. }