LocalConfigComponent.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. using UnityGameFramework.Runtime;
  6. namespace GFMain
  7. {
  8. public class LocalConfigComponent : GameFrameworkComponent
  9. {
  10. private readonly Dictionary<string, string> dic = new Dictionary<string, string>();
  11. protected override void Awake()
  12. {
  13. base.Awake();
  14. string filePath = Path.Combine(Application.streamingAssetsPath, "LocalConfig.txt");
  15. string[] strLines = File.ReadAllLines(filePath);
  16. for (int i = 0; i < strLines.Length; i++)
  17. {
  18. string line = strLines[i].Trim();
  19. if (!line.StartsWith('#'))
  20. {
  21. var index = line.IndexOf(':');
  22. if (index != -1)
  23. {
  24. dic.Add(line.Substring(0, index).Trim(), line.Substring(index + 1).Trim());
  25. }
  26. }
  27. }
  28. }
  29. public string this[string key]
  30. {
  31. get
  32. {
  33. if (dic.ContainsKey(key))
  34. {
  35. return dic[key];
  36. }
  37. else
  38. {
  39. return null;
  40. }
  41. }
  42. }
  43. }
  44. }