Add mouse sensitivity cvar, devconfig.cfg
This commit is contained in:
@@ -12,6 +12,9 @@ public class CameraMovement : Script
|
|||||||
[Tooltip("Camera speed")]
|
[Tooltip("Camera speed")]
|
||||||
public float MoveSpeed { get; set; } = 400;
|
public float MoveSpeed { get; set; } = 400;
|
||||||
|
|
||||||
|
[ConsoleVariable("sensitivity")]
|
||||||
|
public static float Sensitivity;
|
||||||
|
|
||||||
public override void OnStart()
|
public override void OnStart()
|
||||||
{
|
{
|
||||||
Float3 initialEulerAngles = Actor.Orientation.EulerAngles;
|
Float3 initialEulerAngles = Actor.Orientation.EulerAngles;
|
||||||
@@ -26,8 +29,8 @@ public class CameraMovement : Script
|
|||||||
Actor rootActor = Actor.GetChild(0);
|
Actor rootActor = Actor.GetChild(0);
|
||||||
Camera camera = rootActor.GetChild<Camera>();
|
Camera camera = rootActor.GetChild<Camera>();
|
||||||
|
|
||||||
float xAxis = Input.GetAxisRaw("Mouse X");
|
float xAxis = Input.GetAxisRaw("Mouse X") * Sensitivity;
|
||||||
float yAxis = Input.GetAxisRaw("Mouse Y");
|
float yAxis = Input.GetAxisRaw("Mouse Y") * Sensitivity;
|
||||||
if (xAxis != 0.0f || yAxis != 0.0f)
|
if (xAxis != 0.0f || yAxis != 0.0f)
|
||||||
{
|
{
|
||||||
viewPitch += yAxis;
|
viewPitch += yAxis;
|
||||||
|
|||||||
@@ -27,4 +27,22 @@ public class Config
|
|||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Merge(Config config)
|
||||||
|
{
|
||||||
|
if (config.dictionary.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (var kvp in config.dictionary)
|
||||||
|
{
|
||||||
|
if (dictionary.TryGetValue(kvp.Key, out string oldValue))
|
||||||
|
{
|
||||||
|
if (oldValue == kvp.Value)
|
||||||
|
continue;
|
||||||
|
dictionary[kvp.Key] = kvp.Value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
dictionary.Add(kvp.Key, kvp.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -68,8 +68,9 @@ public class ConsolePlugin : GamePlugin
|
|||||||
|
|
||||||
private void LoadConfig()
|
private void LoadConfig()
|
||||||
{
|
{
|
||||||
Console.Print("Loading config file (GamePlugin)");
|
//Console.Print("Loading config file (GamePlugin)");
|
||||||
AssetManager.Globals.ResetValues();
|
AssetManager.Globals.ResetValues();
|
||||||
|
AssetManager.LoadConfigurationFiles();
|
||||||
|
|
||||||
foreach (var line in AssetManager.Config.GetLines())
|
foreach (var line in AssetManager.Config.GetLines())
|
||||||
Console.Execute(line, false, true);
|
Console.Execute(line, false, true);
|
||||||
@@ -171,9 +172,10 @@ public class ConsoleEditorPlugin : EditorPlugin
|
|||||||
|
|
||||||
private void LoadConfig()
|
private void LoadConfig()
|
||||||
{
|
{
|
||||||
Console.Print("Loading config file (EditorPlugin)");
|
//Console.Print("Loading config file (EditorPlugin)");
|
||||||
|
|
||||||
AssetManager.Globals.ResetValues();
|
AssetManager.Globals.ResetValues();
|
||||||
|
AssetManager.LoadConfigurationFiles();
|
||||||
|
|
||||||
foreach (var line in AssetManager.Config.GetLines())
|
foreach (var line in AssetManager.Config.GetLines())
|
||||||
Console.Execute(line, false, true);
|
Console.Execute(line, false, true);
|
||||||
|
|||||||
@@ -45,13 +45,18 @@ internal struct ConsoleVariable
|
|||||||
{
|
{
|
||||||
if (field != null)
|
if (field != null)
|
||||||
return (string)field.GetValue(null);
|
return (string)field.GetValue(null);
|
||||||
if (setter != null)
|
if (getter != null)
|
||||||
|
return (string)getter.Invoke(null, null);
|
||||||
|
}
|
||||||
|
else if (type == typeof(float))
|
||||||
|
{
|
||||||
|
if (field != null)
|
||||||
|
return field.GetValue(null).ToString();
|
||||||
|
if (getter != null)
|
||||||
return (string)getter.Invoke(null, null);
|
return (string)getter.Invoke(null, null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
throw new Exception($"Unsupported console variable type '{type.FullName}'");
|
||||||
throw new Exception("cvar is not type of string");
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Exception("GetValueString no field or getter specified");
|
throw new Exception("GetValueString no field or getter specified");
|
||||||
}
|
}
|
||||||
@@ -66,6 +71,15 @@ internal struct ConsoleVariable
|
|||||||
else if (setter != null)
|
else if (setter != null)
|
||||||
setter.Invoke(null, new object[] { value });
|
setter.Invoke(null, new object[] { value });
|
||||||
}
|
}
|
||||||
|
else if (type == typeof(float))
|
||||||
|
{
|
||||||
|
if (!float.TryParse(value, out var floatValue))
|
||||||
|
return;
|
||||||
|
if (field != null)
|
||||||
|
field.SetValue(null, floatValue);
|
||||||
|
else if (setter != null)
|
||||||
|
setter.Invoke(null, new object[] { floatValue });
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new Exception("Unsupported type for SetValue: " + type.Name);
|
throw new Exception("Unsupported type for SetValue: " + type.Name);
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ public class PlayerInput2 : IPlayerInput
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private PlayerInputState2 _recordState;
|
private PlayerInputState2 _recordState;
|
||||||
|
|
||||||
|
[ConsoleVariable("sensitivity")]
|
||||||
|
public static float Sensitivity;
|
||||||
|
|
||||||
public void SetFrame(ulong frame)
|
public void SetFrame(ulong frame)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -60,11 +63,11 @@ public class PlayerInput2 : IPlayerInput
|
|||||||
// or taken with the peak values (axis direction),
|
// or taken with the peak values (axis direction),
|
||||||
// binary values should be OR'ed so triggered action is not lost if button debounces mid-frame.
|
// binary values should be OR'ed so triggered action is not lost if button debounces mid-frame.
|
||||||
|
|
||||||
float sensitivity = 1.0f / 8.0f;
|
//float sensitivity = 1.0f / 8.0f;
|
||||||
sensitivity = 1.0f;
|
//sensitivity = 1.0f;
|
||||||
float turnSpeed = 100.0f;
|
float turnSpeed = 100.0f;
|
||||||
|
|
||||||
_recordState.ViewDelta += new Float2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")) * sensitivity;
|
_recordState.ViewDelta += new Float2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")) * Sensitivity;
|
||||||
_recordState.ViewDelta += new Float2(Input.GetAxisRaw("LookRight"), Input.GetAxisRaw("LookUp")) * Time.DeltaTime * turnSpeed;
|
_recordState.ViewDelta += new Float2(Input.GetAxisRaw("LookRight"), Input.GetAxisRaw("LookUp")) * Time.DeltaTime * turnSpeed;
|
||||||
|
|
||||||
_recordState.MoveForward = MathF.MaxMagnitude(_recordState.MoveForward, Input.GetAxis("Vertical"));
|
_recordState.MoveForward = MathF.MaxMagnitude(_recordState.MoveForward, Input.GetAxis("Vertical"));
|
||||||
|
|||||||
@@ -14,6 +14,14 @@ public static class AssetManager
|
|||||||
public static string CachePath { get; private set; } =
|
public static string CachePath { get; private set; } =
|
||||||
Path.Combine(Directory.GetCurrentDirectory(), "Cache");
|
Path.Combine(Directory.GetCurrentDirectory(), "Cache");
|
||||||
|
|
||||||
|
public static string ConfigFilePath { get; private set; } =
|
||||||
|
Path.Combine(ContentPath, "config.cfg");
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
public static string ConfigDevFilePath { get; private set; } =
|
||||||
|
Path.Combine(ContentPath, "devconfig.cfg");
|
||||||
|
#endif
|
||||||
|
|
||||||
public static GameplayGlobals Globals { get; private set; }
|
public static GameplayGlobals Globals { get; private set; }
|
||||||
public static Config Config { get; private set; }
|
public static Config Config { get; private set; }
|
||||||
|
|
||||||
@@ -21,6 +29,20 @@ public static class AssetManager
|
|||||||
static AssetManager()
|
static AssetManager()
|
||||||
{
|
{
|
||||||
Globals = Content.Load<GameplayGlobals>(Path.Combine(ContentPath, "Settings", "GameSettings", "GameplayGlobals.flax"));
|
Globals = Content.Load<GameplayGlobals>(Path.Combine(ContentPath, "Settings", "GameSettings", "GameplayGlobals.flax"));
|
||||||
Config = ConfigParser.ParseFile(Path.Combine(ContentPath, "config.cfg"));
|
}
|
||||||
|
|
||||||
|
public static void LoadConfigurationFiles()
|
||||||
|
{
|
||||||
|
Config = ConfigParser.ParseFile(ConfigFilePath);
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
if (!File.Exists(ConfigDevFilePath))
|
||||||
|
{
|
||||||
|
File.WriteAllText(ConfigDevFilePath,
|
||||||
|
$"""
|
||||||
|
// Personal configuration file used during development, do not commit this file.
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
Config.Merge(ConfigParser.ParseFile(ConfigDevFilePath));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user