GlobalConfigComponent.cs 703 B

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