I improved things a lot since before and forgot to post and took a break for a while. I think this is about as good as I’m going to get it without being able to edit Unity’s source code.
Never expected to be getting into this before finishing even a game jam sized game. Some of this stuff is really lacking documentation and took way longer than it should have cause I’ve been in over my head and had to do some kind of hacky stuff. But it works for practical purposes.
In case somebody doesn’t know how to use it: Just put the file in a folder called “Editor” somewhere in your project, it can be a subfolder of something else, and you’ll have new shortcuts you can rebind in Unity. I set the default to Space and Q for this because I doubt many are using what I use (Dvorak’s ESDF equivalent).
Improvements/comments always welcome.
Edit: Note it doesn’t use camera easing or acceleration, I leave them off anyway.
using UnityEngine;
using UnityEditor;
using UnityEditor.ShortcutManagement;
#pragma warning disable IDE0051 // Stop messages about unused functions, they are actually used because of Unity attributes
//todo: speed isn't rite
// it speeds up after being held a bit, even when using a flat constant number like 0.2f (not bad actually, small adjustments slower, moving looking downward works better)
// (still weird though, would like to know why)
//
//cleanup: it recognizes it when holding shift and pressing it, but uses a second shortcut key for it - must be a better way
public class TrueUpAndDown
{
private const float flySpeed = 4.75f; //kind of just arbitrary, adjusts speed compared to other directions to make them close
private const float shiftSpeedMod = 5f; //what unity seems to use for speed when holding shift
private const float fakeDeltaTime = 0.0102051939f; //because making it not fake seems like a pain
[ClutchShortcut("3D Viewport/Fly Mode True Up", typeof(SceneView), KeyCode.Space)] //really lacking documentation on a lot of this stuff
static void FlyModeTrueUp(ShortcutArguments arguments)
{
if ((Tools.viewTool == ViewTool.FPS) && (arguments.stage == ShortcutStage.Begin))
{
SceneView.duringSceneGui += MoveUp;
}
if (arguments.stage == ShortcutStage.End)
{
SceneView.duringSceneGui -= MoveUp;
}
}
[ClutchShortcut("3D Viewport/Fly Mode True Down", typeof(SceneView), KeyCode.Q)]
static void FlyModeTrueDown(ShortcutArguments arguments)
{
if ((Tools.viewTool == ViewTool.FPS) && (arguments.stage == ShortcutStage.Begin))
{
SceneView.duringSceneGui += MoveDown;
}
if (arguments.stage == ShortcutStage.End)
{
SceneView.duringSceneGui -= MoveDown;
}
}
//Just calling the others except these catch it when shift is held first
[ClutchShortcut("3D Viewport/Fly Mode True Up (with shift)", typeof(SceneView), KeyCode.Space, ShortcutModifiers.Shift)]
static void FlyModeTrueUpWithShift(ShortcutArguments arguments)
{
FlyModeTrueUp(arguments);
}
[ClutchShortcut("3D Viewport/Fly Mode True Down (with shift)", typeof(SceneView), KeyCode.Q, ShortcutModifiers.Shift)]
static void FlyModeTrueDownWithShift(ShortcutArguments arguments)
{
FlyModeTrueDown(arguments);
}
static void MoveUp(SceneView view)
{
view.pivot += new Vector3(0, OverallSpeedFormula(view), 0);
}
static void MoveDown(SceneView view)
{
view.pivot += new Vector3(0, -1 * OverallSpeedFormula(view), 0);
}
private static float OverallSpeedFormula(SceneView view)
{
if (Event.current.shift)
return flySpeed * view.cameraSettings.speed * fakeDeltaTime * shiftSpeedMod;
return flySpeed * view.cameraSettings.speed * fakeDeltaTime;
}
}
6156768–672963–TrueUpAndDown.cs (2.99 KB)