Exemplo n.º 1
0
    /// <summary>
    /// 获取带有子物体的资源
    /// </summary>
    /// <param name="assetName"></param>
    /// <returns>所有资源</returns>
    public Object[] LoadAssetWithSubAssets(string bundleName, string assetName)
    {
        //if (!nameBundleDic.ContainsKey(bundleName))
        //{
        //    Debug.LogError("当前" + bundleName + "包没有加载,无法获取资源!");
        //    return null;
        //}

        //return nameBundleDic[bundleName].LoadAssetWithSubAssets(assetName);



        // 1.先判断缓存没缓存?
        if (nameCacheDic.ContainsKey(bundleName))
        {
            Object[] assets = nameCacheDic[bundleName].GetAsset(assetName);
            if (assets != null)
            {
                return(assets);
            }
        }

        // 2.当前包有没有被加载
        if (!nameBundleDic.ContainsKey(bundleName))
        {
            Debug.LogError("当前" + bundleName + "包没有加载,无法获取资源!");
            return(null);
        }

        // 3.当前包已经被加载了,

        Object[]   asset     = nameBundleDic[bundleName].LoadAssetWithSubAssets(assetName);
        TempObject tempAsset = new TempObject();

        // 有这个缓存层,里面也有资源 , 但是这次获取资源的名字,是以前没缓存过的
        if (nameCacheDic.ContainsKey(bundleName))
        {
            // 直接加进去
            nameCacheDic[bundleName].AddAsset(assetName, tempAsset);
        }
        else
        {
            // 当前包已经被加载了,但是 是第一次获取这个包里的资源
            // 创建一个新的缓存层
            AssetCaching caching = new AssetCaching();
            caching.AddAsset(assetName, tempAsset);

            // 保存,下次使用
            nameCacheDic.Add(bundleName, caching);
        }



        return(asset);
    }
Exemplo n.º 2
0
    /// <summary>
    /// 获取带有子物体的资源
    /// </summary>
    /// <param name="assetName">资源名称</param>
    /// <returns>所有资源</returns>
    public Object[] LoadAssetWithSubAssets(string bundleName, string assetName)
    {
        //if (!nameBundleDict.ContainsKey(bundleName))
        //{
        //    Debug.LogError("当前 " + bundleName + " 包没有加载,无法获取资源");
        //    return null;
        //}

        //return nameBundleDict[bundleName].LoadAssetWithSubAssets(assetName);

        //-------------------------------------------------------------------

        //先判断缓存没缓存
        if (nameCacheDict.ContainsKey(bundleName))
        {
            Object[] assets = nameCacheDict[bundleName].GetAsset(assetName);
            //安全校验
            if (assets != null)
            {
                return(assets);
            }
        }

        //当前包有没有被加载
        if (!nameBundleDict.ContainsKey(bundleName))
        {
            Debug.LogError("当前 " + bundleName + " 包没有加载,无法获取资源");
            return(null);
        }

        //当前的包已经被加载了
        Object[]   asset    = nameBundleDict[bundleName].LoadAssetWithSubAssets(assetName);
        TempObject tmpAsset = new TempObject(asset);

        //有这个缓存层 里面也有资源 但是 这次获取的资源名字 是以前没缓存过的
        if (nameCacheDict.ContainsKey(bundleName))
        {
            //直接加进去
            nameCacheDict[bundleName].AddAsset(assetName, tmpAsset);
        }
        else
        {
            // 但是 第一次获取这个包里面的资源

            //创建一个新的缓存层
            AssetCaching caching = new AssetCaching();
            caching.AddAsset(assetName, tmpAsset);

            //保存到字典里面 方便下次使用
            nameCacheDict.Add(bundleName, caching);
        }

        return(asset);
    }
Exemplo n.º 3
0
    /// <summary>
    /// 获取单个资源
    /// </summary>
    /// <param name="assetName">资源名字</param>
    /// <returns>Obj类型的资源</returns>
    public Object LoadAsset(string bundleName, string assetName)
    {
        // 第一次加载 : 层层加载,并存到字典里;
        // 第二次加载 : 到字典里找,有就用,没有就再层层加载;

        // 1.先判断缓存没缓存?
        if (nameCacheDic.ContainsKey(bundleName))
        {
            Object[] assets = nameCacheDic[bundleName].GetAsset(assetName);
            if (assets != null)
            {
                return(assets[0]); //获取单个嘛,肯定就一个
            }
        }

        // 2.当前包有没有被加载
        if (!nameBundleDic.ContainsKey(bundleName))
        {
            Debug.LogError("当前" + bundleName + "包没有加载,无法获取资源!");
            return(null);
        }

        // 3.当前包已经被加载了,

        Object     asset     = nameBundleDic[bundleName].LoadAsset(assetName);
        TempObject tempAsset = new TempObject();

        // 有这个缓存层,里面也有资源 , 但是这次获取资源的名字,是以前没缓存过的
        if (nameCacheDic.ContainsKey(bundleName))
        {
            // 直接加进去
            nameCacheDic[bundleName].AddAsset(assetName, tempAsset);
        }
        else
        {
            // 当前包已经被加载了,但是 是第一次获取这个包里的资源
            // 创建一个新的缓存层
            AssetCaching caching = new AssetCaching();
            caching.AddAsset(assetName, tempAsset);

            // 保存,下次使用
            nameCacheDic.Add(bundleName, caching);
        }



        return(asset);
    }
Exemplo n.º 4
0
    /// <summary>
    /// 获取带有子物体的资源
    /// </summary>
    /// <param name="bundleName"></param>
    /// <param name="assetName">资源名称</param>
    /// <returns></returns>
    public Object[] LoadAssetWithSubAssets(string bundleName, string assetName)
    {
        //先到缓存查找
        if (nameCacheDict.ContainsKey(bundleName))
        {
            Object[] assets = nameCacheDict[bundleName].GetAsset(assetName);
            //有可能比没有加入缓存,但资源已经加载
            if (assets != null)
            {
                return(assets);
            }
        }

        //当前包没有被加载
        if (!nameBundleDict.ContainsKey(bundleName))
        {
            Debug.LogError("当前 " + bundleName + "包没有被加载,无法获取资源!");
            return(null);
        }

        //当前包已经被加载
        Object[]   asset    = nameBundleDict[bundleName].LoadAssetWithSubAssets(assetName);
        TempObject tmpAsset = new TempObject(asset);

        //有这个缓存层,并且里面有资源,但是这次获取的资源是之前没有缓存过的
        //直接添加
        if (nameCacheDict.ContainsKey(bundleName))
        {
            nameCacheDict[bundleName].AddAsset(assetName, tmpAsset);
        }
        else
        {
            //第一次获取这个包里面的资源
            AssetCaching catching = new AssetCaching();
            catching.AddAsset(assetName, tmpAsset);
            //保存到字典
            nameCacheDict.Add(bundleName, catching);
        }
        return(asset);
    }