LocationProxyComponentSystem.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Threading.Tasks;
  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. StartConfigComponent startConfigComponent = StartConfigComponent.Instance;
  18. StartConfig startConfig = startConfigComponent.LocationConfig;
  19. self.LocationAddress = startConfig.GetComponent<InnerConfig>().IPEndPoint;
  20. }
  21. public static async ETTask Add(this LocationProxyComponent self, long key, long instanceId)
  22. {
  23. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.LocationAddress);
  24. await session.Call(new ObjectAddRequest() { Key = key, InstanceId = instanceId });
  25. }
  26. public static async ETTask Lock(this LocationProxyComponent self, long key, long instanceId, int time = 1000)
  27. {
  28. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.LocationAddress);
  29. await session.Call(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. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.LocationAddress);
  34. await session.Call(new ObjectUnLockRequest() { Key = key, OldInstanceId = oldInstanceId, InstanceId = instanceId});
  35. }
  36. public static async ETTask Remove(this LocationProxyComponent self, long key)
  37. {
  38. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.LocationAddress);
  39. await session.Call(new ObjectRemoveRequest() { Key = key });
  40. }
  41. public static async ETTask<long> Get(this LocationProxyComponent self, long key)
  42. {
  43. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.LocationAddress);
  44. ObjectGetResponse response = (ObjectGetResponse)await session.Call(new ObjectGetRequest() { Key = key });
  45. return response.InstanceId;
  46. }
  47. }
  48. }