private void MakeSureShowIndices(TileRect tr)
        {
            m_PendingGenCells.Clear();
            int index_of_tile;
            int prefabid_of_tile;

            //第一步,计算玩家EndDrag的时候,需要显示的新的格子
            for (int ix = tr.x; ix <= tr.x_end; ix++)
            {
                for (int iy = tr.y; iy <= tr.y_end; iy++)
                {
                    index_of_tile    = ix * m_Config.width + iy;
                    prefabid_of_tile = m_ArchiveFile[index_of_tile];

                    m_PendingGenCells.Add(index_of_tile, prefabid_of_tile);

                    //这里先添加到SpawingCells中去,真正的Spawn和Delete都在Update里面进行的。
                    //可以延迟加载和删除,防止卡顿。
                    if (m_ActiveCells.ContainsKey(index_of_tile) == false)
                    {
                        m_SpawningCells[index_of_tile] = new TilePoint(ix, iy);
                    }

                    SpawnGeneration++;

                    //如果这个格子在死亡格子里面,那么,取消他的死刑。
                    if (m_DyingCells.ContainsKey(index_of_tile))
                    {
                        m_DyingCells.Remove(index_of_tile);
                    }
                }
            }

            //Debug.Log("m_spawing cells count is " + m_SpawningCells.Count);

            foreach (int key in m_ActiveCells.Keys)
            {
                //pending里面不包含这个格子,那么他是将要删掉的格子。
                if (m_PendingGenCells.ContainsKey(key) == false)
                {
                    m_DyingCells[key] = Time.timeSinceLevelLoad + deleteDelay;

                    //对于将要删除的格子,判断他是不是将要生成的格子,避免尴尬
                    if (m_SpawningCells.ContainsKey(key))
                    {
                        m_SpawningCells.Remove(key);
                    }
                }
            }

            //Debug.Log("Dying Key count " + m_DyingCells.Count);
        }
Beispiel #2
0
 /// <summary>
 /// 将一个TilePoint,散列成一个唯一的索引值,用于在Dictionary快速定位一个MapTile格子
 /// </summary>
 /// <param name="point"></param>
 /// <returns></returns>
 public static int Hash(TilePoint point)
 {
     return(SharedUtil.PointHash(point.x, point.y));
 }
Beispiel #3
0
 //返回两点之间的笛卡尔距离。
 public static int DescartesDistance(TilePoint p1, TilePoint p2)
 {
     return(Mathf.Abs(p1.x - p2.x) + Mathf.Abs(p1.y - p2.y));
 }