private static IEnumerator StartLoadCortine(IDictionary maps, ConfigValueType valueType, Action <float> onProcess, int maxAsyncReadCnt) { if (maps == null || maps.Count <= 0) { yield break; } int curCnt = 0; int idx = 0; if (valueType == ConfigValueType.cvObject) { var iter = maps.GetEnumerator(); while (iter.MoveNext()) { IConfigBase config = iter.Value as IConfigBase; if (!config.StreamSeek()) { continue; } config.ReadValue(); if (onProcess != null) { ++idx; float process = 0.5f + (float)idx / (float)maps.Count; onProcess(process); } ++curCnt; if (curCnt >= maxAsyncReadCnt) { curCnt = 0; InitEndFrame(); yield return(m_EndFrame); } } iter.DisposeIter(); } else if (valueType == ConfigValueType.cvList) { var iter = maps.GetEnumerator(); while (iter.MoveNext()) { IList vs = iter.Value as IList; IConfigBase v = vs [0] as IConfigBase; if (!v.StreamSeek()) { continue; } for (int i = 0; i < vs.Count; ++i) { v = vs[i] as IConfigBase; v.ReadValue(); ++curCnt; if (curCnt >= maxAsyncReadCnt) { curCnt = 0; InitEndFrame(); yield return(m_EndFrame); } } if (onProcess != null) { ++idx; float process = 0.5f + (float)idx / (float)maps.Count; onProcess(process); } } iter.DisposeIter(); } else if (valueType == ConfigValueType.cvMap) { // 字典类型 var iter = maps.GetEnumerator(); while (iter.MoveNext()) { IDictionary map = iter.Value as IDictionary; var subIter = map.GetEnumerator(); if (subIter.MoveNext()) { IConfigBase v = subIter.Value as IConfigBase; if (!v.StreamSeek()) { continue; } v.ReadValue(); while (subIter.MoveNext()) { v = subIter.Value as IConfigBase; v.ReadValue(); ++curCnt; if (curCnt >= maxAsyncReadCnt) { curCnt = 0; InitEndFrame(); yield return(m_EndFrame); } } } subIter.DisposeIter(); if (onProcess != null) { ++idx; float process = 0.5f + (float)idx / (float)maps.Count; onProcess(process); } } iter.DisposeIter(); } }
private static UnityEngine.Coroutine StartLoadAllCortine(IDictionary maps, UnityEngine.MonoBehaviour parent, ConfigValueType valueType, Action <float> onProcess, int maxAsyncReadCnt) { if (maps == null || maps.Count <= 0) { return(null); } if (parent != null) { return(parent.StartCoroutine(StartLoadCortine(maps, valueType, onProcess, maxAsyncReadCnt))); } else { if (valueType == ConfigValueType.cvObject) { var iter = maps.GetEnumerator(); while (iter.MoveNext()) { IConfigBase config = iter.Value as IConfigBase; Stream stream = config.stream; if (stream == null) { continue; } stream.Seek(config.dataOffset, SeekOrigin.Begin); config.ReadValue(); } iter.DisposeIter(); } else if (valueType == ConfigValueType.cvList) { var iter = maps.GetEnumerator(); while (iter.MoveNext()) { IList vs = iter.Value as IList; IConfigBase v = vs[0] as IConfigBase; Stream stream = v.stream; if (stream == null) { continue; } stream.Seek(v.dataOffset, SeekOrigin.Begin); for (int i = 0; i < vs.Count; ++i) { v = vs[i] as IConfigBase; v.ReadValue(); } } iter.DisposeIter(); } else if (valueType == ConfigValueType.cvMap) { // 字典类型 var iter = maps.GetEnumerator(); while (iter.MoveNext()) { IDictionary map = iter.Value as IDictionary; var subIter = map.GetEnumerator(); if (subIter.MoveNext()) { IConfigBase v = subIter.Value as IConfigBase; if (!v.StreamSeek()) { continue; } v.ReadValue(); while (subIter.MoveNext()) { v = subIter.Value as IConfigBase; v.ReadValue(); } } subIter.DisposeIter(); } iter.DisposeIter(); } } return(null); }