Skip to content

Commit c16e1fb

Browse files
author
ale
committed
配置改成json
1 parent b2b9137 commit c16e1fb

File tree

13 files changed

+132
-211
lines changed

13 files changed

+132
-211
lines changed

LuaProfiler/example/Assets/LuaProfiler/Common/Setting/LuaDeepProfilerAssetSetting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* ==============================================================================
3434
*/
3535

36-
#if UNITY_EDITOR_WIN || USE_LUA_PROFILER
36+
#if UNITY_EDITOR_WIN
3737
using UnityEngine;
3838
using UnityEditor;
3939

LuaProfiler/example/Assets/LuaProfiler/Common/Setting/LuaDeepProfilerSetting.cs

Lines changed: 96 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@
3333
* ==============================================================================
3434
*/
3535

36+
using System;
37+
using System.IO;
38+
3639
#if UNITY_EDITOR_WIN || USE_LUA_PROFILER
3740
namespace MikuLuaProfiler
3841
{
3942
using System.Collections.Generic;
40-
#if UNITY_EDITOR_WIN
41-
using UnityEditor;
42-
#endif
4343
using UnityEngine;
4444

45-
public class LuaDeepProfilerSetting : ScriptableObject
45+
[Serializable]
46+
public class LuaDeepProfilerSetting
4647
{
4748
#region instance
4849
private static LuaDeepProfilerSetting instance;
@@ -52,56 +53,51 @@ public static LuaDeepProfilerSetting Instance
5253
{
5354
if (instance == null)
5455
{
55-
instance = AssetDatabase.LoadAssetAtPath<LuaDeepProfilerSetting>("Assets/LuaDeepProfilerSetting.asset");
56-
if (instance == null)
57-
{
58-
UnityEngine.Debug.Log("Lua Profiler: cannot find integration settings, creating default settings");
59-
instance = CreateInstance<LuaDeepProfilerSetting>();
60-
instance.name = "Lua Profiler LuaDeepProfiler Setting";
61-
#if UNITY_EDITOR
62-
AssetDatabase.CreateAsset(instance, "Assets/LuaDeepProfilerSetting.asset");
63-
#endif
64-
}
56+
instance = new LuaDeepProfilerSetting();
6557
}
6658
return instance;
6759
}
6860
}
6961
#endregion
7062

71-
public bool isDeepMonoProfiler
72-
{
73-
get
74-
{
75-
return LuaDeepProfilerAssetSetting.Instance.isDeepMonoProfiler;
76-
}
77-
set
78-
{
79-
LuaDeepProfilerAssetSetting.Instance.isDeepMonoProfiler = value;
80-
}
81-
}
82-
8363
public bool isDeepLuaProfiler
8464
{
8565
get
8666
{
67+
#if UNITY_EDITOR
8768
return LuaDeepProfilerAssetSetting.Instance.isDeepLuaProfiler;
69+
#else
70+
return m_isDeepLuaProfiler;
71+
#endif
8872
}
8973
set
9074
{
75+
m_isDeepLuaProfiler = value;
76+
Save();
77+
#if UNITY_EDITOR
9178
LuaDeepProfilerAssetSetting.Instance.isDeepLuaProfiler = value;
79+
#endif
9280
}
9381
}
82+
9483
public bool isLocal
9584
{
9685
get
9786
{
87+
#if UNITY_EDITOR
9888
return LuaDeepProfilerAssetSetting.Instance.isLocal;
89+
#else
90+
return false;
91+
#endif
9992
}
10093
set
10194
{
95+
#if UNITY_EDITOR
10296
LuaDeepProfilerAssetSetting.Instance.isLocal = value;
97+
#endif
10398
}
10499
}
100+
105101
public bool isCleanMode
106102
{
107103
get
@@ -113,83 +109,11 @@ public bool isCleanMode
113109
if (this.m_isCleanMode != value)
114110
{
115111
this.m_isCleanMode = value;
116-
EditorUtility.SetDirty(this);
117-
}
118-
}
119-
}
120-
121-
public int captureLuaGC
122-
{
123-
get
124-
{
125-
return this.m_captureLuaGC;
126-
}
127-
set
128-
{
129-
if (this.m_captureLuaGC != value)
130-
{
131-
this.m_captureLuaGC = value;
132-
EditorUtility.SetDirty(this);
133-
}
134-
}
135-
}
136-
137-
public bool isNeedCapture
138-
{
139-
get
140-
{
141-
return this.m_isNeedCapture;
142-
}
143-
set
144-
{
145-
if (this.m_isNeedCapture != value)
146-
{
147-
this.m_isNeedCapture = value;
148-
EditorUtility.SetDirty(this);
149-
}
150-
}
151-
}
152-
153-
public string GetAssMD5ByPath(string path)
154-
{
155-
var index = m_assMd5Key.IndexOf(path);
156-
if (index < 0)
157-
{
158-
return "";
159-
}
160-
return m_assMd5[index];
161-
}
162-
163-
public void SetAssMD5ByPath(string path, string value)
164-
{
165-
var index = m_assMd5Key.IndexOf(path);
166-
if (index < 0)
167-
{
168-
m_assMd5Key.Add(path);
169-
m_assMd5.Add(value);
170-
}
171-
else
172-
{
173-
m_assMd5[index] = value;
174-
}
175-
EditorUtility.SetDirty(this);
176-
}
177-
178-
public bool isInited
179-
{
180-
get
181-
{
182-
return this.m_isInited;
183-
}
184-
set
185-
{
186-
if (this.m_isInited != value)
187-
{
188-
this.m_isInited = value;
189-
EditorUtility.SetDirty(this);
112+
Save();
190113
}
191114
}
192115
}
116+
193117

