LocationProxyComponent.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Threading.Tasks;
  2. namespace Model
  3. {
  4. [ObjectEvent]
  5. public class LocationProxyComponentEvent : ObjectEvent<LocationProxyComponent>, IAwake
  6. {
  7. public void Awake()
  8. {
  9. this.Get().Awake();
  10. }
  11. }
  12. public class LocationProxyComponent : Component
  13. {
  14. public string LocationAddress;
  15. public void Awake()
  16. {
  17. this.LocationAddress = Game.Scene.GetComponent<StartConfigComponent>().LocationConfig.GetComponent<InnerConfig>().Address;
  18. }
  19. public async Task Add(long key)
  20. {
  21. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.LocationAddress);
  22. await session.Call<ObjectAddRequest, ObjectAddResponse>(new ObjectAddRequest() { Key = key });
  23. }
  24. public async Task Remove(long key)
  25. {
  26. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.LocationAddress);
  27. await session.Call<ObjectRemoveRequest, ObjectRemoveResponse>(new ObjectRemoveRequest() { Key = key });
  28. }
  29. public async Task<string> Get(long key)
  30. {
  31. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.LocationAddress);
  32. ObjectGetResponse response = await session.Call<ObjectGetRequest, ObjectGetResponse>(new ObjectGetRequest() { Key = key });
  33. return response.Location;
  34. }
  35. public override void Dispose()
  36. {
  37. if (this.Id == 0)
  38. {
  39. return;
  40. }
  41. base.Dispose();
  42. }
  43. }
  44. }