Request.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Scenes.scripts.utils
  4. {
  5. [Serializable]
  6. public class Request
  7. {
  8. public string name = null;
  9. public List<string> args = null;
  10. public Callback callback = null;
  11. private Request()
  12. {
  13. }
  14. [Serializable]
  15. public class Callback
  16. {
  17. public string name = null;
  18. public string method = null;
  19. public string param = null;
  20. }
  21. [NonSerialized]
  22. static Request request;
  23. [NonSerialized]
  24. public static List<string> cmdlist = new List<string>();
  25. public static Request Build()
  26. {
  27. request = new Request();
  28. cmdlist.Clear();
  29. return request;
  30. }
  31. public Request Name(string service_method)
  32. {
  33. this.name = service_method;
  34. return this;
  35. }
  36. public Request Param<T>(string key, T value)
  37. {
  38. cmdlist.Add(createParamStr(key, value));
  39. this.args = cmdlist;
  40. return this;
  41. }
  42. public Request AndroidCallback(Callback callback)
  43. {
  44. this.callback = callback;
  45. return this;
  46. }
  47. public static string createParamStr<T>(string name, T value)
  48. {
  49. string baseCmd = "{\"name\": \"tempName\",\"value\": \"tempValue\"}";
  50. string formatStr0 = baseCmd.Replace("\"tempName\"", "\"" + name + "\"");
  51. string formatStr1 = formatStr0.Replace("\"tempValue\"", "\"" + value + "\"");
  52. return formatStr1;
  53. }
  54. }
  55. }