RemoteCommand.cs 776 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Text;
  3. using UnityEngine;
  4. namespace YooAsset
  5. {
  6. internal enum ERemoteCommand
  7. {
  8. /// <summary>
  9. /// 采样一次
  10. /// </summary>
  11. SampleOnce = 0,
  12. }
  13. [Serializable]
  14. internal class RemoteCommand
  15. {
  16. /// <summary>
  17. /// 命令类型
  18. /// </summary>
  19. public int CommandType;
  20. /// <summary>
  21. /// 命令附加参数
  22. /// </summary>
  23. public string CommandParam;
  24. /// <summary>
  25. /// 序列化
  26. /// </summary>
  27. public static byte[] Serialize(RemoteCommand command)
  28. {
  29. return Encoding.UTF8.GetBytes(JsonUtility.ToJson(command));
  30. }
  31. /// <summary>
  32. /// 反序列化
  33. /// </summary>
  34. public static RemoteCommand Deserialize(byte[] data)
  35. {
  36. return JsonUtility.FromJson<RemoteCommand>(Encoding.UTF8.GetString(data));
  37. }
  38. }
  39. }