Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 3f26df3

Browse files
author
zhangyang
committed
增加缓存信息
1 parent 8fd6d09 commit 3f26df3

File tree

8 files changed

+128
-34
lines changed

8 files changed

+128
-34
lines changed

Base/GameMode.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//-----------------------------------------------------------------------
1+
//-----------------------------------------------------------------------
22
// <copyright>
33
// Copyright (c) 2018 wanderer. All rights reserved.
44
// </copyright>
@@ -85,6 +85,7 @@ public JsonData ConfigJsonData
8585
IEnumerator Start()
8686
{
8787
GameMode.Self = this;
88+
8889
//默认不销毁
8990
DontDestroyOnLoad(gameObject);
9091

@@ -125,7 +126,6 @@ IEnumerator Start()
125126
#endregion
126127

127128
yield return new WaitForEndOfFrame();
128-
129129
}
130130

131131
private void Update()
@@ -158,5 +158,15 @@ private void OnApplicationFocus(bool focus)
158158
OnAppFocus?.Invoke(focus);
159159
}
160160

161+
public static long GetCacheSize()
162+
{
163+
return GameFrameworkMode.GetCacheSize();
164+
}
165+
166+
public static void ClearCache()
167+
{
168+
GameFrameworkMode.ClearCache();
169+
}
170+
161171
}
162172
}

GameFramework/Editor/FolderIcon/FolderIconExtensionEditor.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using UnityEditor;
@@ -25,64 +25,63 @@ private static void OnProjectWindowItemOnGUI(string guid, Rect selectionRect)
2525
if (!assetPath.StartsWith("Assets/Game"))
2626
return;
2727

28-
assetPath = assetPath.ToLower();
2928
bool isSmall = IsIconSmall(selectionRect);
3029
Rect iconRect = GetIconRect(selectionRect, isSmall);
3130
Rect addIconRect = GetAddIconRect(iconRect, isSmall);
3231
// Rect textRect = GetTextRect(selectionRect, isSmall);
33-
if (assetPath.StartsWith("assets/game/animation"))
32+
if (assetPath.StartsWith("assets/game/animation", StringComparison.CurrentCultureIgnoreCase))
3433
{
3534
DrawAddIcon(addIconRect, "animation");
3635
}
37-
else if (assetPath.StartsWith("assets/game/audio"))
36+
else if (assetPath.StartsWith("assets/game/audio", StringComparison.CurrentCultureIgnoreCase))
3837
{
3938
DrawAddIcon(addIconRect, "audio");
4039
}
41-
else if (assetPath.StartsWith("assets/game/datatable"))
40+
else if (assetPath.StartsWith("assets/game/datatable", StringComparison.CurrentCultureIgnoreCase))
4241
{
4342
DrawAddIcon(addIconRect, "excel");
4443
}
45-
else if (assetPath.StartsWith("assets/game/font"))
44+
else if (assetPath.StartsWith("assets/game/font", StringComparison.CurrentCultureIgnoreCase))
4645
{
4746
DrawAddIcon(addIconRect, "font");
4847
}
49-
else if (assetPath.StartsWith("assets/game/minigame"))
48+
else if (assetPath.StartsWith("assets/game/minigame", StringComparison.CurrentCultureIgnoreCase))
5049
{
5150
DrawAddIcon(addIconRect, "game");
5251
}
53-
else if (assetPath.StartsWith("assets/game/scene"))
52+
else if (assetPath.StartsWith("assets/game/scene", StringComparison.CurrentCultureIgnoreCase))
5453
{
5554
DrawAddIcon(addIconRect, "map");
5655
}
57-
else if (assetPath.StartsWith("assets/game/spine"))
56+
else if (assetPath.StartsWith("assets/game/spine", StringComparison.CurrentCultureIgnoreCase))
5857
{
5958
DrawAddIcon(addIconRect, "spine");
6059
}
61-
else if (assetPath.StartsWith("assets/game/texture"))
60+
else if (assetPath.StartsWith("assets/game/texture", StringComparison.CurrentCultureIgnoreCase))
6261
{
6362
DrawAddIcon(addIconRect, "picture");
6463
}
65-
else if (assetPath.StartsWith("assets/game/ui"))
64+
else if (assetPath.StartsWith("assets/game/ui", StringComparison.CurrentCultureIgnoreCase))
6665
{
6766
DrawAddIcon(addIconRect, "phone");
6867
}
69-
else if (assetPath.StartsWith("assets/game/xlua"))
68+
else if (assetPath.StartsWith("assets/game/xlua", StringComparison.CurrentCultureIgnoreCase))
7069
{
7170
DrawAddIcon(addIconRect, "lua");
7271
}
73-
else if (assetPath.StartsWith("assets/game/update"))
72+
else if (assetPath.StartsWith("assets/game/update", StringComparison.CurrentCultureIgnoreCase))
7473
{
7574
DrawAddIcon(addIconRect, "update_circle");
7675
}
77-
else if (assetPath.StartsWith("assets/game/scripts"))
76+
else if (assetPath.StartsWith("assets/game/scripts", StringComparison.CurrentCultureIgnoreCase))
7877
{
7978
DrawAddIcon(addIconRect, "script_01");
8079
}
81-
else if (assetPath.StartsWith("assets/game/shader"))
80+
else if (assetPath.StartsWith("assets/game/shader", StringComparison.CurrentCultureIgnoreCase))
8281
{
8382
GUI.DrawTexture(addIconRect, EditorGUIUtility.IconContent("d_ShaderVariantCollection Icon").image, ScaleMode.ScaleToFit);
8483
}
85-
else if (assetPath.StartsWith("assets/game/material"))
84+
else if (assetPath.StartsWith("assets/game/material", StringComparison.CurrentCultureIgnoreCase))
8685
{
8786
GUI.DrawTexture(addIconRect, EditorGUIUtility.IconContent("Material Icon").image, ScaleMode.ScaleToFit);
8887
}

