Completed InputManager refactor

Separate InputManager from CameraController
InputManager is one, consolidated input handling object
CameraController provides an interface for keystrokes & mouse movements detected/handled by InputManager
more-targets
Daniel Lovell 2024-09-23 22:00:18 -07:00
parent 3b64fc9f2b
commit aab46e4d39
4 changed files with 154 additions and 164 deletions

View File

@ -159,12 +159,12 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 17322847}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_Father: {fileID: 1457077473}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &61846315
GameObject:
@ -734,12 +734,12 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 253946925}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.12123265, y: 0.17553951, z: -8.531889}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_Father: {fileID: 1457077473}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &320210793
GameObject:
@ -753,7 +753,7 @@ GameObject:
- component: {fileID: 320210797}
- component: {fileID: 320210796}
- component: {fileID: 320210795}
m_Layer: 0
m_Layer: 6
m_Name: Floor
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -1677,30 +1677,29 @@ MonoBehaviour:
m_GameObject: {fileID: 963194225}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6a028bd12cca23f45a9eeb9fb0c4d1f1, type: 3}
m_Script: {fileID: 11500000, guid: b9e222cf9df32df4196f08036d68d740, type: 3}
m_Name:
m_EditorClassIdentifier:
mouseActive: 1
autoplayCamSpeed: 2
xAutoRotateTime: 5
yAutoRotateTime: 5
lockUserInput: 0
_cameraSpeedNormal: 100
_cameraSpeedMax: 1000
_speedH: 2
_speedV: 2
autoRotate: 0
_speedH: 1
_speedV: 1
_autoRotate: 0
target: {fileID: 1255004942}
targetRenderer: {fileID: 1255004940}
floorRenderer: {fileID: 394856875}
matAlpha: 0
orbitDistance: 5000
orbitXSpeed: 0.1
orbitYSpeed: 0.1
_orbitDistance: 5
_orbitXSpeed: 0.1
_orbitYSpeed: 0.1
_zoomSpeed: 5
orbitYMinLimit: -20
orbitYMaxLimit: 80
orbitDistanceMin: 10
orbitDistanceMax: 10000
targetRenderer: {fileID: 1255004940}
floorRenderer: {fileID: 320210796}
matAlpha: 0
autoplayCamSpeed: 2
xAutoRotateTime: 5
yAutoRotateTime: 5
forwardToCameraAngle: 0
--- !u!1 &986996500
GameObject:
@ -1875,6 +1874,52 @@ MeshRenderer:
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!1 &1036072789
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1036072790}
- component: {fileID: 1036072791}
m_Layer: 0
m_Name: InputManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1036072790
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1036072789}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 1715.5709, y: 1660.0452, z: 811.7122}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1457077473}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1036072791
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1036072789}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6a028bd12cca23f45a9eeb9fb0c4d1f1, type: 3}
m_Name:
m_EditorClassIdentifier:
mouseActive: 1
lockUserInput: 0
--- !u!1 &1254435375
GameObject:
m_ObjectHideFlags: 0
@ -2268,6 +2313,40 @@ MeshRenderer:
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!1 &1457077472
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1457077473}
m_Layer: 0
m_Name: Managers
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1457077473
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1457077472}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 253946927}
- {fileID: 1036072790}
- {fileID: 17322849}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1658847972
GameObject:
m_ObjectHideFlags: 0
@ -2622,8 +2701,7 @@ SceneRoots:
- {fileID: 963194228}
- {fileID: 705507995}
- {fileID: 674567085}
- {fileID: 253946927}
- {fileID: 2052906806}
- {fileID: 17322849}
- {fileID: 1255004942}
- {fileID: 564968303}
- {fileID: 1457077473}

View File

