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

View File

@ -1,11 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using GeometryTD.CustomEvent;
using GeometryTD.DataTable; using GeometryTD.DataTable;
using GeometryTD.Definition; using GeometryTD.Definition;
using GeometryTD.Entity; using GeometryTD.Entity;
using GeometryTD.Procedure; using GeometryTD.Procedure;
using GeometryTD.UI;
using UnityEngine; using UnityEngine;
using UnityGameFramework.Runtime; using UnityGameFramework.Runtime;
@ -95,9 +93,8 @@ namespace GeometryTD.CustomComponent
_runtime.NextDropOrdinal = 0; _runtime.NextDropOrdinal = 0;
_runtime.NextRewardOrdinal = 0; _runtime.NextRewardOrdinal = 0;
_runtime.CombatRunResourceStore.InitializeForCombat(level); _runtime.CombatRunResourceStore.InitializeForCombat(level);
for (int i = 0; i < phases.Count; i++) foreach (var phase in phases)
{ {
DRLevelPhase phase = phases[i];
if (phase != null) if (phase != null)
{ {
_runtime.PhaseBuffer.Add(phase); _runtime.PhaseBuffer.Add(phase);
@ -115,7 +112,8 @@ namespace GeometryTD.CustomComponent
_runtime.PhaseLoopRuntime.SetPhases(_runtime.PhaseBuffer); _runtime.PhaseLoopRuntime.SetPhases(_runtime.PhaseBuffer);
if (_runtime.PhaseLoopRuntime.PhaseCount <= 0) if (_runtime.PhaseLoopRuntime.PhaseCount <= 0)
{ {
return _coordinator.HandleStartFailure($"CombatScheduler start failed. Level '{level.Id}' has no phase data."); return _coordinator.HandleStartFailure(
$"CombatScheduler start failed. Level '{level.Id}' has no phase data.");
} }
ChangeState(new CombatLoadingState(_runtime, _coordinator)); ChangeState(new CombatLoadingState(_runtime, _coordinator));
@ -325,6 +323,5 @@ namespace GeometryTD.CustomComponent
} }
#endregion #endregion
} }
} }

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using GeometryTD.UI; using GeometryTD.UI;
using UnityEngine; using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Tilemaps; using UnityEngine.Tilemaps;
namespace GeometryTD.Entity namespace GeometryTD.Entity
@ -70,7 +71,14 @@ namespace GeometryTD.Entity
return false; 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 float mapPlaneZ = tilemap != null
? tilemap.transform.position.z ? tilemap.transform.position.z
: (mapTransform != null ? mapTransform.position.z : 0f); : (mapTransform != null ? mapTransform.position.z : 0f);
@ -84,7 +92,7 @@ namespace GeometryTD.Entity
} }
worldPosition = ray.GetPoint(enterDistance); worldPosition = ray.GetPoint(enterDistance);
screenPosition = BuildScreenPosition(Input.mousePosition); screenPosition = BuildScreenPosition(pointerPosition);
return true; return true;
} }

View File

@ -7,6 +7,7 @@ using GeometryTD.Entity.EntityData;
using GeometryTD.UI; using GeometryTD.UI;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.Tilemaps; using UnityEngine.Tilemaps;
using UnityGameFramework.Runtime; using UnityGameFramework.Runtime;
@ -272,7 +273,8 @@ namespace GeometryTD.Entity
private void HandleCombatSelectInput() private void HandleCombatSelectInput()
{ {
if (!_enableCombatSelectInput || !Input.GetMouseButtonDown(0)) Mouse mouse = Mouse.current;
if (!_enableCombatSelectInput || mouse == null || !mouse.leftButton.wasPressedThisFrame)
{ {
return; return;
} }

View File

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI; using UnityEngine.UI;
using UnityGameFramework.Runtime; using UnityGameFramework.Runtime;
@ -360,24 +361,27 @@ namespace GeometryTD.UI
private static bool TryGetPointerDownScreenPosition(out Vector2 screenPoint) private static bool TryGetPointerDownScreenPosition(out Vector2 screenPoint)
{ {
if (Input.touchCount > 0) Touchscreen touchscreen = Touchscreen.current;
if (touchscreen != null)
{ {
for (int i = 0; i < Input.touchCount; i++) var touches = touchscreen.touches;
for (int i = 0; i < touches.Count; i++)
{ {
Touch touch = Input.GetTouch(i); var touch = touches[i];
if (touch.phase != TouchPhase.Began) if (!touch.press.wasPressedThisFrame)
{ {
continue; continue;
} }
screenPoint = touch.position; screenPoint = touch.position.ReadValue();
return true; return true;
} }
} }
if (Input.GetMouseButtonDown(0)) Mouse mouse = Mouse.current;
if (mouse != null && mouse.leftButton.wasPressedThisFrame)
{ {
screenPoint = Input.mousePosition; screenPoint = mouse.position.ReadValue();
return true; return true;
} }