LogToClientComponent.cs 699 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Base;
  2. namespace Model
  3. {
  4. [ObjectEvent]
  5. public class LogToClientComponentEvent : ObjectEvent<LogToClientComponent>, IAwake
  6. {
  7. public void Awake()
  8. {
  9. this.GetValue().Awake();
  10. }
  11. }
  12. public class LogToClientComponent : Component
  13. {
  14. public void Awake()
  15. {
  16. Log.Callback.Add(this.Id, this.LogToClient);
  17. }
  18. private void LogToClient(LogType type, string message)
  19. {
  20. if (this.Owner.Id == 0)
  21. {
  22. return;
  23. }
  24. this.GetComponent<MessageComponent>().Send(new S2C_ServerLog { Type = type, Log = message });
  25. }
  26. public override void Dispose()
  27. {
  28. if (this.Id == 0)
  29. {
  30. return;
  31. }
  32. long id = this.Id;
  33. base.Dispose();
  34. Log.Callback.Remove(id);
  35. }
  36. }
  37. }