GameFramework/Runtime/Base/GameFrameworkMode.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//-----------------------------------------------------------------------
1+
//-----------------------------------------------------------------------
22
// <copyright>
33
// Copyright (c) 2018 wanderer. All rights reserved.
44
// </copyright>
@@ -99,6 +99,31 @@ public static void ShutDown()
9999
_allGameModules.Clear();
100100
}
101101

102+
/// <summary>
103+
/// 获取缓存大小
104+
/// </summary>
105+
/// <returns>字节</returns>
106+
public static long GetCacheSize()
107+
{
108+
long size = 0;
109+
for (int i = 0; i < _allGameModules.Count; i++)
110+
{
111+
size+=_allGameModules[i].CacheSize();
112+
}
113+
return size;
114+
}
115+
116+
/// <summary>
117+
/// 清理缓存
118+
/// </summary>
119+
public static void ClearCache()
120+
{
121+
for (int i = 0; i < _allGameModules.Count; i++)
122+
{
123+
_allGameModules[i].ClearCache();
124+
}
125+
}
126+
102127
#endregion
103128

104129

GameFramework/Runtime/Base/GameFrameworkModule.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//-----------------------------------------------------------------------
1+
//-----------------------------------------------------------------------
22
// <copyright>
33
// Copyright (c) 2018 wanderer. All rights reserved.
44
// </copyright>
@@ -25,5 +25,19 @@ public virtual void OnInit()
2525
/// </summary>
2626
public abstract void OnClose();
2727

28+
/// <summary>
29+
/// 缓存大小 字节
30+
/// </summary>
31+
/// <returns></returns>
32+
public virtual long CacheSize()
33+
{
34+
return 0;
35+
}
36+
37+
/// <summary>
38+
/// 清理缓存
39+
/// </summary>
40+
public virtual void ClearCache()
41+
{ }
2842
}
2943
}

GameFramework/Runtime/Debugger/DebuggerManager.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using UnityEngine;
@@ -226,6 +226,16 @@ public void ResetLayout()
226226
FullRect = _defaultFullRect;
227227
}
228228

229+
public override long CacheSize()
230+
{
231+
return Log.GetLogFileSize();
232+
}
233+
234+
public override void ClearCache()
235+
{
236+
Log.DeleteLogFiles();
237+
}
238+
229239
#region 内部函数
230240
//绘制大窗口
231241
private void DrawDebuggerFullWindow(int windowId)

