Network.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using LitJson;
  5. using System;
  6. public class Network {
  7. public bool active = false;
  8. public string action;
  9. public WWWForm data;
  10. public string url;
  11. private Action<string> failedFun;
  12. private Action<JsonData> successFun;
  13. /// <summary>
  14. /// Init the specified action, data, type, success and failed.
  15. /// </summary>
  16. /// <param name="action">Action.</param>
  17. /// <param name="data">Data.</param>
  18. /// <param name="success">Success.</param>
  19. /// <param name="failed">Failed.</param>
  20. public void init(string action, WWWForm data,Action<JsonData> successFun = null ,Action<string> failedFun = null)
  21. {
  22. this.action = action;
  23. this.data = data;
  24. this.successFun = successFun;
  25. this.failedFun = failedFun;
  26. active = false;
  27. this.url = action;
  28. }
  29. public void scuess(JsonData data)
  30. {
  31. if (successFun != null) {
  32. successFun (data);
  33. }
  34. }
  35. public void failed (string msg)
  36. {
  37. if (failedFun != null) {
  38. failedFun (msg);
  39. }
  40. }
  41. public void error(string msg)
  42. {
  43. if (failedFun != null) {
  44. failedFun (msg);
  45. }
  46. }
  47. }