Fix Object Instantiating

This commit is contained in:
2025-12-14 10:59:21 +08:00
parent 6fe70bd113
commit 6abccbe6d8
21 changed files with 371 additions and 180 deletions

View File

@@ -0,0 +1,35 @@
using System;
using Services.Interfaces;
using UnityEngine;
namespace Services {
public class InputService : MonoBehaviour, IInputService
{
public event Action<Vector2> OnPointerDown;
public event Action<Vector2> OnPointerUp;
private bool wasDown;
private void Update()
{
// Mouse
var isDown = Input.GetMouseButton(0);
if (!wasDown && isDown)
OnPointerDown?.Invoke(Input.mousePosition);
if (wasDown && !isDown)
OnPointerUp?.Invoke(Input.mousePosition);
wasDown = isDown;
// Optional: Touch (if you want both, you can merge logic more carefully)
if (Input.touchCount <= 0) return;
var t = Input.GetTouch(0);
if (t.phase == TouchPhase.Began)
OnPointerDown?.Invoke(t.position);
else if (t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled)
OnPointerUp?.Invoke(t.position);
}
}
}