using SC.XR.Unity; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace SC.XR.Unity { public class Module_SDKConfiguration : MonoBehaviour { private static Module_SDKConfiguration mInstance; public static Module_SDKConfiguration getInstance { get { if (mInstance == null) { mInstance = new GameObject("SDKConfiguration").AddComponent(); } return mInstance; } } private SDKConfigTranslation SDKConfiguration; private ConfigFile configFile; private string fileConfigPath { get { return Application.persistentDataPath + "/" + "SDK"+"_Configs.txt"; } } public bool isShowConfigLog = false; void Awake() { SDKConfiguration = SDKConfigTranslation.getInstance; if (SDKConfiguration == null) { DebugMy.Log("SDKConfiguration Not Exist !", this, true); } SDKConfiguration.gameObject.transform.SetParent(transform); isShowConfigLog = false; LoadAllConfigFromFileAndAsset(); } private void OnDisable() { SaveAllConfigToFile(); } private void OnDestroy() { if (mInstance != null) { SaveAllConfigToFile(); } } private void OnApplicationPause(bool pause) { return; if (pause) { SaveAllConfigToFile(); } else { LoadAllConfigFromFileAndAsset(); } } private void OnApplicationQuit() { SaveAllConfigToFile(); } private void LoadAllConfigFromFileAndAsset() { configFile = new ConfigFile(fileConfigPath, true); if (Application.isEditor) { DebugMy.Log("Platfom isEditor: Remove SDKConfigs File", this, true); configFile.RemoveConfigFile(); } bool isExist = configFile.ParseConfig(); if (isExist == false) { DebugMy.Log("ConfigFile:" + fileConfigPath + " Not Exist !", this, true); } else { DebugMy.Log("ConfigFile:" + fileConfigPath + " Exist !", this, true); } if (SDKConfiguration) { configFile.SetString("SDK_Information", "Version", API_Module_SDKVersion.Version); if (isExist == false) { foreach (var section in SDKConfiguration.Configs) { foreach (var keyValue in section.KEY_VALUE) { configFile.SetString(section.section, keyValue.Name, keyValue.Value); DebugMy.Log("Write To ConfigsFile ==> [" + section.section + "]:" + keyValue.Name + "=" + keyValue.Value, this, isShowConfigLog); } } } else { foreach (var dic in configFile.Configs.Keys) { foreach (var keyValue in configFile.Configs[dic]) { DebugMy.Log("Read From ConfigsFile ==> [" + dic + "]:" + keyValue.Key + "=" + keyValue.Value, this, true); } } foreach (var section in SDKConfiguration.Configs) { foreach (var keyValue in section.KEY_VALUE) { if (configFile.AddString(section.section, keyValue.Name, keyValue.Value)) { DebugMy.Log("Add Extra Config From SDKConfigurationAsset ==> [" + section.section + "]:" + keyValue.Name + "=" + keyValue.Value, this, isShowConfigLog); } } } } SaveAllConfigToFile(); } } public int GetInt(string section, string key, int defaultVal) { return getInstance.configFile.GetInt(section,key,defaultVal); } public bool GetBool(string section, string key, int defaultVal) { return getInstance.configFile.GetInt(section, key, defaultVal) > 0 ? true : false; } public string GetString(string section, string key, string defaultVal) { return getInstance.configFile.GetString(section, key, defaultVal); } public float GetFloat(string section, string key, float defaultVal) { return getInstance.configFile.GetFloat(section, key, defaultVal); } public bool HasKey(string section, string key) { return getInstance.configFile.HasKey(section,key); } public void SaveAllConfigToFile() { configFile.SaveConfig(); } public void SetString(string sec, string key, string val) { getInstance.configFile.SetString(sec, key, val); } } }