Работаю над системой ржавчины

This commit is contained in:
bybohka committed 2026-10-08 14:38:09 +03:00
1 parent 3e13180e34
commit 9a52384dbb
19 files changed
+924 -33

No files matched your search

@@ -0,0 +1,71 @@
using UnityEngine;
public enum ToolType { Hands, Sander, SprayCan }
public class PlayerToolManager : MonoBehaviour
{
[Header("Инструмент")]
public ToolType currentTool = ToolType.Hands;
[Header("Настройки")]
[SerializeField] private float toolRange = 2.5f;
[SerializeField] private LayerMask interactableLayer;
[SerializeField] private float sandSpeed = 0.35f; // Скорость очистки в сек.
[SerializeField] private Color sprayPaintColor = new Color(0.1f, 0.4f, 0.8f); // Выбранный цвет краски
private Camera playerCam;
private void Awake()
{
playerCam = GetComponentInChildren<Camera>();
}
private void Update()
{
// Не используем инструменты, если открыто меню или выбраны пустые руки
if (currentTool == ToolType.Hands) return;
// Зажата ЛКМ — работаем инструментом
if (Input.GetMouseButton(0))
{
UseActiveTool();
}
}
private void UseActiveTool()
{
Ray ray = new Ray(playerCam.transform.position, playerCam.transform.forward);
if (!Physics.Raycast(ray, out RaycastHit hit, toolRange, interactableLayer)) return;
CarPartVisuals visuals = hit.collider.GetComponentInParent<CarPartVisuals>();
if (visuals == null) return;
if (currentTool == ToolType.Sander)
{
// ШЛИФОВКА: снижаем ржавчину к 0
if (visuals.CurrentRust > 0f)
{
float updatedRust = visuals.CurrentRust - (sandSpeed * Time.deltaTime);
visuals.SetRust(updatedRust);
}
}
else if (currentTool == ToolType.SprayCan)
{
// ПОКРАСКА: красим, только если ржавчина удалена
if (visuals.CurrentRust <= 0.05f)
{
visuals.SetPaintColor(sprayPaintColor);
}
else
{
// Подсказка игроку
Debug.Log("Нельзя красить: деталь еще ржавая! Зашлифуйте её.");
}
}
}
public void SelectTool(ToolType newTool)
{
currentTool = newTool;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 79b9bf3c26bc4f38a11491b3776b8121
timeCreated: 1791393489
@@ -0,0 +1,92 @@
using UnityEngine;
using UnityEngine.UI;
public class ToolRadialMenu : MonoBehaviour
{
[Header("Ссылки")]
[SerializeField] private GameObject menuPanel;
[SerializeField] private PlayerToolManager toolManager;
[SerializeField] private Image[] sectorIcons; // 3 иконки (0: Руки, 1: Шлифмашинка, 2: Баллончик)
[Header("Цвета выделения")]
[SerializeField] private Color normalColor = Color.white;
[SerializeField] private Color selectedColor = Color.yellow;
private int selectedIndex = 0;
private bool isMenuOpen = false;
private void Start()
{
menuPanel.SetActive(false);
}
private void Update()
{
// Открытие/закрытие по клавише Tab
if (Input.GetKeyDown(KeyCode.Tab))
{
OpenMenu();
}
else if (Input.GetKeyUp(KeyCode.Tab))
{
CloseMenuAndApply();
}
if (isMenuOpen)
{
CalculateMouseSector();
}
}
private void OpenMenu()
{
isMenuOpen = true;
menuPanel.SetActive(true);
// Разблокируем курсор для кругового выбора
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
private void CalculateMouseSector()
{
Vector2 screenCenter = new Vector2(Screen.width * 0.5f, Screen.height * 0.5f);
Vector2 mouseDelta = (Vector2)Input.mousePosition - screenCenter;
// Если мышь почти в центре — ничего не меняем
if (mouseDelta.magnitude < 30f) return;
// Вычисляем угол мыши от -180 до 180 градусов
float angle = Mathf.Atan2(mouseDelta.y, mouseDelta.x) * Mathf.Rad2Deg;
if (angle < 0) angle += 360f; // Переводим в 0..360
// 3 сектора по 120 градусов:
// Сектор 0 (0..120): Руки
// Сектор 1 (120..240): Шлифмашинка
// Сектор 2 (240..360): Баллончик
selectedIndex = Mathf.FloorToInt(angle / 120f);
HighlightSelection();
}
private void HighlightSelection()
{
for (int i = 0; i < sectorIcons.Length; i++)
{
sectorIcons[i].color = (i == selectedIndex) ? selectedColor : normalColor;
}
}
private void CloseMenuAndApply()
{
isMenuOpen = false;
menuPanel.SetActive(false);
// Возвращаем прицел от первого лица
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
// Применяем выбранный инструмент
toolManager.SelectTool((ToolType)selectedIndex);
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: aefd5e59eb964d74a70224a9b43918d0
timeCreated: 1791393583