Ejemplo n.º 1
0
    /// <summary>
    /// 释放超过一定时候都还没有显示的节点
    /// </summary>
    void ReleaseTooOld()
    {
        cubeNeedDelete.Clear();
        for (int i = 0; i < cachedCube.Count; i++)
        {
            if (!cachedCube[i].mCube.IsShow)
            {
                if (Time.unscaledTime - cachedCube[i].mTime > DIE_TIME)
                {
                    cubeNeedDelete.Add(cachedCube[i]);
                }
            }
        }

        if (cubeNeedDelete.Count > 0)
        {
            for (int j = 0; j < cubeNeedDelete.Count; j++)
            {
                QuadTreeSpaceCube c = cubeNeedDelete[j].mCube;
                if (c.Release())
                {
                    cachedCube.Remove(cubeNeedDelete[j]);
                }
            }
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 将场景节点加入到缓存中
    /// </summary>
    /// <param name="cube"></param>
    public void AddToCache(QuadTreeSpaceCube cube)
    {
        cachedCube.Add(new CubeTime(cube, Time.unscaledTime));
        cubeNeedDelete.Clear();

        int exceed = cachedCube.Count - MAX_CACHE_NUM;// 超出了可用缓存的数量

        if (exceed > 0)
        {
            for (int i = 0; i < cachedCube.Count; i++)
            {
                if (!cachedCube[i].mCube.IsShow)// 如果缓存中的节点没有显示,则将其添加到需要删除的列表中
                {
                    cubeNeedDelete.Add(cachedCube[i]);
                    if (cubeNeedDelete.Count >= exceed)// 如果需要删除的节点释放后在最大缓存范围内
                    {
                        break;
                    }
                }
            }
        }

        if (cubeNeedDelete.Count > 0)
        {
            for (int j = 0; j < cubeNeedDelete.Count; j++)// 释放需要删除节点的资源
            {
                QuadTreeSpaceCube c = cubeNeedDelete[j].mCube;
                if (c.Release())
                {
                    cachedCube.Remove(cubeNeedDelete[j]);
                }
            }
        }
    }