LocationProxyComponent.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 override void Dispose()
  30. {
  31. if (this.Id == 0)
  32. {
  33. return;
  34. }
  35. base.Dispose();
  36. }
  37. }
  38. }