LogToClientComponent.cs 829 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. private string appType;
  15. public void Awake()
  16. {
  17. this.appType = Game.Scene.GetComponent<OptionsComponent>().Options.AppType;
  18. Log.Callback.Add(this.Id, this.LogToClient);
  19. }
  20. private void LogToClient(LogType type, string message)
  21. {
  22. if (this.Owner.Id == 0)
  23. {
  24. return;
  25. }
  26. this.GetComponent<MessageComponent>().Send(new S2C_ServerLog { AppType = this.appType, Type = type, Log = message });
  27. }
  28. public override void Dispose()
  29. {
  30. if (this.Id == 0)
  31. {
  32. return;
  33. }
  34. long id = this.Id;
  35. base.Dispose();
  36. Log.Callback.Remove(id);
  37. }
  38. }
  39. }