RobotManagerComponentSystem.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Linq;
  3. namespace ET
  4. {
  5. public static class RobotManagerComponentSystem
  6. {
  7. public static async ETTask<Scene> NewRobot(this RobotManagerComponent self, int zone)
  8. {
  9. Scene zoneScene = null;
  10. try
  11. {
  12. zoneScene = SceneFactory.CreateZoneScene(zone, "Robot", self);
  13. await LoginHelper.Login(zoneScene, ConstValue.LoginAddress, zone.ToString(), zone.ToString());
  14. await EnterMapHelper.EnterMapAsync(zoneScene);
  15. Log.Debug($"create robot ok: {zone}");
  16. return zoneScene;
  17. }
  18. catch (Exception e)
  19. {
  20. zoneScene?.Dispose();
  21. throw new Exception($"RobotSceneManagerComponent create robot fail, zone: {zone}", e);
  22. }
  23. }
  24. public static void RemoveAll(this RobotManagerComponent self)
  25. {
  26. foreach (Entity robot in self.Children.Values.ToArray())
  27. {
  28. robot.Dispose();
  29. }
  30. }
  31. public static void Remove(this RobotManagerComponent self, long id)
  32. {
  33. self.GetChild<Scene>(id)?.Dispose();
  34. }
  35. public static void Clear(this RobotManagerComponent self)
  36. {
  37. foreach (Entity entity in self.Children.Values.ToArray())
  38. {
  39. entity.Dispose();
  40. }
  41. }
  42. }
  43. }