Esempio n. 1
0
        public void AddUnit(UnitView unitView, Vector2Int tileXY, int sortOrder, RectInt localBounds)
        {
            UnitMapState state = new UnitMapState(unitView, tileXY, sortOrder, localBounds);

            RectInt worldBounds = new RectInt();

            worldBounds.min = tileXY + localBounds.min;
            worldBounds.max = tileXY + localBounds.max;

            // Add to list
            m_Units.Add(state);

            // Add to map
            for (int x = worldBounds.min.x; x < worldBounds.max.x; ++x)
            {
                if (x < 0 || x >= m_UnitMap.GetLength(0))
                {
                    continue;
                }

                for (int y = worldBounds.min.y; y < worldBounds.max.y; ++y)
                {
                    if (y < 0 || y >= m_UnitMap.GetLength(1))
                    {
                        continue;
                    }
                    m_UnitMap[x, y].Add(state);
                    m_UnitMap[x, y].Sort((a, b) => a.sortOrder.CompareTo(b.sortOrder));
                }
            }

            // Refresh minimap
            RefreshMinimapTiles(worldBounds.min, worldBounds.max);
        }
Esempio n. 2
0
        public void MoveUnit(UnitView unitView, Vector2Int tileXY)
        {
            UnitMapState state = _RemoveUnit(unitView);

            if (state != null)
            {
                AddUnit(unitView, tileXY, state.sortOrder, state.localBounds);
            }
        }
Esempio n. 3
0
        private void RefreshMinimapTile(int x, int y)
        {
            List <UnitMapState> statesOnTile = m_UnitMap[x, y];

            if (statesOnTile.Count == 0)
            {
                // No units left on tile, clear it
                minimapTexture.SetPixel(x, y, Color.clear);
                minimapTexture.Apply();
            }
            else
            {
                // Use color of last unit in list
                UnitMapState lastState = statesOnTile[statesOnTile.Count - 1];
                minimapTexture.SetPixel(x, y, lastState.view.GetMinimapColor());
                minimapTexture.Apply();
            }
        }
Esempio n. 4
0
        private UnitMapState _RemoveUnit(UnitView unitView)
        {
            // Find unit in list
            int index = m_Units.FindIndex((state2) => state2.view == unitView);

            if (index < 0)
            {
                return(null);
            }

            UnitMapState state = m_Units[index];

            // Remove from list
            m_Units.RemoveAt(index);

            RectInt worldBounds = new RectInt();

            worldBounds.min = state.currentTileXY + state.localBounds.min;
            worldBounds.max = state.currentTileXY + state.localBounds.max;

            // Remove from map
            for (int x = worldBounds.min.x; x < worldBounds.max.x; ++x)
            {
                if (x < 0 || x >= m_UnitMap.GetLength(0))
                {
                    continue;
                }

                for (int y = worldBounds.min.y; y < worldBounds.max.y; ++y)
                {
                    if (y < 0 || y >= m_UnitMap.GetLength(1))
                    {
                        continue;
                    }
                    m_UnitMap[x, y].Remove(state);
                }
            }


            // Refresh minimap
            RefreshMinimapTiles(worldBounds.min, worldBounds.max);

            return(state);
        }