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

Smaller fingertips collider - fixes RasterPropMonitor buttons being unusable #88

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
9 changes: 4 additions & 5 deletions KerbalVR/KerbalVR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>ksp_lib\Assembly-CSharp.dll</HintPath>
<HintPath>..\..\..\..\..\..\GOG Games\Kerbal Space Program\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -40,11 +40,10 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>ksp_lib\UnityEngine.dll</HintPath>
<HintPath>..\..\..\..\..\..\GOG Games\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>ksp_lib\UnityEngine.UI.dll</HintPath>
<Reference Include="UnityEngine.UI">
<HintPath>..\..\..\..\..\..\GOG Games\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
149 changes: 103 additions & 46 deletions KerbalVR/KerbalVR_AppGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,30 @@ namespace KerbalVR
{
public class AppGUI
{
private class TextFieldFloat {
private class TextFieldFloat
{
private string parameterName;
private Action<float> parameterCallback;
private string valueStr;

public TextFieldFloat(string parameterName, float parameter, Action<float> parameterCallback) {
public TextFieldFloat(string parameterName, float parameter, Action<float> parameterCallback)
{
this.parameterName = parameterName;
this.parameterCallback = parameterCallback;
valueStr = parameter.ToString("F3");
}

public void UpdateGUI() {
public void UpdateGUI()
{
GUILayout.BeginHorizontal();
GUILayout.Label(parameterName + ":", HighLogic.Skin.label);
valueStr = GUILayout.TextField(valueStr, HighLogic.Skin.textField);
if (GUI.changed) {
if (GUI.changed)
{
float updatedValue;
bool parseSuccess = System.Single.TryParse(valueStr, out updatedValue);
if (parseSuccess) {
if (parseSuccess)
{
parameterCallback(updatedValue);
}
}
Expand All @@ -35,15 +40,19 @@ public void UpdateGUI() {
}

#region Constants
public static string AppButtonLogo {
get {
public static string AppButtonLogo
{
get
{
string path = Path.Combine(Globals.KERBALVR_TEXTURES_DIR, "app_button_logo");
return path.Replace("\\", "/");
}
}

public static bool SceneAllowsAppGUI {
get {
public static bool SceneAllowsAppGUI
{
get
{
return (
#if DEBUG
(HighLogic.LoadedScene == GameScenes.MAINMENU) ||
Expand Down Expand Up @@ -93,7 +102,8 @@ public static bool SceneAllowsAppGUI {
/// application launcher. Note that this callback can be called multiple times
/// throughout the game.
/// </summary>
public void OnAppLauncherReady() {
public void OnAppLauncherReady()
{
// define where should the app button be visible

/*
Expand All @@ -107,7 +117,8 @@ public void OnAppLauncherReady() {
*/

// create new app button instance if it doesn't already exist
if (appButton == null) {
if (appButton == null)
{

// init variables
worldScaleStr = Scene.Instance.WorldScale.ToString("F1");
Expand All @@ -128,11 +139,13 @@ public void OnAppLauncherReady() {
}
}

void OnShow() {
void OnShow()
{
appButtonGuiActive = appButtonGuiActiveLastState;
}

void OnHide() {
void OnHide()
{
appButtonGuiActiveLastState = appButtonGuiActive;
appButtonGuiActive = false;
}
Expand All @@ -142,8 +155,10 @@ void OnHide() {
/// at the time the plugin is loaded. It destroys the application button on the
/// application launcher.
/// </summary>
public void OnAppLauncherDestroyed() {
if (appButton != null) {
public void OnAppLauncherDestroyed()
{
if (appButton != null)
{
OnToggleFalse();
ApplicationLauncher.Instance.RemoveApplication(appButton);
ApplicationLauncher.Instance.RemoveOnShowCallback(OnShow);
Expand All @@ -154,19 +169,23 @@ public void OnAppLauncherDestroyed() {
/// <summary>
/// Callback when the application button is toggled on.
/// </summary>
public void OnToggleTrue() {
public void OnToggleTrue()
{
appButtonGuiActive = true;
}

/// <summary>
/// Callback when the application button is toggled off.
/// </summary>
public void OnToggleFalse() {
public void OnToggleFalse()
{
appButtonGuiActive = false;
}

public void OnGUI() {
if (SceneAllowsAppGUI && appButtonGuiActive) {
public void OnGUI()
{
if (SceneAllowsAppGUI && appButtonGuiActive)
{
appGuiWindowRect = GUILayout.Window(
APP_GUI_ID,
appGuiWindowRect,
Expand All @@ -176,20 +195,23 @@ public void OnGUI() {
}
}

private void GenerateGUI(int windowId) {
private void GenerateGUI(int windowId)
{
string buttonStringToggleVr = BUTTON_STRING_ENABLE_VR;
string labelStringVrActive = LABEL_STRING_VR_INACTIVE;
string buttonStringToggleMirror = BUTTON_STRING_ENABLE_MIRROR;
GUIStyle labelStyleVrActive = new GUIStyle(HighLogic.Skin.label);
labelStyleVrActive.normal.textColor = Color.red;

if (Core.HmdIsRunning) {
if (Core.HmdIsRunning)
{
buttonStringToggleVr = BUTTON_STRING_DISABLE_VR;
labelStringVrActive = LABEL_STRING_VR_ACTIVE;
labelStyleVrActive.normal.textColor = Color.green;
}

if (Core.RenderHmdToScreen) {
if (Core.RenderHmdToScreen)
{
buttonStringToggleMirror = BUTTON_STRING_DISABLE_MIRROR;
}

Expand All @@ -198,25 +220,36 @@ private void GenerateGUI(int windowId) {
// VR toggle button
//------------------------------------------------------------------
UnityEngine.GUI.enabled = Scene.Instance.SceneAllowsVR();
if (GUILayout.Button(buttonStringToggleVr, HighLogic.Skin.button)) {
if (Core.HmdIsEnabled) {
if (GUILayout.Button(buttonStringToggleVr, HighLogic.Skin.button))
{
if (Core.HmdIsEnabled)
{
Core.HmdIsEnabled = false;
} else {
}
else
{
Core.HmdIsEnabled = true;
}
}

if (Core.CanResetSeatedPose()) {
if (GUILayout.Button("Reset Headset Position", HighLogic.Skin.button)) {
if (Core.CanResetSeatedPose())
{
if (GUILayout.Button("Reset Headset Position", HighLogic.Skin.button))
{
Core.ResetInitialHmdPosition();
}
}

if (Core.HmdIsRunning) {
if (GUILayout.Button(buttonStringToggleMirror, HighLogic.Skin.button)) {
if (Core.RenderHmdToScreen) {
if (Core.HmdIsRunning)
{
if (GUILayout.Button(buttonStringToggleMirror, HighLogic.Skin.button))
{
if (Core.RenderHmdToScreen)
{
Core.RenderHmdToScreen = false;
} else {
}
else
{
Core.RenderHmdToScreen = true;
}
}
Expand All @@ -240,17 +273,37 @@ private void GenerateGUI(int windowId) {
#if DEBUG
GUILayout.BeginHorizontal();
GUILayout.Label("Hand Size:", HighLogic.Skin.label);
int handSizeScale = (int)(DeviceManager.Instance.ManipulatorSize * 100f + 0.5f);
string handSizeStr = handSizeScale.ToString();
handSizeStr = GUILayout.TextField(handSizeStr, HighLogic.Skin.textField);
if (GUI.changed) {
bool parseSuccess = System.Int32.TryParse(handSizeStr, out handSizeScale);
if (parseSuccess &&
handSizeScale >= 1 &&
handSizeScale <= 100) {
DeviceManager.Instance.ManipulatorSize = handSizeScale * 0.01f;
} else {
DeviceManager.Instance.ManipulatorSize = 0.45f;
int handSizeScaleLeft = (int)(DeviceManager.Instance.ManipulatorLeft.ManipulatorSize * 100f + 0.5f);
int handSizeScaleRight = (int)(DeviceManager.Instance.ManipulatorRight.ManipulatorSize * 100f + 0.5f);
string handSizeStrLeft = handSizeScaleLeft.ToString();
string handSizeStrRight = handSizeScaleRight.ToString();
handSizeStrLeft = GUILayout.TextField(handSizeStrLeft, HighLogic.Skin.textField);
handSizeStrRight = GUILayout.TextField(handSizeStrRight, HighLogic.Skin.textField);
if (GUI.changed)
{
bool parseSuccessLeft = System.Int32.TryParse(handSizeStrLeft, out handSizeScaleLeft);
bool parseSuccessRight = System.Int32.TryParse(handSizeStrRight, out handSizeScaleRight);

if (parseSuccessLeft &&
handSizeScaleLeft >= 1 &&
handSizeScaleLeft <= 100)
{
DeviceManager.Instance.ManipulatorLeft.ManipulatorSize = handSizeScaleLeft * 0.01f;
}
else
{
DeviceManager.Instance.ManipulatorLeft.ManipulatorSize = 0.45f;
}

if (parseSuccessRight &&
handSizeScaleRight >= 1 &&
handSizeScaleRight <= 100)
{
DeviceManager.Instance.ManipulatorRight.ManipulatorSize = handSizeScaleRight * 0.01f;
}
else
{
DeviceManager.Instance.ManipulatorRight.ManipulatorSize = 0.45f;
}
}
GUILayout.EndHorizontal();
Expand All @@ -260,12 +313,14 @@ private void GenerateGUI(int windowId) {
GUILayout.BeginHorizontal();
GUILayout.Label("World Scale:", HighLogic.Skin.label);
worldScaleStr = GUILayout.TextField(worldScaleStr, HighLogic.Skin.textField);
if (GUI.changed) {
if (GUI.changed)
{
float worldScale;
bool parseSuccess = System.Single.TryParse(worldScaleStr, out worldScale);
if (parseSuccess &&
worldScale >= 0.1 &&
worldScale <= 10) {
worldScale <= 10)
{
Scene.Instance.WorldScale = worldScale;
}
}
Expand All @@ -274,15 +329,17 @@ private void GenerateGUI(int windowId) {
// init at startup toggle
GUILayout.BeginHorizontal();
bool initOpenVrAtStartup = GUILayout.Toggle(Configuration.Instance.InitOpenVrAtStartup, "Init OpenVR at startup", HighLogic.Skin.toggle);
if (GUI.changed) {
if (GUI.changed)
{
Configuration.Instance.InitOpenVrAtStartup = initOpenVrAtStartup;
}
GUILayout.EndHorizontal();

// swap control stick yaw and roll
GUILayout.BeginHorizontal();
bool swapYawRollControls = GUILayout.Toggle(Configuration.Instance.SwapYawRollControls, "Swap Yaw/Roll Controls", HighLogic.Skin.toggle);
if (GUI.changed) {
if (GUI.changed)
{
Configuration.Instance.SwapYawRollControls = swapYawRollControls;
}
GUILayout.EndHorizontal();
Expand Down
6 changes: 6 additions & 0 deletions KerbalVR/KerbalVR_Manipulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class Manipulator : MonoBehaviour
public SteamVR_Controller.Device State { get; private set; }
public Vector3 GripPosition { get; private set; }

// if this is 0.66, then the fingertip's collider will be only 66% as big as the glove's model original fingertip sphere collider. 1.0 keeps the original size.
private float _overrideFingertipScale = 0.66f;

// Manipulator object properties
private float _manipulatorSize = 0.45f;
public float ManipulatorSize {
Expand Down Expand Up @@ -95,6 +98,9 @@ protected void LoadManipulatorRenderGameObject() {
}
fingertipCollider = colliderObject.GetComponent<SphereCollider>();

// Reduce the size of the finger tip to avoid butterfingers on the square buttons around RasterPropMonitor (the regular fingerTip's sphere clicks 3 at once).
fingertipCollider.transform.localScale = _overrideFingertipScale * fingertipCollider.transform.localScale;

colliderObject = gloveGameObject.transform.Find("HandDummy/Arm Bone L/Wrist Bone L");
if (colliderObject == null) {
Utils.LogWarning("Manipulator is missing grip collider child object");
Expand Down
Binary file not shown.
Binary file added KerbalVR/Library/AnnotationManager
Binary file not shown.
1 change: 1 addition & 0 deletions KerbalVR/Library/AssetImportState
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
19;0;4;0;0
Empty file.
Binary file added KerbalVR/Library/BuildSettings.asset
Binary file not shown.
Loading