LocationProxyComponentSystem.cs 2.2 KB

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