Пример #1
0
        private void SetBuildingPosition()
        {
            if (TryGetMouseGridPosition(out MapGridPosition closestGridPosition))
            {
                bool enoughResources = Building.Construction.HasEnoughResources();
                if (!enoughResources)
                {
                    Debug.Log("Not enough resources!");
                    return;
                }

                bool isSlotAvailable = Building.Map.Grid.IsSlotAvailable(closestGridPosition.GridPosition, Building.Size);
                if (isSlotAvailable)
                {
                    Building.SetMapGridPosition(closestGridPosition);
                    Building.Construction.StartConstruction();
                    LevelManager.Instance.Buildings.ClearPlacement();
                }
            }
        }
Пример #2
0
        public void OnEndDrag(PointerEventData eventData)
        {
            if (!Active)
            {
                return;
            }

            MapGridPosition closestPosition = GetClosestMouseGridPosition(eventData);
            Vector2Int      gridPosition    = closestPosition.GridPosition;

            Building.Map.Grid.RemoveFromGrid(Building.CurrentPosition, Building.Size);
            if (Building.Map.Grid.IsSlotAvailable(gridPosition, Building.Size))
            {
                Building.SetMapGridPosition(closestPosition);
            }
            else
            {
                Building.Map.Grid.InsertIntoGrid(Building.CurrentPosition, Building.Size);
                transform.position = _startingPosition;
            }
        }