LocationProxyComponentSystem.cs 2.1 KB

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