Skip to content

Commit 4be5291

Browse files
committed
修改资源检查更新
1 parent b8894fb commit 4be5291

File tree

5 files changed

+96
-75
lines changed

5 files changed

+96
-75
lines changed

Assets/Game/Scripts/Editor/Module/ResourceModuleEditor.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,33 @@ namespace GameFramework.Taurus
1616
{
1717
public class ResourceModuleEditor : ModuleEditorBase
1818
{
19+
private BuildTargetGroup _lastBuildTargetGroup;
20+
private string _lastScriptingDefineSymbols;
21+
1922
public ResourceModuleEditor(string name, Color mainColor, GameMode gameMode)
2023
: base(name, mainColor, gameMode)
2124
{
22-
25+
//获取当前的BuildTargetGroup
26+
_lastBuildTargetGroup = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget);
27+
_lastScriptingDefineSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(_lastBuildTargetGroup);
2328
}
2429

2530
public override void OnDrawGUI()
2631
{
2732
GUILayout.BeginVertical("HelpBox");
2833

34+
GUILayout.BeginHorizontal("HelpBox");
35+
GUILayout.Label("Define",GUILayout.Width(50));
36+
string scriptingDefineSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(_lastBuildTargetGroup);
37+
_lastScriptingDefineSymbols = GUILayout.TextArea(_lastScriptingDefineSymbols);
38+
if (GUILayout.Button("OK",GUILayout.Width(40))&&!_lastScriptingDefineSymbols.Equals(scriptingDefineSymbols))
39+
{
40+
_lastBuildTargetGroup = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget);
41+
PlayerSettings.SetScriptingDefineSymbolsForGroup(_lastBuildTargetGroup, _lastScriptingDefineSymbols);
42+
}
43+
GUILayout.EndHorizontal();
44+
45+
2946
_gameMode.ResUpdateType =
3047
(ResourceUpdateType)EditorGUILayout.EnumPopup("Resource Update Type", _gameMode.ResUpdateType);
3148
if (_gameMode.ResUpdateType != ResourceUpdateType.Editor)

Assets/Game/Scripts/State/CheckResourceState.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private void OnHttpReadTextSuccess(object sender, IEventArgs e)
106106
{
107107
if (ne.Url == Path.Combine(GameMode.Resource.ResUpdatePath, _assetPlatformVersionText))
108108
{
109-
AssetPlatformVersionInfo assetPlatform= JsonUtility.FromJson<AssetPlatformVersionInfo>(ne.Content);
109+
PlatformVersionInfo assetPlatform= JsonUtility.FromJson<PlatformVersionInfo>(ne.Content);
110110
string platformName = GetPlatformName();
111111
if (assetPlatform.Platforms.Contains(platformName))
112112
{
@@ -202,10 +202,10 @@ private bool CompareVersion()
202202
private void UpdateResource()
203203
{
204204

205-
foreach (var item in _remoteVersion.Resources)
205+
foreach (var item in _remoteVersion.AssetHashInfos)
206206
{
207207
//本地有响应文件则跳过
208-
if (_localVersion!=null&& _localVersion.Resources!=null&&_localVersion.Resources.Contains(item))
208+
if (_localVersion!=null&& _localVersion.AssetHashInfos!=null&&_localVersion.AssetHashInfos.Contains(item))
209209
continue;
210210
string remoteUrl = Path.Combine(GameMode.Resource.ResUpdatePath, item.Name);
211211
//获取本地文件的路径

Assets/GameFramework/Config/AssetBundleVersionInfo.cs

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,47 @@
99

1010
using System;
1111
using System.Collections.Generic;
12-
13-
[Serializable]
14-
public class AssetPlatformVersionInfo
15-
{
16-
public int Version;
17-
public List<string> Platforms;
18-
}
19-
20-
[Serializable]
21-
public class AssetBundleVersionInfo
22-
{
23-
public int Version;
24-
public bool IsEncrypt;
25-
public string ManifestAssetBundle;
26-
public List<ResourcesInfo> Resources;
27-
}
28-
29-
[Serializable]
30-
public class ResourcesInfo
12+
namespace GameFramework.Taurus
3113
{
32-
public string Name;
33-
public string MD5;
34-
35-
public override bool Equals(object obj)
36-
{
37-
ResourcesInfo other = obj as ResourcesInfo;
38-
if (other.Name.Equals(Name) && other.MD5.Equals(MD5))
39-
return true;
40-
41-
return false;
42-
}
43-
44-
public override int GetHashCode()
45-
{
46-
return (Name + MD5).GetHashCode();
47-
}
48-
49-
}
14+
15+
//平台资源信息
16+
[System.Serializable]
17+
public class PlatformVersionInfo
18+
{
19+
public int Version;
20+
public List<string> Platforms=new List<string>();
21+
}
22+
23+
//资源版本信息
24+
[System.Serializable]
25+
public class AssetBundleVersionInfo
26+
{
27+
public int Version=0;
28+
public bool IsEncrypt=false;
29+
public string ManifestAssetBundle;
30+
public List<AssetHashInfo> AssetHashInfos=new List<AssetHashInfo>();
31+
}
32+
33+
//资源hash值
34+
[System.Serializable]
35+
public class AssetHashInfo
36+
{
37+
public string Name;
38+
public string Hash;
39+
40+
public override bool Equals(object obj)
41+
{
42+
AssetHashInfo other = obj as AssetHashInfo;
43+
if (other.Name.Equals(Name) && other.Hash.Equals(Hash))
44+
return true;
45+
46+
return false;
47+
}
48+
49+
public override int GetHashCode()
50+
{
51+
return (Name + Hash).GetHashCode();
52+
}
53+
54+
}
55+
}

Assets/GameFramework/Editor/AssetBundleEditor/AssetBundleBuildEditor.cs

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
using System.IO;
66
using System;
77

8+
namespace GameFramework.Taurus
9+
{
10+
811
public class AssetBundleBuildEditor :EditorWindow {
912

10-
private static string _configPath="ProjectSettings/AssetBundleEditorConifg.json";
13+
//资源信息文本名称
14+
private const string _assetVersionTxt = "AssetVersion.txt";
15+
private const string _configPath="ProjectSettings/AssetBundleEditorConifg.json";
1116
private static AssetBundleConifgInfo _config;
1217
private static List<string> _buildTargets;
1318
private static string _outPutPath="";
@@ -183,29 +188,46 @@ private static void BuildTarget(BuildTarget target,BuildAssetBundleOptions optio
183188
//保存资源版本信息
184189
private static void SaveAssetVersion(string buildPath,BuildTarget target)
185190
{
186-
AssetVersionInfo assetVersionInfo=new AssetVersionInfo();
191+
string targetBundlePath=Path.Combine(buildPath,target.ToString());
192+
if(!File.Exists(targetBundlePath))
193+
return;
194+
195+
AssetBundleVersionInfo assetVersionInfo=new AssetBundleVersionInfo();
187196
assetVersionInfo.Version=_config.Version;
197+
assetVersionInfo.ManifestAssetBundle=target.ToString();
188198
assetVersionInfo.AssetHashInfos=new List<AssetHashInfo>();
189199

190-
AssetBundle targetBundle=AssetBundle.LoadFromFile(Path.Combine(buildPath,target.ToString()));
200+
AssetBundle targetBundle=AssetBundle.LoadFromFile(targetBundlePath);
191201
AssetBundleManifest manifest=targetBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
192-
string[] assetNames=manifest.GetAllAssetBundles();
193-
for (int i = 0; i < assetNames.Length; i++)
202+
List<string> assetNames=new List<string>();
203+
assetNames.Add(target.ToString());
204+
assetNames.AddRange(manifest.GetAllAssetBundles());
205+
for (int i = 0; i < assetNames.Count; i++)
194206
{
195207
AssetHashInfo assetHashInfo=new AssetHashInfo();
196208
assetHashInfo.Name=assetNames[i];
197-
assetHashInfo.Hash=manifest.GetAssetBundleHash(assetNames[i]).ToString();
209+
//AssetBundleManifest的hashcode 获取一直为00000000000000000000000000000000 于是用版本号代替
210+
assetHashInfo.Hash=i==0?_config.Version.ToString():manifest.GetAssetBundleHash(assetNames[i]).ToString();
198211
assetVersionInfo.AssetHashInfos.Add(assetHashInfo);
212+
//删除manifest文件
213+
string manifestPath=Path.Combine(buildPath,assetNames[i],".manifeset");
214+
if(File.Exists(manifestPath))
215+
{
216+
File.Delete(manifestPath);
217+
}
199218
}
200219

201220
string json=JsonUtility.ToJson(assetVersionInfo);
202-
File.WriteAllText(Path.Combine(buildPath,"version.txt"),json);
221+
File.WriteAllText(Path.Combine(buildPath,_assetVersionTxt),json);
203222
targetBundle.Unload(true);
204223
}
205224

206225
//保存平台版本信息
207226
private static void SavePlatformVersion(List<BuildTarget> targets)
208227
{
228+
if(targets==null||targets.Count==0)
229+
return;
230+
209231
PlatformVersionInfo platformInfo=new PlatformVersionInfo();
210232
platformInfo.Version=_config.Version;
211233
platformInfo.Platforms=new List<string>();
@@ -215,7 +237,7 @@ private static void SavePlatformVersion(List<BuildTarget> targets)
215237
}
216238
string json=JsonUtility.ToJson(platformInfo);
217239
//保存平台信息
218-
File.WriteAllText(Path.Combine(_config.BuildPath,"version.txt"),json);
240+
File.WriteAllText(Path.Combine(_config.BuildPath,_assetVersionTxt),json);
219241
//更新资源版本号 -- 保存配置文件
220242
_config.Version++;
221243
SaveConfig();
@@ -232,30 +254,6 @@ public class AssetBundleConifgInfo
232254
public List<int> BuildTargets=new List<int>();
233255

234256
}
235-
236-
//平台资源信息
237-
[System.Serializable]
238-
public class PlatformVersionInfo
239-
{
240-
public int Version;
241-
public List<string> Platforms=new List<string>();
242-
}
243-
244-
//资源版本信息
245-
[System.Serializable]
246-
public class AssetVersionInfo
247-
{
248-
public int Version=0;
249-
public List<AssetHashInfo> AssetHashInfos=new List<AssetHashInfo>();
250-
}
251257

252-
//资源hash值
253-
[System.Serializable]
254-
public class AssetHashInfo
255-
{
256-
public string Name;
257-
public string Hash;
258258
}
259-
260-
261-
}
259+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"Version":4,"BuildPath":"Assets","BuildTargets":[24]}
1+
{"Version":0,"BuildPath":"","BuildTargets":[]}

0 commit comments

Comments
 (0)