Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maroon-568 [Settings] Add Mouse Sensitivity setting #576

Merged
merged 17 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions unity/Assets/Maroon/GlobalEntities/ControlsManager.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using UnityEngine;

namespace Maroon.GlobalEntities.ControlsManager
{
/// <summary>
/// Handles settings related to controls in Maroon.
/// e.g. Mouse sensitivity
/// </summary>
public class ControlsManager : MonoBehaviour, GlobalEntity
{
private static ControlsManager _instance = null;
/// <summary>
/// The ControlsManager instance
/// </summary>
public static ControlsManager Instance => ControlsManager._instance;
MonoBehaviour GlobalEntity.Instance => Instance;


private float _mouseSensitivity = 200f;
/// <summary>
/// The sensitivity of the mouse for first-person controls, e.g. when looking around in the laboratory.
/// </summary>
public float MouseSensitivity
{
get { return _mouseSensitivity; }
set { _mouseSensitivity = value; }
}

/// <summary>
/// Called by Unity. Initializes singleton instance and DontDestroyOnLoad (stays active on new scene load).
/// </summary>
private void Awake()
{
// Singleton
if(ControlsManager._instance == null)
{
ControlsManager._instance = this;
}
else if(ControlsManager._instance != this)
{
DestroyImmediate(this.gameObject);
return;
}

// Keep alive
this.transform.parent = null;
DontDestroyOnLoad(this.gameObject);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4398862966192869678
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4398862966192869714}
- component: {fileID: 641600007337123814}
m_Layer: 0
m_Name: ControlsManager
m_TagString: GlobalEntity
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4398862966192869714
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4398862966192869678}
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: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &641600007337123814
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4398862966192869678}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: de7690d93ceea354f845306e19e07c59, type: 3}
m_Name:
m_EditorClassIdentifier:
_uiPrimary: {fileID: 0}
_uiInfo: {fileID: 0}
_uiSuccess: {fileID: 0}
_uiWarning: {fileID: 0}
_uiDanger: {fileID: 0}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Maroon.GlobalEntities.ControlsManager",
"rootNamespace": "",
"references": [
"GUID:ccf513c02a7c0734f97bf699ec9fcc75"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ MonoBehaviour:
- {fileID: 8818070926525646678, guid: 302b7109c8d10294ca8d00d1afda5596, type: 3}
- {fileID: 33374579202797631, guid: eed70ff69ff3c944583fecc5f1e742fc, type: 3}
- {fileID: 4398862966192869678, guid: cd3a2bbefec729343ae52783e013e3c7, type: 3}
- {fileID: 4398862966192869678, guid: 41d397097d0aec1499082001ad70a5fc, type: 3}
- {fileID: 538104954294960671, guid: 4f28eaf72d62ccd40a9c46f034ecbd5c, type: 3}
- {fileID: 6149192965341415347, guid: 2996bb6600c1de04fb3905aee4d88771, type: 3}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "Maroon.SharedEntities.Player",
"rootNamespace": "",
"references": [
"GUID:20a3f6c7643c02b4f91ee2b86822b6a7",
"GUID:ccf513c02a7c0734f97bf699ec9fcc75",
"GUID:51ec8fffa7eb75940951e2921fd5bff2",
"GUID:e4c75b2556442fb489c9292e2964558b",
"GUID:17647d96bdd7118428d22f6754e5ce23"
"GUID:17647d96bdd7118428d22f6754e5ce23",
"GUID:130981aeffffb874b90f19c27f2ebc7c"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections;
using Maroon.GlobalEntities;
using Maroon.GlobalEntities.ControlsManager;
using UnityEngine;
using UnityEngine.Events;

Expand Down Expand Up @@ -38,8 +39,6 @@ public class ModeFirstPerson : MonoBehaviour
public float killHeight = -50f;

[Header("Rotation")]
[Tooltip("Rotation speed for moving the camera")]
public float rotationSpeed = 200f;
[Range(0.1f, 1f)]
[Tooltip("Rotation speed multiplier when aiming")]
public float aimingRotationMultiplier = 0.4f;
Expand Down Expand Up @@ -225,13 +224,13 @@ void HandleCharacterMovement()
// horizontal character rotation
{
// rotate the transform with the input speed around its local Y axis
transform.Rotate(new Vector3(0f, (m_InputHandler.GetLookInputsHorizontal() * rotationSpeed * RotationMultiplier), 0f), Space.Self);
transform.Rotate(new Vector3(0f, (m_InputHandler.GetLookInputsHorizontal() * ControlsManager.Instance.MouseSensitivity * RotationMultiplier), 0f), Space.Self);
}

// vertical camera rotation
{
// add vertical inputs to the camera's vertical angle
m_CameraVerticalAngle += m_InputHandler.GetLookInputsVertical() * rotationSpeed * RotationMultiplier;
m_CameraVerticalAngle += m_InputHandler.GetLookInputsVertical() * ControlsManager.Instance.MouseSensitivity * RotationMultiplier;

// limit the camera's vertical angle to min/max
m_CameraVerticalAngle = Mathf.Clamp(m_CameraVerticalAngle, -89f, 89f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"GUID:f9b0aa2a96663864693b204ee0977e65",
"GUID:449a0c9cf3915a641858e3bdae6f899e",
"GUID:51ec8fffa7eb75940951e2921fd5bff2",
"GUID:30817c1a0e6d646d99c048fc403f5979",
"GUID:325984b52e4128546bc7558552f8b1d2",
"GUID:130981aeffffb874b90f19c27f2ebc7c",
"GUID:a2847fe8ff68496469df31833d8fdacb",
"GUID:339607d959a71f14eadd1d72a99e0287",
"GUID:5c3ba91dd3f1c8f41a4c009c1e31712a",
Expand Down
Loading
Loading