LocationProxyComponentSystem.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. namespace ET
  3. {
  4. [ObjectSystem]
  5. public class LocationProxyComponentSystem : AwakeSystem<LocationProxyComponent>
  6. {
  7. public override void Awake(LocationProxyComponent self)
  8. {
  9. self.Awake();
  10. }
  11. }
  12. public static class LocationProxyComponentEx
  13. {
  14. public static void Awake(this LocationProxyComponent self)
  15. {
  16. LocationProxyComponent.Instance = self;
  17. }
  18. public static async ETTask Add(this LocationProxyComponent self, long key, long instanceId)
  19. {
  20. await MessageHelper.CallActor(
  21. StartSceneConfigCategory.Instance.LocationConfig.SceneId,
  22. new ObjectAddRequest() { Key = key, InstanceId = instanceId });
  23. }
  24. public static async ETTask Lock(this LocationProxyComponent self, long key, long instanceId, int time = 1000)
  25. {
  26. await MessageHelper.CallActor(
  27. StartSceneConfigCategory.Instance.LocationConfig.SceneId,
  28. new ObjectLockRequest() { Key = key, InstanceId = instanceId, Time = time });
  29. }
  30. public static async ETTask UnLock(this LocationProxyComponent self, long key, long oldInstanceId, long instanceId)
  31. {
  32. await MessageHelper.CallActor(
  33. StartSceneConfigCategory.Instance.LocationConfig.SceneId,
  34. new ObjectUnLockRequest() { Key = key, OldInstanceId = oldInstanceId, InstanceId = instanceId });
  35. }
  36. public static async ETTask Remove(this LocationProxyComponent self, long key)
  37. {
  38. await MessageHelper.CallActor(
  39. StartSceneConfigCategory.Instance.LocationConfig.SceneId,
  40. new ObjectRemoveRequest() { Key = key });
  41. }
  42. public static async ETTask<long> Get(this LocationProxyComponent self, long key)
  43. {
  44. if (key == 0)
  45. {
  46. throw new Exception($"get location key 0");
  47. }
  48. ObjectGetResponse response =
  49. (ObjectGetResponse)await MessageHelper.CallActor(
  50. StartSceneConfigCategory.Instance.LocationConfig.SceneId,
  51. new ObjectGetRequest() { Key = key });
  52. return response.InstanceId;
  53. }
  54. public static async ETTask AddLocation(this Entity self)
  55. {
  56. await Game.Scene.GetComponent<LocationProxyComponent>().Add(self.Id, self.InstanceId);
  57. }
  58. public static async ETTask RemoveLocation(this Entity self)
  59. {
  60. await Game.Scene.GetComponent<LocationProxyComponent>().Remove(self.Id);
  61. }
  62. }
  63. }