RobotManager.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Random = UnityEngine.Random;
  5. public class RobotManager
  6. {
  7. #region Config
  8. public static List<Robot> Robots = new List<Robot>();
  9. #endregion
  10. public static void AddRobot(int sfsRoomID, int maxRobot)
  11. {
  12. Robot.Initialize();
  13. Robot robot = new Robot();
  14. robot.Connect(sfsRoomID, maxRobot);
  15. Robots.Add(robot);
  16. }
  17. private static float MinRandomTime = 3f;
  18. private static float MaxRandomTime = 10f;
  19. public static void DeactivateAllRobots(bool afterRandomTime)
  20. {
  21. if (afterRandomTime)
  22. {
  23. foreach (var robot in Robots)
  24. {
  25. DelayCall.Call(Random.Range(MinRandomTime, MaxRandomTime), robot.Deactivate);
  26. }
  27. }
  28. else
  29. {
  30. foreach (var robot in Robots)
  31. {
  32. robot.Deactivate();
  33. }
  34. }
  35. Robots = new List<Robot>();
  36. }
  37. public static void Update()
  38. {
  39. for (int i = 0; i < Robots.Count; i++)
  40. {
  41. if (Robots[i].Update())
  42. {
  43. Robots[i--].Deactivate();
  44. }
  45. }
  46. }
  47. }