private static IEnumerator _DoLoadBundleAsync(string bundleName, System.Action <Object> callback) { #if UNITY_EDITOR && !USE_BUNDLE_IN_EDITOR callback(null); yield break; #else //Debug.LogFormat("[XLoader] AsyncLoading: ({0} : {1})", path, type.ToString()); if (string.IsNullOrEmpty(bundleName)) { Debug.LogErrorFormat("[XLoader.LoadBundle] sent empty/null name!"); yield break; } XManifest.Pack pack = XManifest.Instance.GetPack(bundleName); if (pack == null) { Debug.LogErrorFormat("[XLoader.LoadBundle] can not find bundle pack: [{0}]", bundleName); callback(null); yield break; } XManifest.Location local = pack.NoBundle() ? XManifest.Location.Resource : XManifest.Location.Bundle; switch (local) { case XManifest.Location.Bundle: { yield return(AssetBundleManager.Instance.LoadBundleAsync(bundleName, delegate(Object result) { })); } break; default: break; } callback(null); #endif }
private static IEnumerator _DoLoadAsync(string path, System.Type type, System.Action <Object> callback) { #if UNITY_EDITOR && !USE_BUNDLE_IN_EDITOR ResourceRequest request = Resources.LoadAsync(Path.ChangeExtension(path, null), type); yield return(request); Object obj = request.asset; if (obj == null) { obj = _LoadObjInEditorAt(path, type); } callback(obj); #else //Debug.LogFormat("[XLoader] AsyncLoading: ({0} : {1})", path, type.ToString()); if (string.IsNullOrEmpty(path)) { Debug.LogErrorFormat("[XLoader.Load] sent empty/null path!"); yield break; } string name = Path.ChangeExtension(path, null); XManifest.AssetInfo info = XManifest.Instance.Find(name); UnityEngine.Object obj = null; if (info != null) { switch (info.location) { case XManifest.Location.Resource: { ResourceRequest request = Resources.LoadAsync(name, type); yield return(request); obj = request.asset; } break; case XManifest.Location.Bundle: { yield return(AssetBundleManager.Instance.LoadAssetAsync(info, type, delegate(Object result) { obj = result; })); } break; default: break; } } else { string bundleName = XManifest.Instance.GetABNameByPath(name); if (!string.IsNullOrEmpty(bundleName)) { XManifest.Pack pack = XManifest.Instance.GetPack(bundleName); if (pack == null) { Debug.LogErrorFormat("[XLoader.LoadAsync] can not find bundle pack: [{0}] for res [{1}]", bundleName, name); callback(null); yield break; } XManifest.Location local = pack.NoBundle() ? XManifest.Location.Resource : XManifest.Location.Bundle; XManifest.AssetInfo assetInfo = new XManifest.AssetInfo() { location = local, bundle = pack.name, fullName = path }; switch (local) { case XManifest.Location.Resource: { ResourceRequest request = Resources.LoadAsync(name, type); yield return(request); obj = request.asset; } break; case XManifest.Location.Bundle: { yield return(AssetBundleManager.Instance.LoadAssetAsync(assetInfo, type, delegate(Object result) { obj = result; })); } break; default: break; } if (obj != null) { XManifest.Instance.AddFastIndex(path, assetInfo); } } else { ResourceRequest request = Resources.LoadAsync(name, type); yield return(request); obj = request.asset; } } if (obj == null) { if (info != null) { Debug.LogErrorFormat("[XLoader] Can't find {0} in Location({1})", name, info.location); } else { Debug.LogErrorFormat("[XLoader] Can't find {0} in Resources", name); } } callback(obj); #endif }
public static Object Load(string path, System.Type type) { Debug.LogFormat("[XLoader] Load: ({0} : {1})", path, type.ToString()); if (string.IsNullOrEmpty(path)) { Debug.LogErrorFormat("[XLoader.Load] sent empty/null path!"); return(null); } Object obj = null; #if UNITY_EDITOR obj = Resources.Load(Path.ChangeExtension(path, null), type); if (obj == null) { obj = _LoadObjInEditorAt(path, type); } if (obj != null) { return(obj); } //return obj; #endif //#else string name = Path.ChangeExtension(path, null); //UnityEngine.Object obj = null; //Debug.LogFormat("[XLoader] can't find Asset({0} : {1}) in cache: ", name, type.ToString()); XManifest.AssetInfo info = XManifest.Instance.Find(name); if (info != null) { switch (info.location) { case XManifest.Location.Resource: { obj = Resources.Load(name, type); } break; case XManifest.Location.Bundle: { obj = AssetBundleManager.Instance.LoadAsset(info, type); } break; default: break; } } else { string bundleName = XManifest.Instance.GetABNameByPath(name); if (!string.IsNullOrEmpty(bundleName)) { XManifest.Pack pack = XManifest.Instance.GetPack(bundleName); if (pack == null) { Debug.LogErrorFormat("[XLoader.Load] can not find bundle pack: [{0}] for res [{1}]", bundleName, name); return(null); } XManifest.Location local = pack.NoBundle() ? XManifest.Location.Resource : XManifest.Location.Bundle; XManifest.AssetInfo assetInfo = new XManifest.AssetInfo() { location = local, bundle = pack.name, fullName = path }; switch (local) { case XManifest.Location.Resource: { obj = Resources.Load(name, type); } break; case XManifest.Location.Bundle: { obj = AssetBundleManager.Instance.LoadAsset(assetInfo, type); } break; default: break; } if (obj != null) { XManifest.Instance.AddFastIndex(path, assetInfo); } } else { obj = Resources.Load(name, type); } } if (obj == null) { if (info != null) { Debug.LogErrorFormat("[XLoader] Can't find {0} in Location({1})", name, info.location); } else { Debug.LogErrorFormat("[XLoader] Can't find {0} in Resources", name); } } else { Debug.LogFormat("[XLoader] ({0} : {1}) Loaded.", name, type.ToString()); } return(obj); //#endif }