SFSManager.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 Config
  75. public static PlazaRoomEvent PlazaRoomEvent
  76. {
  77. get { return GardenSmartFox.EventManager.PlazaRoomEvent; }
  78. }
  79. public static PlazaRoomController PlazaRoomController
  80. {
  81. get { return GardenSmartFox.PlazaRoomController; }
  82. }
  83. public static GardenSmartFox GardenSmartFox;
  84. #endregion
  85. public override bool InitAtOnce()
  86. {
  87. enabled = true;
  88. return base.InitAtOnce();
  89. }
  90. public void Start()
  91. {
  92. GardenSmartFox = new GardenSmartFox();
  93. }
  94. public void OnDisable()
  95. {
  96. if (GardenSmartFox != null)
  97. GardenSmartFox.Connector.Disconnect();
  98. }
  99. public void OnApplicationQuit()
  100. {
  101. if (GardenSmartFox != null)
  102. {
  103. GardenSmartFox.Connector.Disconnect();
  104. }
  105. //RobotManager.DeactivateAllRobots(false);
  106. }
  107. public void Update()
  108. {
  109. GardenSmartFox.SmartFox.ProcessEvents();
  110. GardenSmartFox.PlazaRoomController.Update();
  111. GardenSmartFox.ProcessRequest();
  112. }
  113. }