GardenSmartFoxManager.cs 2.3 KB

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