public void Load() { if (IsFinished) { throw new Exception($"Repeat loading : {ABPath}"); } Status = AssetStatus.ASYNC_LOADING; if (m_dependencies != null) { foreach (var dependency in m_dependencies) { if (dependency.IsFinished || dependency.Status == AssetStatus.ASYNC_LOADING) { continue; } dependency.Load(); } } byte[] offsetData = System.Text.Encoding.UTF8.GetBytes(ABPath.GetHashCode().ToString()); var ab = AssetBundle.LoadFromFile(AssetBundleLoadProvider.DetermineLocation(ABPath), 0, (ulong)offsetData.Length); SetAssetBundle(ab); }
public void LoadAsync(Action callback) { if (IsFinished) { throw new Exception($"Repeat loading : {ABPath}"); } ulong flag = 0; bool selfLoaded = false; void FinishCheck() { if (flag == 0 && selfLoaded) { callback?.Invoke(); } } if (Status == AssetStatus.ASYNC_LOADING) { void Callback(AssetRefObject refObject) { if (!IsFinished) { return; } OnStatusChanged -= Callback; callback?.Invoke(); } OnStatusChanged += Callback; return; } Status = AssetStatus.ASYNC_LOADING; const ulong mask = 1; if (m_dependencies != null) { for (int i = 0; i < m_dependencies.Length; i++) { var index = i; var dependency = m_dependencies[i]; if (dependency.IsFinished) { continue; } flag |= mask << i; if (dependency.Status == AssetStatus.ASYNC_LOADING) { dependency.OnStatusChanged += _ => { if (dependency.IsFinished) { // ReSharper disable once AccessToModifiedClosure flag &= ~(mask << index); FinishCheck(); } }; } else { dependency.LoadAsync(() => { // ReSharper disable once AccessToModifiedClosure flag &= ~(mask << index); FinishCheck(); }); } } } byte[] offsetData = System.Text.Encoding.UTF8.GetBytes(ABPath.GetHashCode().ToString()); var req = AssetBundle.LoadFromFileAsync(AssetBundleLoadProvider.DetermineLocation(ABPath), 0, (ulong)offsetData.Length); req.completed += _ => { selfLoaded = true; SetAssetBundle(req.assetBundle); FinishCheck(); }; }