Skip to content

Commit 2d3a1ff

Browse files
author
wanderer
committed
修改WebRequest增加网络请求,以及文件下载功能,AssetBundle增加是否强制更新的功能,增加文件md5的异步验证,命令模式增加GameObject.SendMessage
1 parent 43f9718 commit 2d3a1ff

21 files changed

+701
-397
lines changed

Base/GameMode.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,6 @@ IEnumerator Start()
133133
// audioPlayer.AddComponent<AudioSource>());
134134
#endregion
135135

136-
#region WebRequest
137-
//设置帮助类
138-
GameObject webDownloadHelper = new GameObject("IWebDownloadMonoHelper");
139-
webDownloadHelper.transform.SetParent(transform);
140-
WebRequest.SetWebDownloadHelper(webDownloadHelper.AddComponent<WebDownloadMonoHelper>());
141-
#endregion
142-
143136
#region state
144137
//开启整个项目的流程
145138
Assembly = typeof(GameMode).Assembly;

GameFramework/Editor/AssetBundleEditor/AssetBundleBuildEditor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ private static void SaveAssetVersion(string buildPath, string targetName, BuildT
334334
{
335335
AssetHashInfo assetHashInfo = new AssetHashInfo();
336336
assetHashInfo.Name = assetNames[i];
337+
assetHashInfo.ForceUpdate = _config.UseAssetBundleEditor ? AssetBundleEditor.GetForceUpdate(assetHashInfo.Name) : true;
337338
string filePath = Path.Combine(buildPath, assetNames[i]);
338339
byte[] data = FileUtility.GetBytes(filePath);
339340
//加密

GameFramework/Editor/AssetBundleEditor/AssetBundleEditor.cs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class AssetBundleEditor : EditorWindow
4444
[MenuItem("Tools/Asset Bundle/Asset Bundle Editor")]
4545
private static void MainWindow()
4646
{
47-
GetWindowWithRect<AssetBundleEditor>(new Rect(100, 100, 900, 600), false, "Asset Bundle Editor");
47+
GetWindowWithRect<AssetBundleEditor>(new Rect(100, 100, 1000, 600), false, "Asset Bundle Editor");
4848
}
4949

5050

@@ -76,6 +76,36 @@ public static AssetBundleBuild[] GetAssetBundleBuild()
7676
return null;
7777
}
7878

79+
/// <summary>
80+
/// 设置是否强制更新
81+
/// </summary>
82+
/// <param name="name"></param>
83+
/// <returns></returns>
84+
public static bool GetForceUpdate(string name)
85+
{
86+
JsonData config = ProjectSettingsConfig.LoadJsonData(_configName);
87+
if (config != null || config.Count > 0)
88+
{
89+
for (int i = 0; i < config.Count; i++)
90+
{
91+
JsonData item = config[i];
92+
string abName = (string)item["AssetBundleName"];
93+
abName = abName.ToLower().Trim();
94+
if (name.Equals(abName) || name.Contains($"{abName}_part"))
95+
{
96+
string key = "ForceUpdate";
97+
if (item.ContainsKey(key))
98+
{
99+
bool forceUpdate = (bool)item[key];
100+
if (!forceUpdate)
101+
return false;
102+
}
103+
}
104+
}
105+
}
106+
return true;
107+
}
108+
79109
/// <summary>
80110
/// JsonData转AssetBundleBuild
81111
/// </summary>
@@ -219,6 +249,7 @@ private void OnGUI()
219249
GUILayout.Label("SearchInFolders",GUILayout.Width(300));
220250
GUILayout.Label("Split",GUILayout.Width(100));
221251
GUILayout.Label("SplitCount", GUILayout.Width(100));
252+
GUILayout.Label("ForceUpdate", GUILayout.Width(100));
222253
GUILayout.EndHorizontal();
223254
int configCount = _config.Count;
224255
if (configCount > 0)
@@ -383,11 +414,23 @@ private void DrawJsonData(JsonData jsonData)
383414
jsonData[key] = 1;
384415
}
385416
int splitCount =(int)jsonData[key];
386-
int newSplitCount = EditorGUILayout.IntField(splitCount, GUILayout.Width(70));
417+
int newSplitCount = EditorGUILayout.IntField(splitCount, GUILayout.Width(100));
387418
if (splitCount != newSplitCount)
388419
{
389420
jsonData[key] = newSplitCount;
390421
}
422+
423+
key = "ForceUpdate";
424+
if (!jsonData.Keys.Contains(key))
425+
{
426+
jsonData[key] = true;
427+
}
428+
bool forceUpdate = (bool)jsonData[key];
429+
bool newForceUpdate = EditorGUILayout.Toggle(forceUpdate, GUILayout.Width(70));
430+
if (forceUpdate != newForceUpdate)
431+
{
432+
jsonData[key] = newForceUpdate;
433+
}
391434
}
392435
}
393436

