コード例 #1
0
    public void UnloadAll()
    {
        if (_bundle != null)
        {
            RGLog.DebugResLoad("<color=red> unload all bundle </color> -> {0}", _packageName);
            _bundle.Unload(false);
            _bundle = null;
        }

        RGRes res = null;

        for (int i = 0; i < _cacheRes.Count; i++)
        {
            res = _cacheRes[i];
            if (res != null)
            {
                RGLog.DebugResLoad("{0}:{1} \tRef:{2}", _packageName, res.ResName, res.RefCount);

                res.UnLoad();
            }
        }

        _cacheRes.Clear();
        // 清除list所占的内存
        _cacheRes.TrimExcess();

        Unloaded = true;
    }
コード例 #2
0
    public UnityEngine.Object LoadAsset(string assetName)
    {
        if (_bundle == null)
        {
            LoadBundle(assetName);
        }

        if (IsUI || IsForverBundle)
        {
            return(_bundle);
        }

        RGRes res = FindRes(assetName);

        if (res != null)
        {
            return(GetAsset(assetName));
        }

        var asset = _bundle.LoadAsset <UnityEngine.Object>(assetName);

        // 添加资源缓存
        AddRes(assetName, asset);
        return(asset);
    }
コード例 #3
0
    private RGRes AddRes(string assetName, UnityEngine.Object obj)
    {
        var res = new RGRes(assetName, obj);

        _cacheRes.Add(res);

        return(res);
    }
コード例 #4
0
    private RGRes FindRes(string resName)
    {
        RGRes res = null;

        for (int i = 0; i < _cacheRes.Count; i++)
        {
            res = _cacheRes[i];
            if (res != null && res.ResName == resName)
            {
                return(res);
            }
        }
        return(null);
    }
コード例 #5
0
    public void LoadAssetAsync(string assetName, Action <UnityEngine.Object, LoadEventData> loadComplete,
                               LoadEventData evData)
    {
        RGRes res = FindRes(assetName);

        if (res != null)
        {
            var asset = GetAsset(assetName);
            loadComplete(asset, evData);
            return;
        }
        AddCallback(assetName, loadComplete, evData);

        CoroutineManager.Instance.StartCoroutine(IELoadAssetAsync(assetName, loadComplete, evData));
    }
コード例 #6
0
    private bool RemoveRes(RGRes removeRes)
    {
        RGRes res = null;

        for (int i = 0; i < _cacheRes.Count; i++)
        {
            res = _cacheRes[i];
            if (res == removeRes)
            {
                _cacheRes.RemoveAt(i);
                return(true);
            }
        }
        return(false);
    }