示例#1
0
    private void LoadCompleteCallBack(string abName)
    {
        LogHelperLSK.LogError("加载完成: " + abName);

        GameObject temp = AssetBundleMgr.Instance.LoadAsset(m_sceneName, m_abName, m_assetName, false) as GameObject;
        GameObject obj  = GameObject.Instantiate(temp);

        obj.transform.SetParent(this.transform);
    }
示例#2
0
 /// <summary>
 /// 释放单个资源
 /// </summary>
 /// <param name="sceneName">场景名</param>
 /// <param name="abName">ab包名</param>
 /// <param name="resName">资源名</param>
 public void DisposeResObj(string sceneName, string abName, string resName)
 {
     if (m_allScenes.ContainsKey(sceneName))
     {
         m_allScenes[sceneName].DisposeResObj(abName, resName);
     }
     else
     {
         LogHelperLSK.LogError("DisposeResObj 出错,不存在sceneName: " + sceneName);
     }
 }
示例#3
0
 /// <summary>
 /// 释放某个资源
 /// </summary>
 /// <param name="resName"></param>
 public void DisposeResObj(string resName)
 {
     if (m_asetLoader != null)
     {
         m_asetLoader.DisposeResObj(resName);
     }
     else
     {
         LogHelperLSK.LogError("释放资源出错(DisposeResObj) m_assetLoader is null ");
     }
 }
示例#4
0
 /// <summary>
 /// /释放资源
 /// </summary>
 public void Dispose()
 {
     if (m_asetLoader != null)
     {
         m_asetLoader.Dispose();
     }
     else
     {
         LogHelperLSK.LogError("释放资源出错(Dispose) m_assetLoader is null ");
     }
 }
示例#5
0
 /// <summary>
 /// 释放某个场景种的所有ab包
 /// </summary>
 /// <param name="sceneName"></param>
 public void DisposeAllBundleByScene(string sceneName)
 {
     if (m_allScenes.ContainsKey(sceneName))
     {
         m_allScenes[sceneName].DisposeAllBundle();
     }
     else
     {
         LogHelperLSK.LogError("加载资源出错,不存在sceneName: " + sceneName);
     }
 }
示例#6
0
 /// <summary>
 /// 释放某个ab包里面的某个资源
 /// </summary>
 /// <param name="abName"></param>
 /// <param name="resName"></param>
 public void DisposeResObj(string abName, string resName)
 {
     if (m_singleABDict.ContainsKey(abName))
     {
         m_singleABDict[abName].DisposeResObj(resName);
     }
     else
     {
         LogHelperLSK.LogError("卸载资源出错,包名: " + abName + " 资源名:" + resName);
     }
 }
示例#7
0
 /// <summary>
 /// 卸载指定资源
 /// </summary>
 /// <param name="assetObj"></param>
 public void UnLoadAsset(UnityEngine.Object assetObj)
 {
     if (m_asetLoader != null)
     {
         m_asetLoader.UnLoadAsset(assetObj);
     }
     else
     {
         LogHelperLSK.LogError("卸载资源出错 m_assetLoader is null ");
     }
 }
示例#8
0
    public SingleABLoader(string abName, LoadComplete loadComplete)
    {
        m_asetLoader = null;

        m_abName = abName;

        m_loadCompleteHandle = loadComplete;

        m_abDownLoadPath = PathTools.GetWWWPath() + "/" + m_abName;

        LogHelperLSK.Log("下载路径是:  " + m_abDownLoadPath);
    }
示例#9
0
 /// <summary>
 /// 查询包含得所有资源名称
 /// </summary>
 /// <returns></returns>
 public string[] RetiveAllAssetName()
 {
     if (m_asetLoader != null)
     {
         return(m_asetLoader.RetiveAllAssetName());
     }
     else
     {
         LogHelperLSK.LogError(" m_assetLoader is null ");
         return(null);
     }
 }
示例#10
0
 /// <summary>
 /// 加载资源
 /// </summary>
 /// <param name="assetName">资源名</param>
 /// <param name="isCache">是否缓存</param>
 /// <returns></returns>
 public UnityEngine.Object LoadAsset(string assetName, bool isCache)
 {
     if (m_asetLoader != null)
     {
         return(m_asetLoader.LoadAsset(assetName, isCache));
     }
     else
     {
         LogHelperLSK.LogError("加载资源出错,m_assetLoader is null: " + assetName);
         return(null);
     }
 }
