示例#1
0
    /// <summary>
    /// 在游戏过程中的加载【需要预防:加载完后回调已经被删除】
    /// 可以用于loading过程,也能用于游戏过程,可以选择是否缓存
    /// </summary>
    /// <param name="name"></param>
    /// <param name="_callback"></param>
    /// <param name="noCache"></param>
    public void loadWeak(string name, LoadCallback _callback, bool cache)
    {
        //确认cache
        sCacheUnit scu = sCache.GetInstance().getUnusedCache(name);

        if (scu != null)
        {
            scu.isUsing = true;
            if (_callback != null)
            {
                if (sCache.GetInstance().isLoadOK(name))
                {
                    _callback(scu);
                }
                else
                {
                    sCache.GetInstance().pushCache(name, _callback);
                }
            }
            return;
        }
        //如果cache无法解决,则读取资源(需要先创建一个scu,用于确保下次读取时不用重复加载)
        sCache.GetInstance().initPreCache(CacheType.single, name, !cache);
        sCache.GetInstance().pushCache(name, _callback);
        sLoadAssetbundle.GetInstance().loadAssetBundle(name, (obj) =>
        {
            sCache.GetInstance().cacheLoadOK(name, obj);
        });
    }
示例#2
0
    public sCacheUnit getUnusedCache(string name)
    {
        if (_caches.ContainsKey(name))
        {
            if (!_deepCache.ContainsKey(name))
            {
                return(_caches[name][0]);
            }
            for (int i = 0; i < _caches[name].Count; ++i)
            {
                if (_caches[name][i].isUsing)
                {
                    continue;
                }
                return(_caches[name][i]);
            }
            int num = _caches[name].Count;
            //数量全部被用完,需要手动扩充
            for (int i = 0; i < 2; ++i)
            {
                sCacheUnit cu = new sCacheUnit();

                cu.obj     = GameObject.Instantiate(_deepCache[name].obj, Vector3.zero, Quaternion.identity) as GameObject;
                cu.isUsing = false;
                _caches[name].Add(cu);
            }
            return(_caches[name][num]);
        }
        return(null);
    }
示例#3
0
    public void _loadcallback(sCacheUnit scu)
    {
        sULoading.instance.disableCamera();
        scu.obj.SetActive(true);

        //sCache.GetInstance().clearScu(scu);
        //scu.obj = null;
    }
示例#4
0
 public void _loadcallback(sCacheUnit scu)
 {
     //Debug.Log("loadcb:" + scu);
     scu.obj.SetActive(true);
     tsc.Add(scu);
     //sCache.GetInstance().clearScu(scu);
     //scu.obj = null;
 }
示例#5
0
 public void _loadcallback(sCacheUnit scu)
 {
     //加载场景完成
     //这里暂时将loading隐藏的调用放着,之后流程完成化后需要进flow
     scu.obj.SetActive(true);
     sULoading.instance.hideLoading();
     _mapOver = true;
 }
示例#6
0
    void loadModelOK(sCacheUnit scu)
    {
        scu.obj.transform.parent = playerCC.transform;

        float height = playerCC.GetComponent <CapsuleCollider>().height;

        scu.obj.transform.localPosition = new Vector3(0, -height / 2, 0);
        scu.obj.transform.localRotation = Quaternion.identity;
        scu.obj.SetActive(true);
        anim = scu.obj.GetComponent <Animation> ();
        pc   = playerCC.GetComponent <sEntityControl>();
        pc.setAnim(anim);

        _model = scu;
    }
示例#7
0
    public void initPreCache(CacheType ctype, string name, bool noCache)
    {
        if (_caches.ContainsKey(name))
        {
            Debug.LogError("same name cache:" + name);
            return;
        }
        int cachenum = 2;

        if (!noCache)
        {
            _caches.Add(name, new List <sCacheUnit>());
            for (int i = 0; i < cachenum; ++i)
            {
                sCacheUnit cu = new sCacheUnit();
                cu.name    = name;
                cu.obj     = null;
                cu.isUsing = false;

                _caches[name].Add(cu);
            }
        }
    }
示例#8
0
    public void cacheLoadOK(string name, UnityEngine.Object go)
    {
        sCacheUnit tmp = new sCacheUnit();

        tmp.obj = GameObject.Instantiate(go, Vector3.zero, Quaternion.identity) as GameObject;
        tmp.obj.SetActive(false);
        _deepCache.Add(name, tmp);

        if (_caches.ContainsKey(name))
        {
            for (int i = 0; i < _caches[name].Count; ++i)
            {
                _caches[name][i].obj     = GameObject.Instantiate(_deepCache[name].obj, Vector3.zero, Quaternion.identity) as GameObject;
                _caches[name][i].isUsing = false;
            }
        }

        if (_waitCaches.ContainsKey(name))
        {
            Debug.Log("cache name:" + name + "," + _waitCaches[name].Count + "," + _caches.ContainsKey(name));
            //唯一
            if (_waitCaches[name].Count == 1 && !_caches.ContainsKey(name))
            {
                _waitCaches[name][0](_deepCache[name]);
            }
            else
            {
                for (int i = 0; i < _waitCaches[name].Count; ++i)
                {
                    sCacheUnit scu = getUnusedCache(name);
                    scu.isUsing = true;
                    _waitCaches[name][i](scu);
                }
            }
        }
    }
示例#9
0
 /// <summary>
 /// 不是真实的卸载,而是disable
 /// </summary>
 /// <param name="scu"></param>
 public void clearScu(sCacheUnit scu)
 {
     scu.isUsing = false;
     scu.obj.SetActive(false);
 }
示例#10
0
 /// <summary>
 /// 这个不是卸载,只是将scu通过cache隐藏,等待其他人使用
 /// </summary>
 /// <param name="name"></param>
 public void unloadWeak(sCacheUnit scu)
 {
     sCache.GetInstance().clearScu(scu);
 }
示例#11
0
 public void destroyModel()
 {
     sLoadingGame.GetInstance().unloadWeak(_model);
     _model = null;
 }