/
GeekNerd
/
ServerModelingProject
Обзор
Документация
Войти
/
GeekNerd
/
ServerModelingProject
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Assets/Scripts/RoomBuilding/RoomMouseInputHandler.cs
84 строки
2 KB
Gorney-Alex
Init
30 май 2026, 19:05
30 май 2026, 19:05
3cdcc49
Код
Авторство
О чём код?
using UnityEngine; using UnityEngine.EventSystems; using Zenject; namespace RoomBuilding { public class RoomMouseInputHandler : MonoBehaviour, IInitializable { private PolygonDrawingService _drawingService; private Camera _camera; [Inject] public void Construct(PolygonDrawingService drawingService) { _drawingService = drawingService; } public void Initialize() { _camera = Camera.main; } private void Update() { _drawingService.IsColumnMode = Input.GetKey(KeyCode.B); if (Input.GetKeyDown(KeyCode.Z) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))) { _drawingService.RemoveLastVertex(); return; } if (Input.GetKeyDown(KeyCode.Escape)) { _drawingService.Clear(); return; } if (_drawingService.IsColumnMode && !Mathf.Approximately(Input.mouseScrollDelta.y, 0f)) { _drawingService.ChangePreviewRadius(Input.mouseScrollDelta.y * 0.1f); } if ((_drawingService.State == DrawingState.Drawing || _drawingService.IsColumnMode) && !IsPointerOverUI()) { if (TryGetGroundPoint(out var point)) { _drawingService.HandleCursorMove(point); } } } private bool TryGetGroundPoint(out Vector2 result) { result = Vector2.zero; if (_camera == null) { _camera = Camera.main; if (_camera == null) return false; } var ray = _camera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out var hit, 1000f)) { result = new Vector2(hit.point.x, hit.point.z); return true; } var plane = new Plane(Vector3.up, Vector3.zero); if (plane.Raycast(ray, out float distance)) { var world = ray.GetPoint(distance); result = new Vector2(world.x, world.z); return true; } return false; } private static bool IsPointerOverUI() => EventSystem.current != null && EventSystem.current.IsPointerOverGameObject(); } }