Skip to content

Commit 2e4e131

Browse files
author
DESKTOP-UBV38B7\codingworks
committed
更新资源后,更新本地资源信息文本文件
1 parent 80afcec commit 2e4e131

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

Assets/Game/Scripts/State/CheckResourceState.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class CheckResourceState : GameState
1919
{
2020
#region 属性
2121

22+
//资源信息文本名称
23+
private string _assetVersionTxt = "AssetVersion.txt";
24+
2225
//本地版本信息
2326
private AssetBundleVersionInfo _localVersion;
2427

@@ -74,9 +77,14 @@ public override void OnUpdate()
7477
{
7578
base.OnUpdate();
7679

77-
//更新资源--切换到加载界面
78-
if (_resourceUpdateDone&& _downloadResouces.Count==0)
80+
//更新资源
81+
if (_resourceUpdateDone && _downloadResouces.Count == 0)
82+
{
83+
//更新本地资源信息文本
84+
UpdateAssetVersionTxt();
85+
// 切换到加载界面
7986
ChangeState<LoadResourceState>();
87+
}
8088
}
8189

8290
#endregion
@@ -90,6 +98,12 @@ private void OnHttpReadTextSuccess(object sender, IEventArgs e)
9098
if (ne != null)
9199
{
92100
_remoteVersion = JsonUtility.FromJson<AssetBundleVersionInfo>(ne.Content);
101+
if (_remoteVersion == null)
102+
{
103+
Debug.LogError("Remote Version is null");
104+
return;
105+
}
106+
93107
//如果资源版本不一样 则更新资源
94108
if (!CompareVersion())
95109
{
@@ -139,7 +153,7 @@ private void OnDownloadProgress(object sender, IEventArgs e)
139153
//加载本地版本信息
140154
private AssetBundleVersionInfo LoadLocalVersion()
141155
{
142-
string localPath = GameMode.Resource.LocalPath + "/AssetVersion.txt";
156+
string localPath =Path.Combine(GameMode.Resource.LocalPath, _assetVersionTxt);
143157
if(!File.Exists(localPath))
144158
return null;
145159

@@ -150,14 +164,14 @@ private AssetBundleVersionInfo LoadLocalVersion()
150164
//加载远程版本信息
151165
private void LoadRemoteVersion()
152166
{
153-
string remotePath = GameMode.Resource.ResUpdatePath + "/AssetVersion.txt";
167+
string remotePath =Path.Combine(GameMode.Resource.ResUpdatePath, _assetVersionTxt);
154168
GameMode.WebRequest.ReadHttpText(remotePath);
155169
}
156170

157171
//比较版本
158172
private bool CompareVersion()
159173
{
160-
return _remoteVersion.Version == _localVersion.Version;
174+
return _localVersion!=null && _remoteVersion.Version == _localVersion.Version;
161175
}
162176

163177
//更新资源
@@ -192,6 +206,16 @@ private void DownloadResource()
192206
}
193207
}
194208

209+
//更新资源版本信息文本
210+
private void UpdateAssetVersionTxt()
211+
{
212+
if (!CompareVersion())
213+
{
214+
string localPath = Path.Combine(GameMode.Resource.LocalPath, _assetVersionTxt);
215+
File.WriteAllText(localPath, JsonUtility.ToJson(_remoteVersion));
216+
}
217+
}
218+
195219
#endregion
196220

197221
}

0 commit comments

Comments
 (0)