public static void LoadSpriteAsync(string spritePath, System.Action <Object> callback) { #if UNITY_EDITOR && !USE_BUNDLE_IN_EDITOR LoadAsync(spritePath, typeof(Sprite), callback); #else var type = typeof(UnityEngine.U2D.SpriteAtlas); string name = spritePath.ToLower(); XManifest.AssetInfo info = XManifest.Instance.Find(name); if (info != null) { LoadAsync(spritePath, type, callback); } else { var spritepack = XManifest.Instance.FindPackBySprite(spritePath); if (spritepack != null) { LoadAsync(spritepack.realName, type, (obj) => { callback((obj as UnityEngine.U2D.SpriteAtlas).GetSprite(Path.GetFileName(spritePath))); }); } else { Debug.LogErrorFormat("{0} can't find any where", spritePath); } } #endif }
public static byte[] Load(string fn) { #if !RELEASE //Debug.LogFormat("LuasLoader {0}", fn); #endif fn = fn.Replace(".", "/"); string bytefn = fn.Replace("/", "+"); string hashName = GHelper.Md5Sum(bytefn); #if !USE_BUNDLE_IN_EDITOR && (UNITY_EDITOR || UNITY_STANDALONE || !PUBLISH || ENABLE_GM) foreach (var path in Defines.LuaFileSearchPath) { byte[] buffer = LoadFrom(path, fn); string p = Path.Combine(path, fn + ".lua"); if (buffer != null) { FileInfo fi = new FileInfo(p); string lastWrite = fi.LastWriteTime.ToString(); fileMap.Add(fn); fileMapKey.Add(lastWrite + p); return(buffer); } } #endif XManifest.AssetInfo info = XManifest.Instance.Find(hashName); if (info != null) { if (info.location == XManifest.Location.Streaming) { return(ResHelper.LoadBytesFromStreamingAssets(System.IO.Path.Combine(streamBasePath, info.fullName))); } else { var filePath1 = System.IO.Path.Combine(dataBasePath, info.fullName); if (System.IO.File.Exists(filePath1)) { System.IO.FileStream fs = System.IO.File.OpenRead(filePath1); byte[] buffer = new byte[(int)fs.Length]; fs.Read(buffer, 0, (int)fs.Length); fs.Close(); return(buffer); } } } else { } return(null); }
private Object _DoLoadAsset(XManifest.AssetInfo info, System.Type type) { AssetBundleInfo bundleInfo = GetAssetBundleInfo(info.bundle); if (!bundleInfo.isDone) { _LoadAssetBundle(bundleInfo); } if (bundleInfo.bundle == null) { return(null); } bundleInfo.IncRef(Time.time); bundleInfo.DecRef(); return(bundleInfo.bundle.LoadAsset(System.IO.Path.Combine(Defines.AssetBundleSourcePath, info.fullName), type)); }
private IEnumerator _DoLoadAssetAsync(XManifest.AssetInfo info, System.Type type, System.Action <Object> callback) { AssetBundleInfo bundleInfo = GetAssetBundleInfo(info.bundle); if (!bundleInfo.isDone) { yield return(CoroutineHelper.Run(_LoadAssetBundleAsync(bundleInfo))); } if (bundleInfo.isDone) { bundleInfo.IncRef(Time.time); AssetBundleRequest request = null; request = bundleInfo.bundle.LoadAssetAsync(System.IO.Path.Combine(Defines.AssetBundleSourcePath, info.fullName), type); yield return(request); bundleInfo.DecRef(); callback(request.asset); } }
public Coroutine LoadAssetAsync(XManifest.AssetInfo info, System.Type type, System.Action <Object> callback) { return(CoroutineHelper.Run(_DoLoadAssetAsync(info, type, callback))); }
public Object LoadAsset(XManifest.AssetInfo info, System.Type type) { return(_DoLoadAsset(info, type)); }
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 }