LocationProxyComponent.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 int AppId;
  16. public void Awake()
  17. {
  18. StartConfig startConfig = Game.Scene.GetComponent<StartConfigComponent>().LocationConfig;
  19. this.AppId = startConfig.AppId;
  20. this.LocationAddress = startConfig.GetComponent<InnerConfig>().Address;
  21. }
  22. public async Task Add(long key)
  23. {
  24. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.LocationAddress);
  25. await session.Call<ObjectAddResponse>(new ObjectAddRequest() { Key = key });
  26. }
  27. public async Task Lock(long key, int time = 1000)
  28. {
  29. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.LocationAddress);
  30. await session.Call<ObjectLockResponse>(new ObjectLockRequest() { Key = key, AppId = this.AppId, Time = time });
  31. }
  32. public async Task UnLock(long key, string value)
  33. {
  34. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.LocationAddress);
  35. await session.Call<ObjectUnLockResponse>(new ObjectUnLockRequest() { Key = key, AppId = this.AppId, Value = value});
  36. }
  37. public async Task Remove(long key)
  38. {
  39. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.LocationAddress);
  40. await session.Call<ObjectRemoveResponse>(new ObjectRemoveRequest() { Key = key });
  41. }
  42. public async Task<string> Get(long key)
  43. {
  44. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.LocationAddress);
  45. ObjectGetResponse response = await session.Call<ObjectGetResponse>(new ObjectGetRequest() { Key = key });
  46. return response.Location;
  47. }
  48. public override void Dispose()
  49. {
  50. if (this.Id == 0)
  51. {
  52. return;
  53. }
  54. base.Dispose();
  55. }
  56. }
  57. }