示例#11
0
 /// <summary>
 /// 加载ab包中的资源
 /// </summary>
 /// <param name="abName">ab包名</param>
 /// <param name="assetName">资源名</param>
 /// <param name="isCache">是否需要缓存</param>
 /// <returns></returns>
 public UnityEngine.Object LoadAsset(string abName, string assetName, bool isCache)
 {
     if (m_singleABDict.ContainsKey(abName))
     {
         return(m_singleABDict[abName].LoadAsset(assetName, isCache));
     }
     else
     {
         LogHelperLSK.LogError("加载资源出错,资源名: " + assetName + "  ab包名:" + abName);
         return(null);
     }
 }
示例#12
0
 /// <summary>
 /// 释放一个场景中的所有资源
 /// </summary>
 /// <param name="sceneName"></param>
 public void DisposeAllAsset(string sceneName)
 {
     if (m_allScenes.ContainsKey(sceneName))
     {
         m_allScenes[sceneName].DisposeAllAsset();
         m_allScenes.Remove(sceneName);
     }
     else
     {
         LogHelperLSK.LogError("DisposeAllAsset资源出错,不存在sceneName: " + sceneName);
     }
 }
示例#13
0
 /// <summary>
 /// 获取指定ab包所有依赖关系
 /// </summary>
 /// <param name="abName">ab包名</param>
 /// <returns></returns>
 public string[] GetAllDependices(string abName)
 {
     if (m_manifest != null && !string.IsNullOrEmpty(abName))
     {
         return(m_manifest.GetAllDependencies(abName));
     }
     else
     {
         LogHelperLSK.LogError("m_manifest is null");
     }
     return(null);
 }
示例#14
0
    private void LoadComplate(string abName)
    {
        LogHelperLSK.Log(abName + " 加载完成");

        GameObject obj  = m_abLoader.LoadAsset(m_assetName, false) as GameObject;
        GameObject temp = GameObject.Instantiate(obj);

        string[] str = m_abLoader.RetiveAllAssetName();
        for (int i = 0; i < str.Length; i++)
        {
            LogHelperLSK.LogError(str[i]);
        }
    }
示例#15
0
 /// <summary>
 /// 卸载指定资源
 /// </summary>
 /// <param name="asset"></param>
 /// <returns></returns>
 public bool UnLoadAsset(UnityEngine.Object asset)
 {
     if (asset != null)
     {
         Resources.UnloadAsset(asset);
         return(true);
     }
     else
     {
         LogHelperLSK.LogError(GetType() + "要卸载得资源为空");
         return(false);
     }
 }
示例#16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="ab">给定www加载的ab</param>
 public AsetLoader(AssetBundle ab)
 {
     if (ab != null)
     {
         m_currentAssetBundle = ab;
         m_dict = new Dictionary <string, UnityEngine.Object>();
     }
     else
     {
         LogHelperLSK.LogError("AssetLoader 构造函数 ab is null");
         //LogHelperLSK
     }
 }
示例#17
0
    /// <summary>
    /// 加载指定场景中指定包中的指定资源
    /// </summary>
    /// <param name="sceneName"></param>
    /// <param name="abName"></param>
    /// <param name="assetName"></param>
    /// <param name="isCache"></param>
    /// <returns></returns>

    public UnityEngine.Object LoadAsset(string sceneName, string abName, string assetName, bool isCache)
    {
        if (m_allScenes.ContainsKey(sceneName))
        {
            MutilABMgr mutilABMgr = m_allScenes[sceneName];
            return(mutilABMgr.LoadAsset(abName, assetName, isCache));
        }
        else
        {
            LogHelperLSK.LogError("加载资源出错,不存在sceneName: " + sceneName);
        }
        return(null);
    }
示例#18
0
 /// <summary>
 /// 获取AssetBundleManifest
 /// </summary>
 /// <returns></returns>
 public AssetBundleManifest GetAssetBundleManifest()
 {
     if (m_isLoadFnish)
     {
         if (m_manifest != null)
         {
             return(m_manifest);
         }
         else
         {
             LogHelperLSK.LogError("m_manifest is null");
         }
     }
     else
     {
         LogHelperLSK.Log("manifest 加载尚未完成");
     }
     return(null);
 }
