use new input system

This commit is contained in:
SepComet
2026-04-30 14:52:19 +08:00
parent a38a8d4b39
commit 1422db3b19
4 changed files with 37 additions and 26 deletions
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using GeometryTD.UI;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Tilemaps;
namespace GeometryTD.Entity
@@ -70,7 +71,14 @@ namespace GeometryTD.Entity
return false;
}
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
Mouse mouse = Mouse.current;
if (mouse == null)
{
return false;
}
Vector2 pointerPosition = mouse.position.ReadValue();
Ray ray = mainCamera.ScreenPointToRay(pointerPosition);
float mapPlaneZ = tilemap != null
? tilemap.transform.position.z
: (mapTransform != null ? mapTransform.position.z : 0f);
@@ -84,7 +92,7 @@ namespace GeometryTD.Entity
}
worldPosition = ray.GetPoint(enterDistance);
screenPosition = BuildScreenPosition(Input.mousePosition);
screenPosition = BuildScreenPosition(pointerPosition);
return true;
}
@@ -7,6 +7,7 @@ using GeometryTD.Entity.EntityData;
using GeometryTD.UI;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.Tilemaps;
using UnityGameFramework.Runtime;
@@ -15,17 +16,17 @@ namespace GeometryTD.Entity
public class MapEntity : EntityBase
{
private const int DefaultTowerTypeId = 401;
private static readonly Spawner[] EmptySpawners = Array.Empty<Spawner>();
[SerializeField] private bool _enableCombatSelectInput = true;
[SerializeField] private int _towerTypeId = DefaultTowerTypeId;
[SerializeField] private int[] _buildTowerCosts = { 40, 60, 60, 80 };
[SerializeField] private int _upgradeCost = 50;
[SerializeField] private int _destroyGain = 40;
private MapDataRefs _mapDataRefs;
@@ -119,7 +120,7 @@ namespace GeometryTD.Entity
}
base.OnShow(_mapData);
_combatRuntimeBridge?.Initialize(loadContext, name);
RefreshTiles();
@@ -272,7 +273,8 @@ namespace GeometryTD.Entity
private void HandleCombatSelectInput()
{
if (!_enableCombatSelectInput || !Input.GetMouseButtonDown(0))
Mouse mouse = Mouse.current;
if (!_enableCombatSelectInput || mouse == null || !mouse.leftButton.wasPressedThisFrame)
{
return;
}