123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- using Newtonsoft.Json;
- using PublicTools.XMLDataBase;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace XRTool.Util
- {
- /// <summary>
- /// 读取系统配置
- /// 系统配置是json文件,默认会放在steammingpath下面
- /// 应用发布时会生成到sd卡目录或者可读写文件下面
- /// </summary>
- public class SystemSettingMgr : Singleton<SystemSettingMgr>
- {
- private TableInterface table;
- public SystemSettings settings;
- public SystemSettingMgr()
- {
- InitSettings();
- }
- /// <summary>
- /// 实例化Dlg窗口
- /// </summary>
- public void InstanceDlg()
- {
- GameObject dlg = ResourcesManager.Instance.DataLoader.Load("SystemSetDlg") as GameObject;
- if (dlg)
- {
- GameObject obj = GameObject.Instantiate(dlg) as GameObject;
- GameNode.Instance.SetParent(ObjNode.WorldCanvas, obj.transform, new Vector3(0, 0, 2), Vector3.zero, new Vector3(0.001f, 0.001f, 0.001f));
- }
- }
- public void OpenSql()
- {
- if (XSql.Instance.Open(Application.persistentDataPath))
- {
- table = XSql.Instance.OpenTable(typeof(SystemSettings).Name, ".xml", true);
- if (!table.Open())
- {
- table.Create(typeof(SystemSettings).Name);
- }
- ReadSetting();
- }
- else
- {
- UnityLog.Instance.LogError("数据库打开失败,请检查权限");
- }
- }
- public SystemSettings ReadSetting()
- {
- settings = table.FindData<SystemSettings>("SystemSetting");
- if (settings == null)
- {
- settings = new SystemSettings();
- table.InsertData(settings);
- table.Save();
- }
- return settings;
- }
- /// <summary>
- /// 获取配置
- /// </summary>
- public void InitSettings()
- {
- if (table == null)
- {
- OpenSql();
- }
- else
- {
- ReadSetting();
- }
- SetLogLevel();
- }
- private void SetLogLevel()
- {
- #if !UNITY_EDITOR
- if (settings != null)
- {
- UnityLog.Instance.logLevel = settings.LogLevel;
- }
- #endif
- }
- public void SaveSettings()
- {
- if (table == null)
- {
- OpenSql();
- if (table != null)
- {
- table.UpdateData(this.settings);
- table.Save();
- }
- }
- else
- {
- UnityLog.Instance.Log(JsonConvert.SerializeObject(this.settings));
- bool isChange = table.UpdateData(this.settings);
- UnityLog.Instance.Log(isChange);
- table.Save();
- UnityLog.Instance.Log(JsonConvert.SerializeObject(this.settings));
- UnityLog.Instance.Log(settings.IfOpenFPS);
- }
- SetLogLevel();
- }
- public void SetLogLevel(int level)
- {
- if (this.settings != null)
- {
- this.settings.LogLevel = level;
- SaveSettings();
- }
- }
- public void SetBoolFPS(bool ifOpenFPS)
- {
- if (this.settings != null)
- {
- this.settings.IfOpenFPS = ifOpenFPS;
- SaveSettings();
- }
- }
- public void SetBoolLogText(bool ifOpenLog)
- {
- if (this.settings != null)
- {
- this.settings.IfOpenLog = ifOpenLog;
- SaveSettings();
- }
- }
- public void SetQuilty(int level)
- {
- if (this.settings != null)
- {
- QualitySettings.SetQualityLevel(level);
- settings.QualityLevel = level;
- SaveSettings();
- }
- }
- public void SetShadowType(int shadowType)
- {
- if (this.settings != null)
- {
- settings.ShadowType = shadowType;
- SaveSettings();
- }
- }
- public void ChangeIPAddress(string ip)
- {
- if (this.settings != null)
- {
- settings.Ip = ip;
- SaveSettings();
- }
- }
- public void ChangePort(string port)
- {
- if (this.settings != null)
- {
- settings.Port = port;
- SaveSettings();
- }
- }
- }
- }
|