ActorComponent.cs 978 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. namespace Model
  5. {
  6. public class ActorMessageInfo
  7. {
  8. public Session Session;
  9. public uint RpcId;
  10. public ActorRequest Message;
  11. }
  12. /// <summary>
  13. /// 挂上这个组件表示该Entity是一个Actor, 它会将Entity位置注册到Location Server, 接收的消息将会队列处理
  14. /// </summary>
  15. public class ActorComponent: Component
  16. {
  17. public IEntityActorHandler entityActorHandler;
  18. public long actorId;
  19. // 队列处理消息
  20. public Queue<ActorMessageInfo> queue;
  21. public TaskCompletionSource<ActorMessageInfo> tcs;
  22. public override void Dispose()
  23. {
  24. try
  25. {
  26. if (this.IsDisposed)
  27. {
  28. return;
  29. }
  30. base.Dispose();
  31. var t = this.tcs;
  32. this.tcs = null;
  33. t?.SetResult(null);
  34. Game.Scene.GetComponent<ActorManagerComponent>().Remove(actorId);
  35. }
  36. catch (Exception)
  37. {
  38. Log.Error($"unregister actor fail: {this.actorId}");
  39. }
  40. }
  41. }
  42. }