示例#19
0
    /// <summary>
    /// 加载资源
    /// </summary>
    /// <param name="assetName">资源名称</param>
    /// <param name="isCache">是否需要缓存</param>
    /// <returns></returns>
    private T LoadResource <T>(string assetName, bool isCache = false) where T : UnityEngine.Object
    {
        //先判断是否已经缓存
        if (m_dict.ContainsKey(assetName))
        {
            return(m_dict[assetName] as T);
        }

        T temp = m_currentAssetBundle.LoadAsset <T>(assetName);

        if (temp != null && isCache)
        {
            m_dict[assetName] = temp;
        }
        else if (temp == null)
        {
            LogHelperLSK.LogError(GetType() + "/ 获取资源为空,资源名: " + assetName);
        }
        return(temp);
    }
示例#20
0
    /// <summary>
    /// ab包下载
    /// </summary>
    /// <returns></returns>
    public IEnumerator LoadAssetBundle()
    {
        using (WWW www = new WWW(m_abDownLoadPath))
        {
            yield return(www);

            //下载完成
            if (www.progress >= 1)
            {
                LogHelperLSK.Log("加载完成:  " + m_abDownLoadPath);

                if (!string.IsNullOrEmpty(www.error))
                {
                    LogHelperLSK.LogError("www加载ab出错,路径是: " + m_abDownLoadPath + "错误: " + www.error);
                }

                //获取assetBundle的实例
                AssetBundle abObj = www.assetBundle;
                if (abObj != null)
                {
                    m_asetLoader = new AsetLoader(abObj);

                    //下载完成  调用委托
                    if (m_loadCompleteHandle != null)
                    {
                        m_loadCompleteHandle(m_abName);
                    }
                }
                else
                {
                    LogHelperLSK.LogError("AssetBundle is null:  " + m_abDownLoadPath);
                }
            }
            else
            {
                LogHelperLSK.LogError("www下载失败,下载路径是:  " + m_abDownLoadPath +
                                      "    www.error: " + www.error);
            }
        }
    }
示例#21
0
    public IEnumerator LoadManifestFile()
    {
        using (WWW www = new WWW(m_manifestPath))
        {
            yield return(www);

            if (www.progress >= 1)
            {
                //加载完成
                AssetBundle temp = www.assetBundle;
                if (temp != null)
                {
                    m_abReadManifest = temp;
                    //读取到Manifest
                    m_manifest    = m_abReadManifest.LoadAsset(ABDefine.AssetBundleManifest) as AssetBundleManifest;
                    m_isLoadFnish = true;
                }
                else
                {
                    LogHelperLSK.LogError("加载Manifest出错,请检查manifestPath: " + m_manifestPath + "  www error: " + www.error);
                }
            }
        }
    }
示例#22
0
    //public bool HaveLoad(string abName)
    //{
    //    return m_singleABDict.ContainsKey(abName);
    //}

    /// <summary>
    /// 释放本场景中的所有资源
    /// </summary>
    public void DisposeAllAsset()
    {
        List <string> keys = new List <string>();

        keys.AddRange(m_singleABDict.Keys);
        try
        {
            for (int i = 0; i < keys.Count; i++)
            {
                m_singleABDict[keys[i]].DisposeAll();
            }
        }
        catch (Exception ex)
        {
            LogHelperLSK.LogError(ex);
        }
        finally
        {
            m_singleABDict.Clear();
            m_singleABDict = null;

            //释放其他的
            m_relationDict.Clear();
            m_relationDict = null;

            m_currentSingleABLoader = null;
            m_currentABName         = null;
            m_ABCompleteHandle      = null;

            //卸载没有使用到的资源
            Resources.UnloadUnusedAssets();

            //强制GC
            GC.Collect();
        }
    }
示例#23
0
 private void LoadCompleteCallBack1(string abName)
 {
     LogHelperLSK.LogError("加载完成: " + abName);
     image.sprite = AssetBundleMgr.Instance.LoadAsset("scene_comon", "scene_comon/needloadsprite.ab", "Equipment_40.png", false) as Sprite;
 }