//**************************************************************************************************** // //**************************************************************************************************** public WebMapTile Grab(WebMapTileSlot slot) { WebMapTile tile = null; if (slot != null) { for (int entry = m_size - 1; entry >= 0; --entry) { if (m_entries[entry].location.coordGrid == slot.coordGrid) { tile = m_entries[entry]; m_entries[entry] = m_entries[--m_size]; break; } } if (tile == null) { tile = (m_size > 0) ? m_entries[--m_size] : null; } if (tile != null) { slot.Bind(tile); tile.pool = null; tile.gameObject.SetActive(true); } } return(tile); }
//**************************************************************************************************** // //**************************************************************************************************** public void ResetLayout() { float startX = (-(m_nbColsUsed >> 1) + 0.5f) * m_tilesSize; if ((m_nbColsUsed & 1) != 0) { startX -= 0.5f * m_tilesSize; } float startZ = ((m_nbRowsUsed >> 1) - 0.5f) * m_tilesSize; if ((m_nbRowsUsed & 1) != 0) { startZ += 0.5f * m_tilesSize; } for (int row = 0; row < m_nbRowsUsed; ++row) { for (int col = 0; col < m_nbColsUsed; ++col) { WebMapTileSlot Slot = m_slotsUsed[(row * m_nbColsUsed) + col]; Slot.layoutPos = new Vector3(startX + (col * m_tilesSize), 0.0f, startZ - (row * m_tilesSize)); Slot.position = Slot.layoutPos; Slot.coordGeo = GetGeoCoordsFromPosition(Slot.position); Slot.coordGrid = new GridCoords(int.MaxValue, int.MaxValue); } } UpdateLoadSequence(); }
//**************************************************************************************************** // //**************************************************************************************************** public void CreateLayout() { if (ResolveDependencies()) { m_loadingIcon.Setup("2D/MapTile/TileLoading"); m_tilesNode = new GameObject("Tiles"); m_tilesNode.transform.parent = transform; GameObject mdl = Resources.Load <GameObject>("3D/MapTile/MapTile"); Quaternion q = Quaternion.AngleAxis(90.0f, Vector3.right); if (mdl != null) { for (int tile = 0; tile < m_nbTiles; ++tile) { m_pool.Release(CreateTile(string.Format("Tile{0}", tile), mdl, q, m_tilesNode.transform, m_tilesSize)); } } for (int slot = 0; slot < m_nbSlots; ++slot) { m_slots[slot] = new WebMapTileSlot(); } } }
//**************************************************************************************************** // //**************************************************************************************************** public void UpdateTilesPosition() { int nbTilesRelaxed = 0; for (int slot = 0; slot < m_nbSlotsUsed; ++slot) { WebMapTileSlot Slot = m_slotsUsed[slot]; Slot.position = Slot.layoutPos - m_virtualPosSnaped; Slot.coordGeo = GetGeoCoordsFromPosition(Slot.position); Slot.coordGrid = GetGridCoordsFromRelativePosition(Slot.position); if (Slot.tile != null) { if (Slot.tile.location.coordGrid != Slot.coordGrid) { m_tilesRelaxed[nbTilesRelaxed++] = Slot.tile; m_pool.Release(Slot.tile); } } } for (int slot = 0; slot < m_nbSlotsUsed; ++slot) { WebMapTileSlot Slot = m_slotsUsed[slot]; if (Slot.tile == null) { m_pool.Grab(Slot); if (Slot.tile != null) { Slot.tile.location.coordGrid = Slot.coordGrid; Slot.tile.location.coordGeo = Slot.coordGeo; } } if (Slot.tile != null) { Slot.tile.position = Slot.position; } } for (int tile = 0; tile < nbTilesRelaxed; ++tile) { if (m_tilesRelaxed[tile].slot == null) { m_tilesRelaxed[tile].CancelLoadingRequest(); } } }