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

Commit 95de9a3

Browse files
committed
清理掉部分update里的foreach
1 parent a37343f commit 95de9a3

File tree

5 files changed

+57
-16
lines changed

5 files changed

+57
-16
lines changed

Assets/Game/Scripts/State/CheckResourceState.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// <describe> #检查资源状态# </describe>
66
// <email> [email protected] </email>
77
// <time> #2018年7月8日 13点20分# </time>
8+
//-----------------------------------------------------------------------
9+
810

911
using System;
1012
using System.Collections;
@@ -34,16 +36,19 @@ public class CheckResourceState : GameState
3436
private bool _resourceUpdateDone;
3537
//需要更新的资源
3638
private Dictionary<string, string> _downloadResouces;
37-
#endregion
39+
//余下的资源
40+
private List<string> _remainingResources;
41+
#endregion
3842

39-
#region 重写函数
43+
#region 重写函数
4044

41-
public override void OnInit()
45+
public override void OnInit()
4246
{
4347
base.OnInit();
4448

4549
_downloadResouces = new Dictionary<string, string>();
46-
}
50+
_remainingResources = new List<string>();
51+
}
4752

4853
public override void OnEnter(params object[] parameters)
4954
{
@@ -80,7 +85,7 @@ public override void OnUpdate()
8085
base.OnUpdate();
8186

8287
//更新资源
83-
if (_resourceUpdateDone && _downloadResouces.Count == 0)
88+
if (_resourceUpdateDone && _remainingResources.Count == 0)
8489
{
8590
//更新本地资源信息文本
8691
UpdateAssetVersionTxt();
@@ -147,9 +152,11 @@ private void OnHttpReadTextFaile(object sender, IEventArgs e)
147152
private void OnDownloadSuccess(object sender, IEventArgs e)
148153
{
149154
DownloadSuccessEventArgs ne = (DownloadSuccessEventArgs) e;
150-
if (_downloadResouces.ContainsKey(ne.RemoteUrl))
151-
_downloadResouces.Remove(ne.RemoteUrl);
152-
}
155+
if (_remainingResources.Contains(ne.RemoteUrl))
156+
_remainingResources.Remove(ne.RemoteUrl);
157+
//if (_downloadResouces.ContainsKey(ne.RemoteUrl))
158+
// _downloadResouces.Remove(ne.RemoteUrl);
159+
}
153160
//下载文件失败
154161
private void OnDownloadFaile(object sender, IEventArgs e)
155162
{
@@ -164,11 +171,9 @@ private void OnDownloadProgress(object sender, IEventArgs e)
164171
Debug.Log(
165172
$"path:{ne.LocalPath} progress:{ne.DownloadProgress} bytes:{ne.DownloadBytes} speed:{ne.DownloadSpeed}");
166173
}
167-
168174
#endregion
169175

170176
#region 内部函数
171-
172177
//加载本地版本信息
173178
private AssetBundleVersionInfo LoadLocalVersion()
174179
{
@@ -196,7 +201,8 @@ private bool CompareVersion()
196201
//更新资源
197202
private void UpdateResource()
198203
{
199-
foreach (var item in _remoteVersion.Resources)
204+
205+
foreach (var item in _remoteVersion.Resources)
200206
{
201207
//本地有响应文件则跳过
202208
if (_localVersion!=null&& _localVersion.Resources!=null&&_localVersion.Resources.Contains(item))
@@ -212,7 +218,9 @@ private void UpdateResource()
212218

213219
//添加需要下载的资源
214220
_downloadResouces.Add(remoteUrl, localPath);
215-
}
221+
222+
_remainingResources.Add(remoteUrl);
223+
}
216224

217225
}
218226

@@ -248,7 +256,6 @@ private string GetPlatformName()
248256
#endif
249257
return platformName.ToLower();
250258
}
251-
252259
#endregion
253260

254261
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//-----------------------------------------------------------------------
2+
// <copyright>
3+
// Copyright (c) 2018 Zhang Yang. All rights reserved.
4+
// </copyright>
5+
// <describe> #状态的相关事件# </describe>
6+
// <email> [email protected] </email>
7+
// <time> #2018年12月15日 16点47分# </time>
8+
//-----------------------------------------------------------------------
9+
10+
using System.Collections;
11+
using System.Collections.Generic;
12+
using UnityEngine;
13+
14+
namespace GameFramework.Taurus
15+
{
16+
public class StateEventArgs
17+
{
18+
}
19+
20+
21+
}

Assets/Game/Scripts/State/StateEventArgs.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/GameFramework/Base/GameFrameworkMode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public static class GameFrameworkMode
3939
/// </summary>
4040
public static void Update()
4141
{
42-
foreach (var item in _allUpdates)
43-
item.OnUpdate();
42+
for (int i = 0; i < _allUpdates.Count; i++)
43+
_allUpdates[i].OnUpdate();
4444
}
4545

4646
/// <summary>

Assets/GameFramework/UI/UIManager.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ private AssetConfig CheckAssetPath(Type t)
146146
if (string.IsNullOrEmpty(uIViewAttribute?.ViewPath) || string.IsNullOrEmpty(uIViewAttribute.AssetBundleName))
147147
return null;
148148
assetCofig = new AssetConfig(uIViewAttribute.AssetBundleName, uIViewAttribute.ViewPath);
149-
}
149+
150+
_uiAssetPath[hashCode] = assetCofig;
151+
}
150152
return assetCofig;
151153
}
152154

0 commit comments

Comments
 (0)