using PublicTools.XMLDataBase; using System.Collections; using System.Collections.Generic; using UnityEngine; using XRTool.Util; namespace XRTool.UI { /// /// 数据访问单例 /// /// public class DataConfMgr : Singleton> { private TableHelper tableHelper; public TableHelper TableHelper { get => tableHelper; set => tableHelper = value; } public bool IsInit() { if (TableHelper == null) { return false; } return TableHelper.isInit; } /// /// 按照主键打开表格 /// /// public void OpenTable(string priKey = null) { TableHelper.Open(priKey); } /// /// 打开某路径下的资源 /// /// public void OpenData(string path, bool isForce = false) { if (TableHelper == null || isForce) { if (TableHelper != null) { TableHelper.Reset(!isForce); } TableHelper = new TableHelper(path); } } /// /// 清除所有 /// public void ClearAll() { TableHelper?.DelAll(); } /// /// 删除某一数据 /// /// /// public void DelConf(string key, bool isSave = true) { TableHelper?.DelConf(key, isSave); } /// /// 按照指定的key值查找 /// /// /// public T Get(string key) { if (TableHelper == null) { return default(T); } return TableHelper.FindData(key); } /// /// 获取所有 /// /// public List GetAll() { if (TableHelper == null) { return null; } return TableHelper.DataList; } /// /// 加入一条数据 /// /// /// public void Insert(T t, bool isSave = true) { TableHelper.AddData(t, isSave); } public void Close() { TableHelper.Close(); } public void Save() { TableHelper.SaveData(); } } }