Example #1
0
    /// <summary>
    /// 加载资源入口
    /// </summary>
    public AssetFile OpenAsset(string assetname, Action <AssetFile> Actionfile, bool isAsync)
    {
        AssetFile file = null;

        //????
        //assetname = AssemblyAssetName(assetname);

        if (files.TryGetValue(assetname, out file))
        {
            file.AddRefNum();
        }

        file = AssemblyAssetFile(assetname, isAsync);

        if (isAsync)
        {
            drive.StartCoroutine(AsyncLoad(file, Actionfile));
        }
        else
        {
            SyncLoad(file);
        }

        return(file);
    }
Example #2
0
    /// <summary>
    /// 组装一个AssetFile
    /// </summary>
    private AssetFile AssemblyAssetFile(string filepath, bool isAsync)
    {
        AssetFile assetfile = new AssetFile(num++, filepath);

        assetfile.onDestory += RemoveElement;
        //将文件添加进加载过的files字典
        files.Add(filepath, assetfile);
        //查找到所有的依赖资源
        string[] dps = manifest.GetAllDependencies(filepath);

        for (int i = 0; i < dps.Length; i++)
        {
            AssetFile file = null;
            //假设已经加载过了 引用计数加一 当前的AssetFile依赖文件加一
            if (files.TryGetValue(dps[i], out file))
            {
                file.AddRefNum();
                assetfile.Filelist.Add(file);
            }
            else
            {
                AssetFile newfile = AssemblyAssetFile(filepath, isAsync);
                assetfile.Filelist.Add(file);
                drive.StartCoroutine(AsyncLoad(newfile, null));
            }
        }

        return(assetfile);
    }
Example #3
0
    /// <summary>
    /// 引用计数增加
    /// </summary>
    public void AddRefNum()
    {
        Count++;

        for (int i = 0; i < Filelist.Count; i++)
        {
            AssetFile assetfile = Filelist[i];
            assetfile.AddRefNum();
        }
    }