/// <summary> /// 加载全部包资源 /// </summary> /// <param name="assetId"></param> /// <param name="loadHandler"></param> void ISource.Load(int assetId, DataHandler <UnityEngine.Object[]> loadHandler, EVariantType variant, bool toAsync) { int guid = assetId * Const.variantMaxLength + (int)variant; var chainId = m_variantChains[guid]; int[] chain = m_dependenciesChain[chainId]; if (chain.Length == 1) { int dep = chain[0] / Const.dependLayerDigit; int layer = chain[0] % Const.dependLayerDigit; if (usedSources.ContainsKey(dep)) { if (loadHandler != null) { loadHandler(usedSources[dep].allAssets); } usedSources[dep].dependencieds.Add(guid); } else if (m_waitLoadSourcesIndex.ContainsKey(dep)) { waitLoadSources[dep].AddCompleteHandler(loadHandler); waitLoadSources[dep].dependencieds.Add(guid); } else if (loadingSources.ContainsKey(dep)) { loadingSources[dep].AddCompleteHandler(loadHandler); loadingSources[dep].dependencieds.Add(guid); } else { string assetPath = null; if (m_guidPaths.TryGetValue(dep, out assetPath)) { assetPath = m_guidPaths[dep]; } else { UnityEngine.Debug.LogError("Dont has this assetId: " + dep); loadHandler(null); return; } m_waitLoadSourcesIndex.Add(dep, layer); SourceData d = new SourceData(); d.guid = dep; d.toAsync = toAsync; d.assetPath = assetPath; d.state = ESourceState.WaitLoad; d.AddCompleteHandler(loadHandler); d.dependencieds.Add(guid); waitLoadSources.Add(dep, d); } } else { int maxWaitInsertIndex = 0; for (int i = 0; i < chain.Length; i++) { var lDep = chain[i]; int dep = lDep / Const.dependLayerDigit; int layer = lDep % Const.dependLayerDigit; if (m_waitLoadSourcesIndex.ContainsKey(dep)) { int index = m_waitLoadSourcesIndex[dep]; maxWaitInsertIndex = maxWaitInsertIndex < index ? index : maxWaitInsertIndex; } } for (int i = 0; i < chain.Length; i++) { var lDep = chain[i]; int dep = lDep / Const.dependLayerDigit; int layer = lDep % Const.dependLayerDigit; if (usedSources.ContainsKey(dep)) { if (loadHandler != null) { loadHandler(usedSources[dep].allAssets); } usedSources[dep].dependencieds.Add(guid); } else if (m_waitLoadSourcesIndex.ContainsKey(dep)) { if (i == chain.Length - 1) { waitLoadSources[dep].AddCompleteHandler(loadHandler); waitLoadSources[dep].dependencieds.Add(guid); } } else if (loadingSources.ContainsKey(dep)) { if (i == chain.Length - 1) { loadingSources[dep].AddCompleteHandler(loadHandler); loadingSources[dep].dependencieds.Add(guid); } else { } } else { string assetPath = null; if (m_guidPaths.TryGetValue(dep, out assetPath)) { assetPath = m_guidPaths[dep]; } else { UnityEngine.Debug.LogError("Dont has this assetId: " + dep); return; } m_waitLoadSourcesIndex.Add(dep, maxWaitInsertIndex + layer); SourceData d = new SourceData(); d.guid = dep; d.toAsync = toAsync; d.assetPath = assetPath; d.state = ESourceState.WaitLoad; if (i == chain.Length - 1) { d.AddCompleteHandler(loadHandler); } d.dependencieds.Add(guid); waitLoadSources.Add(dep, d); } } } if (loadEventHandler != null) { loadEventHandler(guid); } }
UnityEngine.Object ISource.Load(int assetId, string name, EVariantType variant) { int guid = assetId * Const.variantMaxLength + (int)variant; var chainId = m_variantChains[guid]; int[] chain = m_dependenciesChain[chainId]; if (chain.Length == 1) { int dep = chain[0] / Const.dependLayerDigit; int layer = chain[0] % Const.dependLayerDigit; if (usedSources.ContainsKey(dep)) { usedSources[dep].dependencieds.Add(guid); if (loadEventHandler != null) { loadEventHandler(guid); } return(usedSources[dep].LoadAsset(name)); } else if (m_waitLoadSourcesIndex.ContainsKey(dep)) { UnityEngine.Debug.LogError("assetId is waitLoadSources: " + guid); return(null); } else if (loadingSources.ContainsKey(dep)) { UnityEngine.Debug.LogError("assetId is loadingSources: " + guid); return(null); } else { string assetPath = null; if (m_guidPaths.TryGetValue(dep, out assetPath)) { assetPath = m_guidPaths[dep]; } else { UnityEngine.Debug.LogError("Dont has this assetId: " + dep); return(null); } SourceData d = new SourceData(); d.guid = dep; d.toAsync = false; d.assetPath = assetPath; d.state = ESourceState.WaitLoad; d.dependencieds.Add(guid); d.LoadAllAsset(); usedSources[dep].dependencieds.Add(guid); if (loadEventHandler != null) { loadEventHandler(guid); } return(d.LoadAsset(name)); } } else { SourceData d = null; for (int i = 0; i < chain.Length; i++) { var lDep = chain[i]; int dep = lDep / Const.dependLayerDigit; int layer = lDep % Const.dependLayerDigit; if (usedSources.ContainsKey(dep)) { usedSources[dep].dependencieds.Add(guid); return(usedSources[dep].LoadAsset(name)); } else if (m_waitLoadSourcesIndex.ContainsKey(dep)) { if (i == chain.Length - 1) { UnityEngine.Debug.LogError("assetId is m_waitLoadSourcesIndex: " + guid); } } else if (loadingSources.ContainsKey(dep)) { if (i == chain.Length - 1) { UnityEngine.Debug.LogError("assetId is loadingSources: " + guid); } else { } } else { string assetPath = null; if (m_guidPaths.TryGetValue(dep, out assetPath)) { assetPath = m_guidPaths[dep]; } else { UnityEngine.Debug.LogError("Dont has this assetId: " + dep); return(null); } d = new SourceData(); d.guid = dep; d.toAsync = false; d.assetPath = assetPath; d.state = ESourceState.WaitLoad; d.dependencieds.Add(guid); d.LoadAllAsset(); usedSources[dep].dependencieds.Add(guid); } } if (loadEventHandler != null) { loadEventHandler(guid); } return(d.LoadAsset(name)); } }
public void LoadAll(int count, bool toAsync) { DataHandler <UnityEngine.Object> loadHandler = (o) => { //cou++; UnityEngine.Debug.Log(o.name); }; int a = 0; foreach (var item in m_guidPaths) { if (a > count) { return; } a++; int guid = item.Key; if (guid % Const.variantMaxLength != 0) { continue; } var chainId = m_variantChains[guid]; int[] chain = m_dependenciesChain[chainId]; if (chain.Length == 1) { int dep = chain[0] / Const.dependLayerDigit; int layer = chain[0] % Const.dependLayerDigit; if (usedSources.ContainsKey(dep)) { if (loadHandler != null) { loadHandler(usedSources[dep].mainAsset); } usedSources[dep].dependencieds.Add(guid); } else if (m_waitLoadSourcesIndex.ContainsKey(dep)) { waitLoadSources[dep].AddCompleteHandler(loadHandler); waitLoadSources[dep].dependencieds.Add(guid); } else if (loadingSources.ContainsKey(dep)) { loadingSources[dep].AddCompleteHandler(loadHandler); loadingSources[dep].dependencieds.Add(guid); } else { string assetPath = null; #if UNITY_EDITOR if (m_guidPaths.ContainsKey(dep)) { assetPath = m_guidPaths[dep]; } else { UnityEngine.Debug.LogError("Dont has this assetId: " + dep); return; } #else assetPath = m_guidPath[dep]; #endif m_waitLoadSourcesIndex.Add(dep, layer); SourceData d = new SourceData(); d.guid = dep; d.assetPath = assetPath; d.toAsync = toAsync; d.state = ESourceState.WaitLoad; d.AddCompleteHandler(loadHandler); d.dependencieds.Add(guid); waitLoadSources.Add(dep, d); } } else { int maxWaitInsertIndex = 0; for (int i = 0; i < chain.Length; i++) { var lDep = chain[i]; int dep = lDep / Const.dependLayerDigit; int layer = lDep % Const.dependLayerDigit; if (m_waitLoadSourcesIndex.ContainsKey(dep)) { int index = m_waitLoadSourcesIndex[dep]; maxWaitInsertIndex = maxWaitInsertIndex < index ? index : maxWaitInsertIndex; } } for (int i = 0; i < chain.Length; i++) { var lDep = chain[i]; int dep = lDep / Const.dependLayerDigit; int layer = lDep % Const.dependLayerDigit; if (usedSources.ContainsKey(dep)) { if (loadHandler != null) { loadHandler(usedSources[dep].mainAsset); } usedSources[dep].dependencieds.Add(guid); } else if (m_waitLoadSourcesIndex.ContainsKey(dep)) { if (i == chain.Length - 1) { waitLoadSources[dep].AddCompleteHandler(loadHandler); waitLoadSources[dep].dependencieds.Add(guid); } } else if (loadingSources.ContainsKey(dep)) { if (i == chain.Length - 1) { loadingSources[dep].AddCompleteHandler(loadHandler); loadingSources[dep].dependencieds.Add(guid); } else { } } else { string assetPath = null; #if UNITY_EDITOR if (m_guidPaths.ContainsKey(dep)) { assetPath = m_guidPaths[dep]; } else { UnityEngine.Debug.LogError("Dont has this assetId: " + dep); return; } #else assetPath = m_guidPath[dep]; #endif m_waitLoadSourcesIndex.Add(dep, maxWaitInsertIndex + layer); SourceData d = new SourceData(); d.guid = dep; d.assetPath = assetPath; d.toAsync = toAsync; d.state = ESourceState.WaitLoad; if (i == chain.Length - 1) { d.AddCompleteHandler(loadHandler); } d.dependencieds.Add(guid); waitLoadSources.Add(dep, d); } } } if (loadEventHandler != null) { loadEventHandler(guid); } } }