Ejemplo n.º 1
0
 /// <summary>
 /// AssetBundle增加对象信息
 /// </summary>
 ///
 private void AddAssetCiteData(string path, AssetCiteData data)
 {
     if (!d_CiteData.ContainsKey(path))
     {
         d_CiteData.Add(path, data);
     }
 }
Ejemplo n.º 2
0
    /// <summary>
    /// AssetBundle卸载,is_recycled是否立即回收内存
    /// </summary>
    ///
    public void UnLoadUnUseAsset(string path, bool is_dependencies = false)
    {
        path = path.Replace(".", "_");
        SetAssetCiteCount(path, -1);
        AssetCiteData acd = GetAssetCiteInfo(path);

        if (acd.p_AssetObj == null)
        {
            return;
        }
        if (acd.p_CiteCount == 0)
        {
            acd.p_AssetObj.Unload(true);
            acd.p_AssetObj = null;
            d_CiteData.Remove(path);
            //Debug.Log("卸载资源路径:" + path);
        }
        if (!is_dependencies)
        {
            if (d_ObjData.ContainsKey(path))
            {
                d_ObjData.Remove(path);
            }
        }
        string[] assetbundleDependencies = main_assetbundle_manifest.GetDirectDependencies(path);
        for (int i = 0; i < assetbundleDependencies.Length; i++)
        {
            UnLoadUnUseAsset(assetbundleDependencies[i], true);
        }
    }
Ejemplo n.º 3
0
 /// <summary>
 /// AssetBundle引用对象信息
 /// </summary>
 ///
 private AssetCiteData GetAssetCiteInfo(string path)
 {
     if (d_CiteData.ContainsKey(path))
     {
         return(d_CiteData[path]);
     }
     return(AssetCiteData.Defult());
 }
Ejemplo n.º 4
0
 /// <summary>
 /// AssetBundle设置引用对象计数
 /// </summary>
 ///
 private void SetAssetCiteCount(string path, int count)
 {
     if (d_CiteData.Count > 0)
     {
         if (d_CiteData.ContainsKey(path))
         {
             AssetCiteData acd = d_CiteData[path];
             acd.p_CiteCount += count;
             d_CiteData[path] = acd;
         }
     }
 }
Ejemplo n.º 5
0
    /// <summary>
    /// 递归加载资源
    /// </summary>
    /// <param name="path">路径</param>
    /// <param name="type">类型</param>
    /// <param name="is_dependencies">是否是依赖资源</param>
    /// <returns></returns>
    private UnityEngine.Object LoadAsset(string path, System.Type type, bool is_dependencies = false)
    {
        path = path.Replace(".", "_");
        AssetBundle ab = null;

        string[] assetbundleDependencies = main_assetbundle_manifest.GetDirectDependencies(path);

        for (int i = 0; i < assetbundleDependencies.Length; i++)
        {
            LoadAsset(assetbundleDependencies[i], null, true);
        }
        if (!HasAssetCite(path))
        {
            //Debug.Log("加载资源路径:" + path);
            ab = AssetBundle.LoadFromFile(AppConst.LoadRes_Root_Path + path);
            if (ab != null)
            {
                AssetCiteData acd = new AssetCiteData();
                acd.p_AssetObj   = ab;
                acd.p_CiteCount += 1;
                acd.p_LoadFinish = true;
                AddAssetCiteData(path, acd);
            }
        }
        else
        {
            if (GetAssetCiteInfo(path).p_AssetObj != null)
            {
                ab = GetAssetCiteInfo(path).p_AssetObj;
            }
            SetAssetCiteCount(path, 1);
        }
        UnityEngine.Object retObj = null;
        if (!is_dependencies)
        {
            if (d_ObjData.ContainsKey(path))
            {
                return(d_ObjData[path]);
            }
            string obj_name      = path.Substring(path.LastIndexOf("/") + 1);
            string obj_name_suff = obj_name.Remove(0, obj_name.LastIndexOf('_') + 1);
            obj_name = obj_name.Remove(obj_name.LastIndexOf('_'), obj_name.Length - obj_name.LastIndexOf('_')) + "." + obj_name_suff;
            retObj   = ab.LoadAsset(obj_name);
            d_ObjData.Add(path, retObj);
        }
        return(retObj);
    }