LogToClientComponent.cs 968 B

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