194118
public bool discardInvalid
195119
{
@@ -202,23 +126,7 @@ public bool discardInvalid
202126
if (m_discardInvalid != value)
203127
{
204128
m_discardInvalid = value;
205-
EditorUtility.SetDirty(this);
206-
}
207-
}
208-
}
209-
210-
public int captureMonoGC
211-
{
212-
get
213-
{
214-
return this.m_captureMonoGC;
215-
}
216-
set
217-
{
218-
if (this.m_captureMonoGC != value)
219-
{
220-
this.m_captureMonoGC = value;
221-
EditorUtility.SetDirty(this);
129+
Save();
222130
}
223131
}
224132
}
@@ -234,7 +142,7 @@ public int captureFrameRate
234142
if (this.m_captureFrameRate != value)
235143
{
236144
this.m_captureFrameRate = value;
237-
EditorUtility.SetDirty(this);
145+
Save();
238146
}
239147
}
240148
}
@@ -250,7 +158,7 @@ public string ip
250158
if (!(this.m_ip == value))
251159
{
252160
this.m_ip = value;
253-
EditorUtility.SetDirty(this);
161+
Save();
254162
}
255163
}
256164
}
@@ -266,7 +174,7 @@ public int port
266174
if (this.m_port != value)
267175
{
268176
this.m_port = value;
269-
EditorUtility.SetDirty(this);
177+
Save();
270178
}
271179
}
272180
}
@@ -281,7 +189,7 @@ public bool isRecord
281189
{
282190
if (m_isRecord == value) return;
283191
m_isRecord = value;
284-
EditorUtility.SetDirty(this);
192+
Save();
285193
}
286194
}
287195

@@ -295,7 +203,7 @@ public bool isStartRecord
295203
{
296204
if (m_isNeedRecord == value) return;
297205
m_isNeedRecord = value;
298-
EditorUtility.SetDirty(this);
206+
Save();
299207
}
300208
}
301209

@@ -309,7 +217,7 @@ public bool isFrameRecord
309217
{
310218
if (m_isFrameRecord == value) return;
311219
m_isFrameRecord = value;
312-
EditorUtility.SetDirty(this);
220+
Save();
313221
}
314222
}
315223

@@ -326,8 +234,7 @@ public void AddLuaDir(string path)
326234
if (!m_luaDir.Contains(path))
327235
{
328236
m_luaDir.Add(path);
329-
EditorUtility.SetDirty(this);
330-
AssetDatabase.SaveAssets();
237+
Save();
331238
}
332239
}
333240

