Skip to content

Commit de3f363

Browse files
committed
记录Debugger的位置
1 parent 39434e1 commit de3f363

File tree

6 files changed

+126
-6
lines changed

6 files changed

+126
-6
lines changed

GameFramework/Runtime/Debugger/DebuggerManager.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public DebuggerManager()
4949
//FullRect = _settingMgr.Get<Rect>("DebuggerManager.FullRect", _defaultFullRect);
5050
FullRect = _defaultFullRect;
5151
WindowScale = _settingMgr.Get<float>("DebuggerManager.WindowScale", _defaultWindowScale);
52+
53+
_defaultSmallRect.position = _settingMgr.Get<Vector2>("DebuggerManager.Small.Position",Vector2.one*10);
5254
}
5355

5456
//初始化
@@ -175,7 +177,13 @@ public void OnImGui()
175177
}
176178
else
177179
{
178-
_defaultSmallRect = GUILayout.Window(0, _defaultSmallRect, DrawDebuggerSmallWindow, "<b>DEBUGGER</b>");
180+
var smallRect = GUILayout.Window(0, _defaultSmallRect, DrawDebuggerSmallWindow, "<b>DEBUGGER</b>");
181+
182+
if (smallRect != _defaultSmallRect)
183+
{
184+
_defaultSmallRect = smallRect;
185+
_settingMgr.Set<Vector2>("DebuggerManager.Small.Position", _defaultSmallRect.position);
186+
}
179187
}
180188
GUI.matrix = lastMatrix;
181189
GUI.skin = lastGuiSkin;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace Wanderer.GameFramework
6+
{
7+
public class CustomerData<T> : ILiteData
8+
{
9+
public int Id { get; set; }
10+
public string Key { get; set; }
11+
public T Data { get; set; }
12+
}
13+
}

GameFramework/Runtime/LiteDB/CustomerData.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace Wanderer.GameFramework
6+
{
7+
public interface ILiteData
8+
{
9+
public int Id { get; set; }
10+
}
11+
}

GameFramework/Runtime/LiteDB/ILiteData.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GameFramework/Runtime/LiteDB/LiteDBManager.cs

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.IO;
5+
using System.Text.RegularExpressions;
56
using UnityEngine;
67

78
namespace Wanderer.GameFramework
@@ -10,15 +11,13 @@ public class LiteDBManager : GameFrameworkModule
1011
{
1112
private Dictionary<string, LiteDBMapper> _litedbs = new Dictionary<string, LiteDBMapper>();
1213

13-
14-
public LiteDBMapper Select(string dbName)
14+
public LiteDBMapper Select(string dbPath)
1515
{
1616
LiteDBMapper mapper;
17-
if (!_litedbs.TryGetValue(dbName, out mapper))
17+
if (!_litedbs.TryGetValue(dbPath, out mapper))
1818
{
19-
string dbPath = Path.Combine(Application.persistentDataPath, $"{dbName}.litedb");
2019
mapper = new LiteDBMapper(dbPath);
21-
_litedbs.Add(dbName, mapper);
20+
_litedbs.Add(dbPath, mapper);
2221
}
2322
return mapper;
2423
}
@@ -76,6 +75,73 @@ public void Download(string key, string localPath)
7675
storage.Download(key, localPath,true);
7776
}
7877

78+
public void SetData<T>(T value) where T: ILiteData
79+
{
80+
var col = _db.GetCollection<T>(GetTableName<T>());
81+
var query = col.Query().Where(x => x.Id==value.Id);
82+
if (query.Count() > 0)
83+
{
84+
col.Update(value);
85+
}
86+
else
87+
{
88+
col.Insert(value);
89+
}
90+
}
91+
92+
public T GetData<T>(int id, T defaultValue = default(T)) where T : ILiteData
93+
{
94+
var col = _db.GetCollection<T>(GetTableName<T>());
95+
var value = col.Query().Where(x =>x.Id==id);
96+
if (value.Count() > 0)
97+
{
98+
return value.First();
99+
}
100+
101+
return defaultValue;
102+
}
103+
104+
public void SetCustomerData<T>(string key, T value)
105+
{
106+
var col = _db.GetCollection<CustomerData<T>>(GetTableName<T>());
107+
CustomerData<T> customerData;
108+
var query = col.Query().Where(x => x.Key.Equals(key));
109+
if (query.Count() > 0)
110+
{
111+
customerData = query.First();
112+
customerData.Data = value;
113+
col.Update(customerData);
114+
}
115+
else
116+
{
117+
customerData = new CustomerData<T>()
118+
{
119+
Key = key,
120+
Data = value
121+
};
122+
col.Insert(customerData);
123+
}
124+
}
125+
126+
public T GetCustomerData<T>(string key, T defaultValue = default(T))
127+
{
128+
var col = _db.GetCollection<CustomerData<T>>(GetTableName<T>());
129+
var value = col.Query().Where(x => x.Key.Equals(key));
130+
if (value.Count() > 0)
131+
{
132+
return value.First().Data;
133+
}
134+
135+
return defaultValue;
136+
}
137+
private string GetTableName<T>()
138+
{
139+
string tableName = Regex.Replace(typeof(T).Name, @"[^a-zA-Z0-9\u4e00-\u9fa5\s]", "");
140+
tableName = $"{tableName}";
141+
return tableName;
142+
}
143+
144+
79145
public void Dispose()
80146
{
81147
if (_db != null)

0 commit comments

Comments
 (0)