Слияние: наши панели HUD, стройка, казармы, камера + карта мира, чат и рейтинг от Саши
This commit is contained in:
@@ -57,7 +57,7 @@ public class BuildManager : MonoBehaviour
|
||||
slotUnderPointer.SetHighlight(canAfford ? highlightValidColor : highlightInvalidColor);
|
||||
lastHighlightedSlot = slotUnderPointer;
|
||||
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
if (Input.GetMouseButtonDown(0) && !UIBlocker.IsPointerOverUI())
|
||||
{
|
||||
TryConfirmPlacement(slotUnderPointer, canAfford);
|
||||
}
|
||||
@@ -113,6 +113,7 @@ public class BuildManager : MonoBehaviour
|
||||
currentlyPlacing.PayCost();
|
||||
|
||||
GameObject built = Instantiate(currentlyPlacing.prefab, slot.transform.position, Quaternion.identity);
|
||||
if (!built.activeSelf) built.SetActive(true); // шаблон казарм хранится выключенным
|
||||
|
||||
PlacedBuildingId idMarker = built.AddComponent<PlacedBuildingId>();
|
||||
idMarker.buildingName = currentlyPlacing.buildingName;
|
||||
@@ -139,6 +140,39 @@ public class BuildManager : MonoBehaviour
|
||||
Debug.Log("[СТРОЙКА] Размещение отменено.");
|
||||
}
|
||||
|
||||
// ===== Новая схема стройки: тап по участку -> выбор здания (BuildModeController) =====
|
||||
|
||||
// Построить здание сразу на указанном участке. true -- получилось.
|
||||
public bool BuildOnSlot(BuildingData data, BuildSlot slot)
|
||||
{
|
||||
if (data == null || slot == null || slot.isOccupied) return false;
|
||||
if (!data.CanAfford()) return false;
|
||||
currentlyPlacing = data;
|
||||
TryConfirmPlacement(slot, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Участок под точкой экрана (с допуском, чтобы попадать с первого раза пальцем)
|
||||
public BuildSlot SlotAtScreen(Vector2 screenPos, float tolerance = 0.35f)
|
||||
{
|
||||
if (mainCam == null) mainCam = Camera.main;
|
||||
if (mainCam == null) return null;
|
||||
Vector3 w = mainCam.ScreenToWorldPoint(screenPos);
|
||||
Vector2 p = new Vector2(w.x, w.y);
|
||||
// Перебираем все участки и берём ближайший: работает и с триггер-коллайдерами, и без настроенного слоя
|
||||
BuildSlot best = null;
|
||||
float bestDist = tolerance;
|
||||
foreach (var slot in FindObjectsByType<BuildSlot>(FindObjectsSortMode.None))
|
||||
{
|
||||
var col = slot.GetComponent<Collider2D>();
|
||||
Bounds b = col != null ? col.bounds : new Bounds(slot.transform.position, Vector3.one * 0.5f);
|
||||
b.center = new Vector3(b.center.x, b.center.y, 0f);
|
||||
float d = Mathf.Sqrt(b.SqrDistance(new Vector3(p.x, p.y, 0f)));
|
||||
if (d <= bestDist) { bestDist = d; best = slot; }
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
// Найти пустой (свободный) BuildSlot по названию -- используется при восстановлении сохранения
|
||||
public BuildSlot FindSlotAtPosition(Vector3 position, float tolerance = 0.05f)
|
||||
{
|
||||
|
||||
@@ -74,6 +74,7 @@ public class TownHall : MonoBehaviour
|
||||
}
|
||||
void OnMouseDown()
|
||||
{
|
||||
if (UIBlocker.IsPointerOverUI()) return; // клик по панели HUD не должен улучшать Ратушу под ней
|
||||
Debug.Log($"[Ратуша] Клик! текущий уровень: {currentLevel}. Улучшение...");
|
||||
Upgrade();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user