@@ -19,6 +19,9 @@ public class CheckResourceState : GameState
19
19
{
20
20
#region 属性
21
21
22
+ //资源信息文本名称
23
+ private string _assetVersionTxt = "AssetVersion.txt" ;
24
+
22
25
//本地版本信息
23
26
private AssetBundleVersionInfo _localVersion ;
24
27
@@ -74,9 +77,14 @@ public override void OnUpdate()
74
77
{
75
78
base . OnUpdate ( ) ;
76
79
77
- //更新资源--切换到加载界面
78
- if ( _resourceUpdateDone && _downloadResouces . Count == 0 )
80
+ //更新资源
81
+ if ( _resourceUpdateDone && _downloadResouces . Count == 0 )
82
+ {
83
+ //更新本地资源信息文本
84
+ UpdateAssetVersionTxt ( ) ;
85
+ // 切换到加载界面
79
86
ChangeState < LoadResourceState > ( ) ;
87
+ }
80
88
}
81
89
82
90
#endregion
@@ -90,6 +98,12 @@ private void OnHttpReadTextSuccess(object sender, IEventArgs e)
90
98
if ( ne != null )
91
99
{
92
100
_remoteVersion = JsonUtility . FromJson < AssetBundleVersionInfo > ( ne . Content ) ;
101
+ if ( _remoteVersion == null )
102
+ {
103
+ Debug . LogError ( "Remote Version is null" ) ;
104
+ return ;
105
+ }
106
+
93
107
//如果资源版本不一样 则更新资源
94
108
if ( ! CompareVersion ( ) )
95
109
{
@@ -139,7 +153,7 @@ private void OnDownloadProgress(object sender, IEventArgs e)
139
153
//加载本地版本信息
140
154
private AssetBundleVersionInfo LoadLocalVersion ( )
141
155
{
142
- string localPath = GameMode . Resource . LocalPath + "/AssetVersion.txt" ;
156
+ string localPath = Path . Combine ( GameMode . Resource . LocalPath , _assetVersionTxt ) ;
143
157
if ( ! File . Exists ( localPath ) )
144
158
return null ;
145
159
@@ -150,14 +164,14 @@ private AssetBundleVersionInfo LoadLocalVersion()
150
164
//加载远程版本信息
151
165
private void LoadRemoteVersion ( )
152
166
{
153
- string remotePath = GameMode . Resource . ResUpdatePath + "/AssetVersion.txt" ;
167
+ string remotePath = Path . Combine ( GameMode . Resource . ResUpdatePath , _assetVersionTxt ) ;
154
168
GameMode . WebRequest . ReadHttpText ( remotePath ) ;
155
169
}
156
170
157
171
//比较版本
158
172
private bool CompareVersion ( )
159
173
{
160
- return _remoteVersion . Version == _localVersion . Version ;
174
+ return _localVersion != null && _remoteVersion . Version == _localVersion . Version ;
161
175
}
162
176
163
177
//更新资源
@@ -192,6 +206,16 @@ private void DownloadResource()
192
206
}
193
207
}
194
208
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
+
195
219
#endregion
196
220
197
221
}
0 commit comments