private int m_countChian; //链式加载堆栈计数,以免死循环 #endif public void LoadAsync(string assetId, Action <IBundleRef> callback) { var assetLowerId = assetId.ToLower(); var bundleId = BundlePathInfoHelepr.GetBundleId(assetLowerId); var loadState = GetLoadState(bundleId); switch (loadState) { case LoadState.NotLoad: OnNotLoad(); break; case LoadState.Loaded: OnLoaded(); break; case LoadState.Loading: OnLoading(); break; default: callback?.Invoke(null); throw new ArgumentOutOfRangeException(); } void OnNotLoad() { AsyncTask task = AsyncTask.Get(); task.SetCallback(callback); Callbcker.AddCallback(bundleId, task.MainLoadDown); var dependInfo = DependInfoHelper.GetDependInfo(bundleId); var dependIds = dependInfo.DirectDepends; if (dependIds.Count == 0) { Callbcker.AddCallback(bundleId, task.OneLoadDown); task.AddCount(); SetLoadState(bundleId, LoadState.Loading); WaitTasks.Enqueue(CreateMainTask(assetLowerId, bundleId)); } else { #if DEBUG m_countChian = 0; #endif PushChianTask(bundleId, dependInfo, task); } } void OnLoaded() { callback(Buffer.GetValue(bundleId)); Buffer.As <BundleBuffer>().IncreaseRef(bundleId); } void OnLoading() { Callbcker.AddCallback(bundleId, callback); } }