public static UGUIAtlas LoadResources(string atlasName) { string atlasPath = "Atlas/" + atlasName; UGUIAtlas atlas = null; ResUseMode useMode = ResourceManager.GetResourceUseMode(atlasPath); switch (useMode) { case ResUseMode.RESOURCE: atlas = Resources.Load <UGUIAtlas> (atlasPath); break; case ResUseMode.PERSIS_STATIC_RESOURCE: { AssetBundle ab = ResourceManager.Instance.staticAssetBundleManager.LoadAssetBundle(atlasPath + ".ab"); atlas = ab.LoadAsset <UGUIAtlas> (atlasName.ToLower()); ResourceManager.Instance.staticAssetBundleManager.UnLoadAssetBundle(atlasPath + ".ab"); } break; case ResUseMode.PERSIS_DYNAMIC_RESOURCE: { AssetBundle ab = ResourceManager.Instance.dynamicAssetBundleManager.LoadAssetBundle(atlasPath + ".ab"); atlas = ab.LoadAsset <UGUIAtlas> (atlasName.ToLower()); ResourceManager.Instance.staticAssetBundleManager.UnLoadAssetBundle(atlasPath + ".ab"); } break; } return(atlas); }
/// <summary> /// 直接获取资源,不会改动引用计数器 /// </summary> /// <param name="resourcePath"></param> /// <returns>资源</returns> public Object GetResource(string resourcePath) { ResUseMode mode = GetResourceUseMode(resourcePath); switch (mode) { case ResUseMode.RESOURCE: return(innerResoruceManager.GetResource(resourcePath)); case ResUseMode.PERSIS_STATIC_RESOURCE: { int lastSplitIndex = resourcePath.LastIndexOf('/'); string assetName = resourcePath.Substring(lastSplitIndex + 1); return(staticAssetBundleManager.GetAssetBundleAsset(resourcePath + ".ab", assetName)); } case ResUseMode.PERSIS_DYNAMIC_RESOURCE: { int lastSplitIndex = resourcePath.LastIndexOf('/'); string assetName = resourcePath.Substring(lastSplitIndex + 1); return(dynamicAssetBundleManager.GetAssetBundleAsset(resourcePath + ".ab", assetName)); } } return(null); }
/// <summary> /// 卸载资源, 引用计数为零将其从内存中清除 /// </summary> /// <param name="resourcePath">资源路径</param> public void UnloadResource(string resourcePath) { ResUseMode useMode = GetResourceUseMode(resourcePath); switch (useMode) { case ResUseMode.RESOURCE: innerResoruceManager.UnloadResource(resourcePath); break; case ResUseMode.PERSIS_STATIC_RESOURCE: { int lastSplitIndex = resourcePath.LastIndexOf('/'); string assetName = resourcePath.Substring(lastSplitIndex + 1); staticAssetBundleManager.UnLoadObject(resourcePath + ".ab", assetName); } break; case ResUseMode.PERSIS_DYNAMIC_RESOURCE: { int lastSplitIndex = resourcePath.LastIndexOf('/'); string assetName = resourcePath.Substring(lastSplitIndex + 1); dynamicAssetBundleManager.UnLoadObject(resourcePath + ".ab", assetName); } break; } }
private void LoadResourceAsync0(string resourcePath) { ResUseMode useMode = GetResourceUseMode(resourcePath); switch (useMode) { case ResUseMode.RESOURCE: this.innerResoruceManager.LoadAsync(resourcePath, (_resourcePath, _asset) => { HandlerAsyncCallBack(resourcePath, _asset); }); break; case ResUseMode.PERSIS_STATIC_RESOURCE: { int lastSplitIndex = resourcePath.LastIndexOf('/'); string assetName = resourcePath.Substring(lastSplitIndex + 1); this.staticAssetBundleManager.LoadObjectFormAssetBundleAsync(resourcePath + ".ab", assetName , (_filePath, _assetName, _asset) => { HandlerAsyncCallBack(resourcePath, _asset); }); } break; case ResUseMode.PERSIS_DYNAMIC_RESOURCE: { int lastSplitIndex = resourcePath.LastIndexOf('/'); string assetName = resourcePath.Substring(lastSplitIndex + 1); this.dynamicAssetBundleManager.LoadObjectFormAssetBundleAsync(resourcePath + ".ab", assetName , (_filePath, _assetName, _asset) => { HandlerAsyncCallBack(resourcePath, _asset); }); } break; } }
static int GetResourceUseMode(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); string arg0 = ToLua.CheckString(L, 1); ResUseMode o = ResourceManager.GetResourceUseMode(arg0); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public TexturePacker(string atlasName) { atlasPath = "Atlas/" + atlasName; Sprite[] sprites = null; ResUseMode useMode = ResourceManager.GetResourceUseMode(atlasPath); switch (useMode) { case ResUseMode.RESOURCE: sprites = Resources.LoadAll <Sprite> (atlasPath); break; case ResUseMode.PERSIS_STATIC_RESOURCE: { AssetBundle ab = ResourceManager.Instance.staticAssetBundleManager.LoadAssetBundle(atlasPath + ".ab"); sprites = ab.LoadAllAssets <Sprite> (); ResourceManager.Instance.staticAssetBundleManager.UnLoadAssetBundle(atlasPath + ".ab"); } break; case ResUseMode.PERSIS_DYNAMIC_RESOURCE: { AssetBundle ab = ResourceManager.Instance.dynamicAssetBundleManager.LoadAssetBundle(atlasPath + ".ab"); sprites = ab.LoadAllAssets <Sprite> (); ResourceManager.Instance.staticAssetBundleManager.UnLoadAssetBundle(atlasPath + ".ab"); } break; } if (sprites == null || sprites.Length == 0) { Debug.LogError("error atlasName:" + atlasPath); } else { InsertSprites(sprites[0].texture, sprites); } }
/// <summary> /// 阻塞加载资源,会增加引用计数器,注意:会阻塞主线程,谨慎使用!!! /// </summary> /// <param name="resourcePath">资源路径</param> /// <returns>加载得到的资源</returns> public Object LoadResourceBlock(string resourcePath) { Object asset = null; ResUseMode useMode = GetResourceUseMode(resourcePath); if (useMode == ResUseMode.RESOURCE) { asset = this.innerResoruceManager.Load(resourcePath); } else if (useMode == ResUseMode.PERSIS_DYNAMIC_RESOURCE) { int lastSplitIndex = resourcePath.LastIndexOf('/'); string assetName = resourcePath.Substring(lastSplitIndex + 1); asset = this.dynamicAssetBundleManager.LoadObjectFormAssetBundle(resourcePath + ".ab", assetName); } else { int lastSplitIndex = resourcePath.LastIndexOf('/'); string assetName = resourcePath.Substring(lastSplitIndex + 1); asset = this.staticAssetBundleManager.LoadObjectFormAssetBundle(resourcePath + ".ab", assetName); } return(asset); }