@ -18,18 +18,8 @@ public class InputManager : MonoBehaviour
public Quaternion rotation;
}
public float autoplayCamSpeed = 2f;
public float xAutoRotateTime = 5f;
public float yAutoRotateTime = 5f;
private Coroutine autoplayRoutine;
public bool lockUserInput = false;
private float _yaw = 0.0f;
private float _pitch = 0.0f;
private float reloadModifier;
private void Awake()
{
@ -92,13 +82,11 @@ public class InputManager : MonoBehaviour
HandleMouseInput();
if (Input.GetKey(KeyCode.LeftShift))
{
reloadModifier = -.1f;
_cameraSpeed = _cameraSpeedMax;
CameraController.Instance.SetCameraSpeed(CameraController.Instance.GetCameraSpeedMax());
}
else
{
reloadModifier = .1f;
_cameraSpeed = _cameraSpeedNormal;
CameraController.Instance.SetCameraSpeed(CameraController.Instance.GetCameraSpeedNormal());
}
// TRANSLATIONAL MOVEMENT
@ -152,15 +140,7 @@ public class InputManager : MonoBehaviour
if (Input.GetKeyDown(KeyCode.P))
{
autoRotate = !autoRotate;
if (autoRotate)
{
autoplayRoutine = StartCoroutine(AutoPlayRoutine());
}
else
{
StopCoroutine( autoplayRoutine );
}
CameraController.Instance.SetAutoRotate(!CameraController.Instance.IsAutoRotate());
}
if (Input.GetKeyDown(KeyCode.Alpha1))

View File

@ -67,7 +67,7 @@ public class CameraController : MonoBehaviour
/// <summary>
/// Determines if the camera should auto-rotate.
/// </summary>
public bool autoRotate = false;
public bool _autoRotate = false;
/// <summary>
/// Target transform for orbit rotation.
@ -239,6 +239,37 @@ public class CameraController : MonoBehaviour
_yaw = rotation.eulerAngles.y;
}
public void SetCameraSpeed(float speed)
{
_cameraSpeed = speed;
}
public float GetCameraSpeedMax()
{
return _cameraSpeedMax;
}
public float GetCameraSpeedNormal()
{
return _cameraSpeedNormal;
}
public bool IsAutoRotate()
{
return _autoRotate;
}
public void SetAutoRotate(bool autoRotate)
{
if (autoRotate && !_autoRotate) {
_autoRotate = true;
autoplayRoutine = StartCoroutine(AutoPlayRoutine());
} else if (!autoRotate && _autoRotate) {
_autoRotate = false;
StopCoroutine(autoplayRoutine);
}
}
public static float ClampAngle(float angle, float min, float max)
{
if (angle < -360F)
@ -282,6 +313,7 @@ public class CameraController : MonoBehaviour
_orbitY = angles.x;
UpdateTargetAlpha();
ResetCameraTarget();
}
IEnumerator AutoPlayRoutine()
@ -410,31 +442,31 @@ public class CameraController : MonoBehaviour
if(forwardToCameraAngle >-45f && forwardToCameraAngle <= 45f)
{
wVector = Vector3.forward;
aVector = Vector3.left;
sVector = Vector3.back;
dVector = Vector3.right;
_translationInputToVectorMap[TranslationInput.Forward] = Vector3.forward;
_translationInputToVectorMap[TranslationInput.Left] = Vector3.left;
_translationInputToVectorMap[TranslationInput.Back] = Vector3.back;
_translationInputToVectorMap[TranslationInput.Right] = Vector3.right;
}
else if(forwardToCameraAngle > 45f && forwardToCameraAngle <= 135f)
{
wVector = Vector3.left;
aVector = Vector3.back;
sVector = Vector3.right;
dVector = Vector3.forward;
_translationInputToVectorMap[TranslationInput.Forward] = Vector3.left;
_translationInputToVectorMap[TranslationInput.Left] = Vector3.back;
_translationInputToVectorMap[TranslationInput.Back] = Vector3.right;
_translationInputToVectorMap[TranslationInput.Right] = Vector3.forward;
}
else if(forwardToCameraAngle > 135f || forwardToCameraAngle <= -135f)
{
wVector = Vector3.back;
aVector = Vector3.right;
sVector = Vector3.forward;
dVector = Vector3.left;
_translationInputToVectorMap[TranslationInput.Forward] = Vector3.back;
_translationInputToVectorMap[TranslationInput.Left] = Vector3.right;
_translationInputToVectorMap[TranslationInput.Back] = Vector3.forward;
_translationInputToVectorMap[TranslationInput.Right] = Vector3.left;
}
else if(forwardToCameraAngle > -135f && forwardToCameraAngle <= -45f)
{
wVector = Vector3.right;
aVector = Vector3.forward;
sVector = Vector3.left;
dVector = Vector3.back;
_translationInputToVectorMap[TranslationInput.Forward] = Vector3.right;
_translationInputToVectorMap[TranslationInput.Left] = Vector3.forward;
_translationInputToVectorMap[TranslationInput.Back] = Vector3.left;
_translationInputToVectorMap[TranslationInput.Right] = Vector3.back;
}
}
@ -448,110 +480,10 @@ public class CameraController : MonoBehaviour
Down
}
public void TranslateCamera(TranslationInput input) {
UpdateDirectionVectors();
target.Translate(_translationInputToVectorMap[input] * Time.unscaledDeltaTime * _cameraSpeed);
UpdateCamPosition(_orbitX, _orbitY);
}
void HandleLockableInput()
{
if (Input.GetKey(KeyCode.LeftShift))
{
_cameraSpeed = _cameraSpeedMax;
}
else
{
_cameraSpeed = _cameraSpeedNormal;
}
}
void HandleNonLockableInput()
{
if (Input.GetKeyDown(KeyCode.P))
{
autoRotate = !autoRotate;
if (autoRotate)
{
autoplayRoutine = StartCoroutine(AutoPlayRoutine());
}
else
{
StopCoroutine( autoplayRoutine );
}
}
if (Input.GetKeyDown(KeyCode.Alpha1))
{
// ORIGIN
transform.position = new Vector3(0, 20, -20);
SetCameraRotation(Quaternion.Euler(24f, -0.5f, 0));
Camera.main.fieldOfView = 45f;
ResetCameraTarget();
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
transform.position = new Vector3(0, 30, -20);
SetCameraRotation(Quaternion.Euler(36.6f, -0.5f, 0));
Camera.main.fieldOfView = 60f;
ResetCameraTarget();
}
if (Input.GetKeyDown(KeyCode.Alpha4))
{
if (Input.GetKey(KeyCode.LeftShift))
{
fourPos.position = transform.position;
fourPos.rotation = transform.rotation;
}
else
{
transform.position = fourPos.position;
SetCameraRotation(fourPos.rotation);
ResetCameraTarget();
}
}
if (Input.GetKeyDown(KeyCode.Alpha5))
{
if (Input.GetKey(KeyCode.LeftShift))
{
fivePos.position = transform.position;
fivePos.rotation = transform.rotation;
}
else
{
transform.position = fivePos.position;
SetCameraRotation(fivePos.rotation);
ResetCameraTarget();
}
}
if (Input.GetKeyDown(KeyCode.Alpha6))
{
if (Input.GetKey(KeyCode.LeftShift))
{
sixPos.position = transform.position;
sixPos.rotation = transform.rotation;
}
else
{
transform.position = sixPos.position;
SetCameraRotation(sixPos.rotation);
ResetCameraTarget();
}
}
}
}

View File

@ -11,7 +11,7 @@ TagManager:
-
- Water
- UI
-
- Floor
-
-
-