Beispiel #1
0
    private void PlaceNewZoneUpToPosition(Vector3 endPoint)
    {
        Vector3Int minPoint = Vector3Int.FloorToInt(_startPoint);
        Vector3Int maxPoint = Vector3Int.FloorToInt(endPoint);

        ZoneCalculator.PrepareStartAndEndPoints(_startPoint, endPoint, ref minPoint, ref maxPoint, _mapBottomLeftCorner);
        HashSet <Vector3Int> newPositionsSet = _grid.GetAllPositionsFromTo(minPoint, maxPoint);

        newPositionsSet = CalculateZoneCost(newPositionsSet);

        _previousEndPosition = endPoint;
        ZoneCalculator.CalculateZone(newPositionsSet, _structuresToBeModified, _gameObjectsToReuse);

        foreach (var positionToPlaceStructure in newPositionsSet)
        {
            if (_grid.IsCellTaken(positionToPlaceStructure))
            {
                continue;
            }

            GameObject structureToAdd = null;
            if (_gameObjectsToReuse.Count > 0)
            {
                var gameObjectToReuse = _gameObjectsToReuse.Dequeue();
                gameObjectToReuse.SetActive(true);
                structureToAdd = _placementManager.MoveStructureOnTheMap(positionToPlaceStructure, gameObjectToReuse, _structureData.prefab);
            }
            else
            {
                structureToAdd = _placementManager.CreateGhostStructure(positionToPlaceStructure, _structureData.prefab);
            }

            _structuresToBeModified.Add(positionToPlaceStructure, structureToAdd);
        }
    }
        public void ZoneCalculatorTestPrepareStartAndEndPositionTopRightBOttomLeft()
        {
            Vector3    startPosition = new Vector3(3, 0, 3);
            Vector3    endPosition   = Vector3.zero;
            Vector3Int minPoint      = Vector3Int.FloorToInt(startPosition);
            Vector3Int maxPoint      = Vector3Int.FloorToInt(endPosition);

            ZoneCalculator.PrepareStartAndEndPoints(startPosition, endPosition, ref minPoint, ref maxPoint, Vector3.zero);
            Assert.AreEqual(Vector3Int.FloorToInt(startPosition), maxPoint);
            Assert.AreEqual(Vector3Int.FloorToInt(endPosition), minPoint);
        }