GameFramework/Runtime/Debugger/LogFile.cs

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.IO;
@@ -60,6 +60,7 @@ public void Start()
6060
{
6161
//监听UnityEngine.Debug
6262
Application.logMessageReceived += OnLogMessageReceived;
63+
6364
//检查日志文件所占的空间大小,如果太大还是需要自动删除
6465
//CheckLogFileSize();
6566
//创建文件流
@@ -123,7 +124,7 @@ public void Info(string message)
123124
{
124125
if (_useUnityLogger)
125126
{
126-
Debug.Log(message);
127+
Debug.Log($"<color=green>[Info]</color> {message}");
127128
}
128129
else
129130
{
@@ -139,7 +140,7 @@ public void Warning(string message)
139140
{
140141
if (_useUnityLogger)
141142
{
142-
Debug.LogWarning(message);
143+
Debug.LogWarning($"<color=yellow>[Warning]</color> {message}");
143144
}
144145
else
145146
{
@@ -155,7 +156,7 @@ public void Error(string message)
155156
{
156157
if (_useUnityLogger)
157158
{
158-
Debug.LogError(message);
159+
Debug.LogWarning($"<color=red>[Error]</color> {message}");
159160
}
160161
else
161162
{
@@ -167,7 +168,8 @@ public void Write(string message,LogType type)
167168
{
168169
if (_canWrite)
169170
{
170-
_logNodes.Enqueue(LogNodePool.Get(message, "", type));
171+
string stack = new System.Diagnostics.StackTrace().ToString();
172+
_logNodes.Enqueue(LogNodePool.Get(message, stack, type));
171173
}
172174
}
173175

@@ -257,17 +259,45 @@ private void WriteTask()
257259
}
258260
}
259261
}
260-
262+
261263
/// <summary>
262-
/// 检查日志文件大小
264+
/// 获取日志文件的大小
263265
/// </summary>
264-
private void CheckLogFileSize()
266+
/// <returns></returns>
267+
public long GetLogFileSize()
265268
{
266-
//string[] files = Directory.GetFiles(LogPath);
267-
//if (files != null && files.Length > 1)
268-
//{
269+
string todayLog = $"{DateTime.Now.ToString("yyyy-MM-dd")}.log";
269270

270-
//}
271+
long size = 0;
272+
string[] files = Directory.GetFiles(LogPath);
273+
if (files != null )
274+
{
275+
for (int i = 0; i < files.Length; i++)
276+
{
277+
if (files[i].EndsWith(todayLog))
278+
continue;
279+
size += File.ReadAllBytes(files[i]).Length;
280+
}
281+
}
282+
return size;
283+
}
284+
285+
/// <summary>
286+
/// 删除日志文件
287+
/// </summary>
288+
public void DeleteLogFiles()
289+
{
290+
string todayLog = $"{DateTime.Now.ToString("yyyy-MM-dd")}.log";
291+
string[] files = Directory.GetFiles(LogPath);
292+
if (files != null)
293+
{
294+
for (int i = 0; i < files.Length; i++)
295+
{
296+
if (files[i].EndsWith(todayLog))
297+
continue;
298+
File.Delete(files[i]);
299+
}
300+
}
271301
}
272302

273303
#endregion

GameFramework/Runtime/Resource/BundleAssetsHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//-----------------------------------------------------------------------
1+
//-----------------------------------------------------------------------
22
// <copyright>
33
// Copyright (c) 2018 wanderer. All rights reserved.
44
// </copyright>

Tests/Editor/FrameworkTestScript.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public void UtilityAESTestPasses()
2020
Log.Info($"解密后 {newdata}");
2121
}
2222

23+
//[Test]
24+
//public void CacheTestPasses()
25+
//{
26+
// Log.Info($"缓存大小: {GameFrameworkMode.GetCacheSize()}");
27+
//}
28+
2329
// A Test behaves as an ordinary method
2430
[Test]
2531
public void FrameworkTestScriptSimplePasses()

0 commit comments

Comments
 (0)