@@ -341,22 +248,16 @@ public string luaIDE
341248
{
342249
if (m_luaIDE == value) return;
343250
m_luaIDE = value;
344-
EditorUtility.SetDirty(this);
345-
AssetDatabase.SaveAssets();
251+
Save();
346252
}
347253
}
348254

349255
public const string SettingsAssetName = "LuaDeepProfilerSettings";
350-
public bool m_isDeepMonoProfiler = false;
256+
public bool m_isNeedRecord = false;
351257
public bool m_isDeepLuaProfiler = false;
352258
public bool m_isCleanMode = false;
353-
public int m_captureLuaGC = 51200;
354-
public bool m_isNeedCapture = false;
355259
public bool m_discardInvalid = true;
356-
public List<string> m_assMd5Key = new List<string>();
357-
public List<string> m_assMd5 = new List<string>();
358-
public bool m_isInited = false;
359-
public int m_captureMonoGC = 51200;
260+
public bool m_isFrameRecord = false;
360261
public int m_captureFrameRate = 30;
361262
public string m_ip = "127.0.0.1";
362263
public int m_port = 2333;
@@ -366,8 +267,67 @@ public string luaIDE
366267
private List<string> m_luaDir = new List<string>();
367268
[SerializeField]
368269
private string m_luaIDE = "";
369-
private bool m_isNeedRecord = false;
370-
private bool m_isFrameRecord = true;
270+
271+
#if UNITY_EDITOR
272+
public void Save()
273+
{
274+
string path = null;
275+
var files = System.IO.Directory.GetFiles(Application.dataPath, "LuaDeepProfilerSetting.cs", System.IO.SearchOption.AllDirectories);
276+
if (files.Length > 0)
277+
{
278+
var f = files[0];
279+
f = f.Replace("\\", "/");
280+
var dirPath = f.Replace("LuaDeepProfilerSetting.cs", "Resources");
281+
if (!Directory.Exists(dirPath))
282+
{
283+
Directory.CreateDirectory(dirPath);
284+
}
285+
286+
path = f.Replace("LuaDeepProfilerSetting.cs", "Resources/LuaDeepProfilerSetting.txt");
287+
}
288+
else
289+
{
290+
throw new Exception("你改了我的文件名,自己想办法拯救吧");
291+
}
292+
293+
string v = JsonUtility.ToJson(this);
294+
File.WriteAllText(path, v);
295+
}
296+
#else
297+
public void Save()
298+
{}
299+
#endif
300+
public static LuaDeepProfilerSetting Load()
301+
{
302+
LuaDeepProfilerSetting result = null;
303+
var ta = Resources.Load<TextAsset>("LuaDeepProfilerSetting");
304+
if (ta == null)
305+
{
306+
result = new LuaDeepProfilerSetting();
307+
#if UNITY_EDITOR
308+
result.Save();
309+
#endif
310+
}
311+
else
312+
{
313+
string json = ta.text;
314+
Resources.UnloadAsset(ta);
315+
316+
try
317+
{
318+
JsonUtility.FromJson<LuaDeepProfilerSetting>(json);
319+
}
320+
catch
321+
{
322+
result = new LuaDeepProfilerSetting();
323+
#if UNITY_EDITOR
324+
result.Save();
325+
#endif
326+
}
327+
}
328+
return result;
329+
}
330+
371331
}
372332
}
373333
#endif

LuaProfiler/example/Assets/LuaProfiler/Common/Setting/LuaProfilerPrecompileSetting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* ==============================================================================
3434
*/
3535

36-
#if UNITY_EDITOR_WIN || USE_LUA_PROFILER
36+
#if UNITY_EDITOR_WIN
3737
namespace MikuLuaProfiler
3838
{
3939
using System;

LuaProfiler/example/Assets/LuaProfiler/Common/Setting/Resources.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"m_isNeedRecord":false,"m_isDeepLuaProfiler":true,"m_isCleanMode":false,"m_discardInvalid":true,"m_isFrameRecord":false,"m_captureFrameRate":30,"m_ip":"127.0.0.1","m_port":2333,"m_luaDir":[],"m_luaIDE":""}

0 commit comments

Comments
 (0)