LocationProxyComponentSystem.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using ETModel;
  2. namespace ETHotfix
  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. StartConfigComponent startConfigComponent = StartConfigComponent.Instance;
  17. StartConfig startConfig = startConfigComponent.LocationConfig;
  18. self.LocationAddress = startConfig.GetComponent<InnerConfig>().IPEndPoint;
  19. }
  20. public static async ETTask Add(this LocationProxyComponent self, long key, long instanceId)
  21. {
  22. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.LocationAddress);
  23. await session.Call(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. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.LocationAddress);
  28. await session.Call(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. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.LocationAddress);
  33. await session.Call(new ObjectUnLockRequest() { Key = key, OldInstanceId = oldInstanceId, InstanceId = instanceId});
  34. }
  35. public static async ETTask Remove(this LocationProxyComponent self, long key)
  36. {
  37. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.LocationAddress);
  38. await session.Call(new ObjectRemoveRequest() { Key = key });
  39. }
  40. public static async ETTask<long> Get(this LocationProxyComponent self, long key)
  41. {
  42. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.LocationAddress);
  43. ObjectGetResponse response = (ObjectGetResponse)await session.Call(new ObjectGetRequest() { Key = key });
  44. return response.InstanceId;
  45. }
  46. }
  47. }