GameFramework/Editor/Other.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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEditor;
5+
using System.IO;
6+
7+
namespace Wanderer.GameFramework
8+
{
9+
public class BinaryToText:EditorWindow
10+
{
11+
private string _content;
12+
13+
[MenuItem("Tools/Other/Binary To Text")]
14+
static void OpenWindow()
15+
{
16+
GetWindow<BinaryToText>("Binary To Text");
17+
}
18+
19+
private void OnGUI()
20+
{
21+
if (GUILayout.Button("Open File"))
22+
{
23+
string file = EditorUtility.OpenFilePanel("open file",Path.GetDirectoryName( Application.dataPath),"*");
24+
if (!string.IsNullOrEmpty(file))
25+
{
26+
_content = File.ReadAllText(file).ToEncrypt();
27+
}
28+
}
29+
GUILayout.TextArea(_content,GUILayout.Height(Screen.height));
30+
}
31+
}
32+
}

GameFramework/Runtime/WebRequest/WebDownloadMonoHelper.cs.meta renamed to GameFramework/Editor/Other/BinaryToText.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GameFramework/Runtime/Config/AssetBundleVersionInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public class AssetHashInfo
6969
/// KB
7070
/// </summary>
7171
public int Size;
72+
/// <summary>
73+
/// 强制更新
74+
/// </summary>
75+
public bool ForceUpdate = true;
7276

7377
public override bool Equals(object obj)
7478
{

GameFramework/Runtime/Debugger/ConsoleWindow.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,18 @@ private void ExecuteCommand(string command)
222222
GameObject findGameObject = GameObject.Find(fullName);
223223
if (findGameObject != null)
224224
{
225-
findGameObject.SendMessage(methodName, args);
225+
if (args == null)
226+
{
227+
findGameObject.SendMessage(methodName);
228+
}
229+
else if (args.Length == 1)
230+
{
231+
findGameObject.SendMessage(methodName, args[0]);
232+
}
233+
else
234+
{
235+
findGameObject.SendMessage(methodName, args);
236+
}
226237
return;
227238
}
228239
}

GameFramework/Runtime/Debugger/DebuggerManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ internal class FPSCounter
262262

263263
public float FPS { get { return _fps; } }
264264

265+
265266
public FPSCounter()
266267
{
267268
_lastTime = Time.realtimeSinceStartup;

GameFramework/Runtime/Resource/ResourceManager.cs

Lines changed: 4 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,11 @@ public string LocalPath
9090
//远程更新的路径
9191
private string _remoteUpdatePath = null;
9292

93-
//平台的资源名称
94-
private string _assetPlatformVersionText = "AssetPlatformVersion.txt";
95-
96-
//资源信息文本名称
97-
private string _assetVersionTxt = "AssetVersion.txt";
98-
99-
/// <summary>
100-
/// 远程的版本信息
101-
/// </summary>
102-
/// <value></value>
103-
public AssetBundleVersionInfo RemoteVersion { get; private set; }
104-
10593
/// <summary>
106-
/// 本地的版本信息
94+
/// 资源的版本信息
10795
/// </summary>
10896
/// <value></value>
109-
public AssetBundleVersionInfo LocalVersion { get; private set; }
110-
97+
public ResourceVersion Version { get; private set; }
11198
#endregion
11299

113100
#region 构造函数
@@ -139,6 +126,8 @@ public override void OnInit()
139126
_remoteUpdatePath = ResOfficialUpdatePath;
140127
#endif
141128
_remoteUpdatePath = Path.Combine(_remoteUpdatePath, Utility.GetRuntimePlatformName());
129+
//资源版本
130+
Version = new ResourceVersion(_remoteUpdatePath,LocalPath);
142131
}
143132

