Module_SDKConfiguration.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using SC.XR.Unity;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace SC.XR.Unity {
  6. public class Module_SDKConfiguration : MonoBehaviour {
  7. private static Module_SDKConfiguration mInstance;
  8. public static Module_SDKConfiguration getInstance {
  9. get {
  10. if (mInstance == null) {
  11. mInstance = new GameObject("SDKConfiguration").AddComponent<Module_SDKConfiguration>();
  12. }
  13. return mInstance;
  14. }
  15. }
  16. private SDKConfiguration SDKConfiguration;
  17. private ConfigFile configFile;
  18. private string fileConfigPath {
  19. get {
  20. return Application.persistentDataPath + "/" + "SDK"+"_Configs.txt";
  21. }
  22. }
  23. void Awake() {
  24. SDKConfiguration = Resources.Load<SDKConfiguration>("SDKConfiguration");
  25. if (SDKConfiguration == null) {
  26. DebugMy.Log("SDKConfiguration Not Exist !", this, true);
  27. }
  28. configFile = new ConfigFile(fileConfigPath,true);
  29. if (Application.isEditor) {
  30. DebugMy.Log("Platfom isEditor: Remove SDKConfigs File",this,true);
  31. configFile.RemoveConfigFile();
  32. }
  33. bool isExist = configFile.ParseConfig();
  34. if (isExist == false) {
  35. DebugMy.Log("ConfigFile:" + fileConfigPath + " Not Exist !", this, true);
  36. } else {
  37. DebugMy.Log("ConfigFile:" + fileConfigPath + " Exist !", this, true);
  38. }
  39. if (SDKConfiguration) {
  40. configFile.SetString("SDK_Information", "Version", API_Module_SDKVersion.Version);
  41. if (isExist == false) {
  42. foreach (var section in SDKConfiguration.Configs) {
  43. foreach (var keyValue in section.KEY_VALUE) {
  44. configFile.SetString(section.section, keyValue.Name, keyValue.Value);
  45. DebugMy.Log("Write To ConfigsFile ==> [" + section.section + "]:" + keyValue.Name + "=" + keyValue.Value, this, true);
  46. }
  47. }
  48. configFile.SaveConfig();
  49. } else {
  50. foreach (var dic in configFile.Configs.Keys) {
  51. foreach (var keyValue in configFile.Configs[dic]) {
  52. DebugMy.Log("Read From ConfigsFile ==> [" + dic + "]:" + keyValue.Key + "=" + keyValue.Value, this, true);
  53. }
  54. }
  55. }
  56. }
  57. }
  58. public int GetInt(string section, string key, int defaultVal) {
  59. return getInstance.configFile.GetInt(section,key,defaultVal);
  60. }
  61. public bool GetBool(string section, string key, int defaultVal) {
  62. return getInstance.configFile.GetInt(section, key, defaultVal) > 0 ? true : false;
  63. }
  64. public string GetString(string section, string key, string defaultVal) {
  65. return getInstance.configFile.GetString(section, key, defaultVal);
  66. }
  67. public float GetFloat(string section, string key, float defaultVal) {
  68. return getInstance.configFile.GetFloat(section, key, defaultVal);
  69. }
  70. public bool HasKey(string section, string key) {
  71. return getInstance.configFile.HasKey(section,key);
  72. }
  73. }
  74. }