GlobalConfigComponent.cs 716 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.IO;
  2. using Base;
  3. namespace Model
  4. {
  5. [ObjectEvent]
  6. public class GlobalConfigComponentEvent : ObjectEvent<GlobalConfigComponent>, IAwake
  7. {
  8. public void Awake()
  9. {
  10. this.GetValue().Awake();
  11. }
  12. }
  13. /// <summary>
  14. /// 全局配置
  15. /// </summary>
  16. public class GlobalConfigComponent : Component
  17. {
  18. public GlobalProto GlobalProto;
  19. public void Awake()
  20. {
  21. {
  22. #if UNITY_EDITOR
  23. string filePath = @"./GlobalProto.txt";
  24. #else
  25. string filePath = @"../GlobalProto.txt";
  26. #endif
  27. if (!File.Exists(filePath))
  28. {
  29. throw new ConfigException("没有找到配置文件GlobalProto.txt");
  30. }
  31. this.GlobalProto = MongoHelper.FromJson<GlobalProto>(File.ReadAllLines(filePath)[0]);
  32. }
  33. }
  34. }
  35. }