144133

@@ -256,110 +245,6 @@ public void UnloadSceneAsync(string sceneName)
256245
return;
257246
}
258247

259-
/// <summary>
260-
/// 请求本地版本信息
261-
/// </summary>
262-
/// <param name="callback"></param>
263-
public void RequestLocalVersion(Action<AssetBundleVersionInfo> callback)
264-
{
265-
LocalVersion = null;
266-
string versionAssetPath = Path.Combine(LocalPath, _assetVersionTxt);
267-
268-
_webRequest.RequestText(versionAssetPath, (result, content) =>
269-
{
270-
if (result && !string.IsNullOrEmpty(content))
271-
{
272-
content = content.ToEncrypt();
273-
LocalVersion = JsonUtility.FromJson<AssetBundleVersionInfo>(content);
274-
}
275-
//本地可能就没有版本信息
276-
callback?.Invoke(null);
277-
// if (LocalVersion == null)
278-
// {
279-
// throw new GameException($"Can't transition local [AssetBundleVersionInfo]!! {versionAssetPath} {content}");
280-
// }
281-
});
282-
}
283-
284-
/// <summary>
285-
/// 请求本地版本信息
286-
/// </summary>
287-
/// <returns></returns>
288-
public Task<AssetBundleVersionInfo> RequestLocalVersion()
289-
{
290-
var resultTask = new TaskCompletionSource<AssetBundleVersionInfo>();
291-
RequestLocalVersion((abvi) =>
292-
{
293-
resultTask.SetResult(abvi);
294-
});
295-
return resultTask.Task;
296-
}
297-
298-
/// <summary>
299-
/// 请求远程版本信息
300-
/// </summary>
301-
/// <param name="callback"></param>
302-
public void RequestRemoteVersion(Action<AssetBundleVersionInfo> callback)
303-
{
304-
RemoteVersion = null;
305-
string versionAssetPath = Path.Combine(_remoteUpdatePath, _assetVersionTxt);
306-
_webRequest.RequestText(versionAssetPath, (result, content) =>
307-
{
308-
if (result && !string.IsNullOrEmpty(content))
309-
{
310-
content = content.ToEncrypt();
311-
RemoteVersion = JsonUtility.FromJson<AssetBundleVersionInfo>(content);
312-
}
313-
314-
if (RemoteVersion == null)
315-
{
316-
throw new GameException($"Can't transition remote [AssetBundleVersionInfo]!! {versionAssetPath} {content}");
317-
}
318-
319-
callback?.Invoke(RemoteVersion);
320-
});
321-
}
322-
323-
/// <summary>
324-
/// 请求远程版本信息
325-
/// </summary>
326-
/// <returns></returns>
327-
public Task<AssetBundleVersionInfo> RequestRemoteVersion()
328-
{
329-
var resultTask = new TaskCompletionSource<AssetBundleVersionInfo>();
330-
RequestRemoteVersion((abvi) =>
331-
{
332-
resultTask.SetResult(abvi);
333-
});
334-
return resultTask.Task;
335-
}
336-
337-
338-
/// <summary>
339-
/// 同时请求本地和远程的版本信息
340-
/// </summary>
341-
/// <param name="callback"></param>
342-
public async void RequestVersion(Action<AssetBundleVersionInfo, AssetBundleVersionInfo> callback)
343-
{
344-
await RequestLocalVersion();
345-
await RequestRemoteVersion();
346-
callback?.Invoke(LocalVersion, RemoteVersion);
347-
}
348-
349-
/// <summary>
350-
/// 同时请求本地和远程的版本信息
351-
/// </summary>
352-
/// <param name="callback"></param>
353-
public Task<AssetBundleVersionInfo[]> RequestVersion()
354-
{
355-
var resultTask = new TaskCompletionSource<AssetBundleVersionInfo[]>();
356-
RequestVersion((localABVI, remoteABVI) =>
357-
{
358-
resultTask.SetResult(new AssetBundleVersionInfo[] { localABVI, remoteABVI });
359-
});
360-
return resultTask.Task;
361-
}
362-
363248
/// <summary>
364249
/// 设置对象池管理器的
365250
/// </summary>

0 commit comments

Comments
 (0)