Refactor: Managers to systems
This commit is contained in:
@@ -4,6 +4,10 @@ using UnityEngine.InputSystem;
|
||||
|
||||
public class CameraSystem : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Camera _mainCamera;
|
||||
public Camera MainCamera => _mainCamera;
|
||||
|
||||
[SerializeField]
|
||||
private CinemachineVirtualCamera _camera;
|
||||
[SerializeField]
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private CameraSystem _cameraSystem;
|
||||
|
||||
private bool _isPause;
|
||||
private InputSystem _inputSystem;
|
||||
private SceneManager _sceneManager;
|
||||
private TimeSystem _timeSystem;
|
||||
private InGameMouseHandler _gameMouseHandler;
|
||||
|
||||
public InputSystem Input => _inputSystem;
|
||||
public SceneManager Scene => _sceneManager;
|
||||
@@ -26,7 +29,7 @@ public class GameManager : MonoBehaviour
|
||||
_inputSystem = new InputSystem();
|
||||
_sceneManager = new SceneManager();
|
||||
_timeSystem = new TimeSystem();
|
||||
|
||||
_gameMouseHandler = new InGameMouseHandler(_cameraSystem.MainCamera);
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
@@ -34,6 +37,7 @@ public class GameManager : MonoBehaviour
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
_gameMouseHandler.Dispose();
|
||||
_inputSystem.Disable();
|
||||
}
|
||||
|
||||
@@ -51,6 +55,7 @@ public class GameManager : MonoBehaviour
|
||||
{
|
||||
if (!_isPause)
|
||||
{
|
||||
_gameMouseHandler.Update();
|
||||
_timeSystem.UpdateTime();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 });
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcf28888027a4ab4ba2df2a33b89899e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
guid: dcf28888027a4ab4ba2df2a33b89899e
|
||||
@@ -1,11 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fbda389b6a6aec14997efc4be22664e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
guid: fbda389b6a6aec14997efc4be22664e7
|
||||
@@ -9,12 +9,9 @@ public class TimeSystem
|
||||
public Action OnMinuteChanged;
|
||||
public Action OnFastForwardEnd;
|
||||
|
||||
[SerializeField]
|
||||
private TimeSpan _startTime = new TimeSpan(1, 08, 00, 00);
|
||||
|
||||
[SerializeField]
|
||||
private float _sunriseHour;
|
||||
[SerializeField]
|
||||
private float _sunsetHour;
|
||||
|
||||
private TimeSpan _sunriseTime;
|
||||
|
||||
@@ -1,11 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00bbfcf5f7cdbb543bd6e09cd773f199
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
guid: 00bbfcf5f7cdbb543bd6e09cd773f199
|
||||
@@ -1,11 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a49cd67cb3095a74d9b654426bc046b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
guid: a49cd67cb3095a74d9b654426bc046b6
|
||||
Reference in New Issue
Block a user