Skip to content

Commit

Permalink
Implement GUI controls via XInput (fixes #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eusth committed Apr 23, 2017
1 parent 1d2e2a8 commit 4f3956b
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 76 deletions.
Binary file added Libs/XInputDotNetPure.dll
Binary file not shown.
Binary file added VookaRaylee/Libs/XInputInterface.dll
Binary file not shown.
99 changes: 99 additions & 0 deletions VookaRaylee/RayleeControls.cs
@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using VRGIN.Core;
using XInputDotNetPure;

namespace VookaRaylee
{


class RayleeControls : ProtectedBehaviour
{
private GamePadState? _PrevState;
private const string TRIGGER = "Joy1Axis3";

private const string DPADX = "Joy1Axis6";
private const string DPADY = "Joy1Axis7";
private const KeyCode RIGHT_STICK = KeyCode.Joystick1Button9;

private float? _RightStickPressTime = null;
private const float TIME_TO_RECENTER = 1.5f;

protected override void OnUpdate()
{
base.OnUpdate();
var state = GamePad.GetState(PlayerIndex.One);
var state2 = GamePad.GetState(PlayerIndex.Two);
var state3 = GamePad.GetState(PlayerIndex.Three);
var state4 = GamePad.GetState(PlayerIndex.Four);

bool thumbStickPressed = state.Buttons.RightStick == ButtonState.Pressed;

if (state.Triggers.Left > 0.5f || state.Triggers.Right > 0.5f)
{
if (state.DPad.Up == ButtonState.Pressed) HandlePressUp(state.Triggers.Left <= 0.5f);
else if (state.DPad.Down == ButtonState.Pressed) HandlePressDown(state.Triggers.Left <= 0.5f);
if (state.DPad.Right == ButtonState.Pressed) HandlePressRight();
else if (state.DPad.Left == ButtonState.Pressed) HandlePressLeft();
}

if (thumbStickPressed)
{
if (_RightStickPressTime == null)
{
_RightStickPressTime = Time.time;
}
if (Time.time - _RightStickPressTime > TIME_TO_RECENTER)
{
(VR.Mode as VookaSeatedMode).Recenter();
_RightStickPressTime = null;
}
}
else
{
_RightStickPressTime = null;
}

_PrevState = state;
}

private void HandlePressLeft()
{

VR.Settings.Rotation -= Time.deltaTime * 90;
}

private void HandlePressRight()
{
VR.Settings.Rotation += Time.deltaTime * 90;
}

private void HandlePressUp(bool alternativeMode)
{
if (alternativeMode)
{
VR.Settings.Distance += Time.deltaTime * 0.5f;
}
else
{
VR.Settings.OffsetY += Time.deltaTime * 0.5f;
}
}

private void HandlePressDown(bool alternativeMode)
{
if (alternativeMode)
{
VR.Settings.Distance -= Time.deltaTime * 0.5f;
}
else
{
VR.Settings.OffsetY -= Time.deltaTime * 0.5f;

}
}
}
}
78 changes: 4 additions & 74 deletions VookaRaylee/RayleeInterpreter.cs
Expand Up @@ -3,20 +3,15 @@
using System.Linq;
using UnityEngine;
using VRGIN.Core;
using XInputDotNetPure;

namespace VookaRaylee
{
public class RayleeInterpreter : GameInterpreter
{
private readonly string[] FX_BLACKLIST = new string[] { "DepthOfField" };
private const string TRIGGER = "Joy1Axis3";


private const string DPADX = "Joy1Axis6";
private const string DPADY = "Joy1Axis7";
private const KeyCode RIGHT_STICK = KeyCode.Joystick1Button9;

private float? _RightStickPressTime = null;
private const float TIME_TO_RECENTER = 1.5f;

// Not used
public override IEnumerable<IActor> Actors
Expand All @@ -39,72 +34,7 @@ public override bool IsAllowedEffect(MonoBehaviour effect)
{
return !FX_BLACKLIST.Contains(effect.GetType().Name) && base.IsAllowedEffect(effect);
}

protected override void OnUpdate()
{
base.OnUpdate();

float trigger = Input.GetAxisRaw(TRIGGER);
float yPress = Input.GetAxisRaw(DPADY);
float xPress = Input.GetAxisRaw(DPADX);

if (Mathf.Abs(trigger) > 0.5f)
{
if (yPress > 0.5f) HandlePressUp(trigger < 0);
else if (yPress < -0.5f) HandlePressDown(trigger < 0);
if (xPress > 0.5f) HandlePressRight();
else if (xPress < -0.5f) HandlePressLeft();
}

if(Input.GetKeyDown(RIGHT_STICK))
{
_RightStickPressTime = Time.time;
}
if(Input.GetKeyUp(RIGHT_STICK))
{
_RightStickPressTime = null;
}
if(_RightStickPressTime != null && Time.time - _RightStickPressTime > TIME_TO_RECENTER)
{
(VR.Mode as VookaSeatedMode).Recenter();
_RightStickPressTime = null;
}
}

private void HandlePressLeft()
{

VR.Settings.Rotation -= Time.deltaTime * 90;
}

private void HandlePressRight()
{
VR.Settings.Rotation += Time.deltaTime * 90;
}

private void HandlePressUp(bool alternativeMode)
{
if (alternativeMode)
{
VR.Settings.Distance += Time.deltaTime * 0.5f;
}
else
{
VR.Settings.OffsetY += Time.deltaTime * 0.5f;
}
}

private void HandlePressDown(bool alternativeMode)
{
if (alternativeMode)
{
VR.Settings.Distance -= Time.deltaTime * 0.5f;
}
else
{
VR.Settings.OffsetY -= Time.deltaTime * 0.5f;

}
}

}

}
11 changes: 9 additions & 2 deletions VookaRaylee/VookaRaylee.csproj
Expand Up @@ -47,17 +47,19 @@
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\VRGIN\Libs\Unity 5.3.4\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="XInputDotNetPure">
<HintPath>..\Libs\XInputDotNetPure.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RayleeControls.cs" />
<Compile Include="RayleeInterpreter.cs" />
<Compile Include="RayleeSettings.cs" />
<Compile Include="VookaContext.cs" />
Expand All @@ -70,6 +72,11 @@
<Name>VRGIN</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Libs\XInputInterface.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
2 changes: 2 additions & 0 deletions VookaRaylee/VookaSeatedMode.cs
Expand Up @@ -24,6 +24,8 @@ protected override void OnStart()
{
InstallVignetting();
}

gameObject.AddComponent<RayleeControls>();
}

private void InstallVignetting()
Expand Down

0 comments on commit 4f3956b

Please sign in to comment.