SFSManager.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.Collections.Generic;
  3. using Sfs2X;
  4. using Sfs2X.Requests;
  5. using UnityEngine;
  6. public class CounterAction
  7. {
  8. public int Count;
  9. public int Counter;
  10. public Action Action;
  11. public CounterAction(Action action, int count = 1)
  12. {
  13. Count = count;
  14. Action = action;
  15. }
  16. public void Invoke()
  17. {
  18. if (Counter++ < Count)
  19. {
  20. Action.Invoke();
  21. }
  22. }
  23. public void Bind(ref Action parent)
  24. {
  25. parent += Invoke;
  26. }
  27. }
  28. public class CounterAction<T>
  29. {
  30. public int Count;
  31. public int Counter;
  32. public Action<T> Action;
  33. public CounterAction(Action<T> action, int count = 1)
  34. {
  35. Count = count;
  36. Action = action;
  37. }
  38. public void Invoke(T t)
  39. {
  40. if (Counter++ < Count)
  41. {
  42. Action.Invoke(t);
  43. }
  44. }
  45. public void Bind(ref Action<T> parent)
  46. {
  47. parent += Invoke;
  48. }
  49. }
  50. public class CounterAction<T1, T2>
  51. {
  52. public int Count;
  53. public int Counter;
  54. public Action<T1, T2> Action;
  55. public CounterAction(Action<T1, T2> action, int count = 1)
  56. {
  57. Count = count;
  58. Action = action;
  59. }
  60. public void Invoke(T1 t1, T2 t2)
  61. {
  62. if (Counter++ < Count)
  63. {
  64. Action.Invoke(t1, t2);
  65. }
  66. }
  67. public void Bind(ref Action<T1, T2> parent)
  68. {
  69. parent += Invoke;
  70. }
  71. }
  72. public class SFSManager : Regist
  73. {
  74. #region Variable
  75. public static GardenSmartFox GardenSmartFox;
  76. #endregion
  77. public override bool RegistImmed()
  78. {
  79. enabled = true;
  80. return base.RegistImmed();
  81. }
  82. public void Start()
  83. {
  84. GardenSmartFox = new GardenSmartFox();
  85. }
  86. public void OnDisable()
  87. {
  88. if (GardenSmartFox != null)
  89. GardenSmartFox.Connector.Disconnect();
  90. }
  91. public void OnApplicationQuit()
  92. {
  93. if (GardenSmartFox != null)
  94. {
  95. GardenSmartFox.Connector.Disconnect();
  96. }
  97. //RobotManager.DeactivateAllRobots(false);
  98. }
  99. public void Update()
  100. {
  101. GardenSmartFox.SmartFox.ProcessEvents();
  102. GardenSmartFox.PlazaRoomManager.Update();
  103. GardenSmartFox.ProcessRequest();
  104. }
  105. }