ActorComponent.cs 979 B

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