Ejemplo n.º 1
0
        private void OpenCellDataSync(SceneCellInfo cellInfo)
        {
            if (cellInfo == null)
            {
#if UNITY_EDITOR
                Debug.LogWarning("cellInfo 为 Null");
#endif
                return;
            }

            if (cellInfo.isOpen)
            {
                return;
            }
            while (m_linkOpenedCell.Count > m_maxCellOpenCount)
            {
                int temp = m_linkOpenedCell.Count;
                CloseCellData();
                if (m_linkOpenedCell.Count >= temp)
                {
#if UNITY_EDITOR
                    Debug.LogError("严重警告!地图块隐藏失败!");
#endif
                    break;
                }
            }

            cellInfo.isOpen = true;
            m_linkOpenedCell.AddLast(cellInfo);
            foreach (var item in cellInfo.itemsNum)
            {
                CreateItem(item, true);
            }
        }
Ejemplo n.º 2
0
        //关闭一个最远的cell地图块
        private void CloseCellData()
        {
            if (m_mapInfo == null)
            {
#if UNITY_EDITOR
                Debug.LogWarning("m_mapInfo 为 Null");
#endif
                return;
            }

            int xNum = (int)((m_playerPos.x - m_xMin) / m_xCellSize);
            int zNum = (int)((m_playerPos.z - m_zMin) / m_zCellSize);

            int           farthest  = 0;
            SceneCellInfo closeCell = null;
            foreach (var cell in m_linkOpenedCell)
            {
                int xCellNum = cell.cellId % m_xCell;
                int zCellNum = cell.cellId / m_xCell;

                int temp = Mathf.Max(Mathf.Abs(xCellNum - xNum),
                                     Mathf.Abs(zCellNum - zNum));
                if (temp > farthest)
                {
                    farthest  = temp;
                    closeCell = cell;
                }
            }

            if (closeCell == null)
            {
#if UNITY_EDITOR
                Debug.LogWarning("没有找到可删除地图块!");
#endif
                return;
            }

            m_linkOpenedCell.Remove(closeCell);
            closeCell.isOpen = false;
            foreach (var item in closeCell.itemsNum)
            {
                DeleteItem(item);
            }
        }