Refactor: Managers to systems
This commit is contained in:
@@ -3,31 +3,34 @@ using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class InGameMouseHandler : MonoBehaviour
|
||||
public class InGameMouseHandler:UnityEngine.Object
|
||||
{
|
||||
[SerializeField]
|
||||
private LayerMask _selectableLayerMask;
|
||||
[SerializeField]
|
||||
|
||||
private LayerMask _walkableLayerMask;
|
||||
[SerializeField]
|
||||
|
||||
private WaypointVisual _waypointVisual;
|
||||
|
||||
[SerializeField]
|
||||
private Camera _camera;
|
||||
|
||||
private Ray _ray;
|
||||
|
||||
private Camera _camera;
|
||||
public static event EventHandler<OnSelectedObjectChangedEventArgs> OnSelectedObjectChanged;
|
||||
|
||||
private BaseInteractableObject _selectedObject;
|
||||
|
||||
|
||||
private void Start()
|
||||
public InGameMouseHandler(Camera camera)
|
||||
{
|
||||
_camera = camera;
|
||||
_selectableLayerMask =LayerMask.NameToLayer("Selectable");
|
||||
_walkableLayerMask = LayerMask.NameToLayer("Walking");
|
||||
|
||||
var waypointPrefab = Resources.Load("WayPointSign", typeof(WaypointVisual)) as WaypointVisual;
|
||||
_waypointVisual =Instantiate(waypointPrefab);
|
||||
|
||||
GameManager.Instance.Input.PlayerAction.PointClick.performed += ClickToMove;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
public void Dispose()
|
||||
{
|
||||
GameManager.Instance.Input.PlayerAction.PointClick.performed += ClickToMove;
|
||||
}
|
||||
@@ -38,7 +41,6 @@ public class InGameMouseHandler : MonoBehaviour
|
||||
{
|
||||
if (_selectedObject != null)
|
||||
{
|
||||
print($"Go to interaction point {_selectedObject._interactionPoint.position}");
|
||||
_waypointVisual.SetWaypoint(_selectedObject._interactionPoint.position);
|
||||
Player.Instance.AddTask(new PlayerTasks(Tasks.Interact, _selectedObject));
|
||||
}
|
||||
@@ -46,7 +48,6 @@ public class InGameMouseHandler : MonoBehaviour
|
||||
{
|
||||
if (Physics.Raycast(_ray, out RaycastHit hit, 100f, _walkableLayerMask))
|
||||
{
|
||||
print($"hit point {hit.point} collider pos {hit.collider.transform.position}");
|
||||
_waypointVisual.SetWaypoint(hit.point);
|
||||
Player.Instance.AddTask(new PlayerTasks(Tasks.Move, _waypointVisual));
|
||||
}
|
||||
@@ -54,7 +55,7 @@ public class InGameMouseHandler : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
public void Update()
|
||||
{
|
||||
_ray = _camera.ScreenPointToRay(Mouse.current.position.ReadValue());
|
||||
if(EventSystem.current.IsPointerOverGameObject())
|
||||
@@ -77,7 +78,6 @@ public class InGameMouseHandler : MonoBehaviour
|
||||
else
|
||||
{
|
||||
OnSelectedObjectChanged?.Invoke(this, new OnSelectedObjectChangedEventArgs() { SelectedObject = null });
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user