Skip to content

Commit

Permalink
modify code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecomi committed Mar 13, 2018
1 parent e5236a9 commit f1b533d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 38 deletions.
6 changes: 4 additions & 2 deletions Assets/VrGrabber/Scripts/VrgIDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace VrGrabber
{

public enum ControllerSide {
public enum ControllerSide
{
Left,
Right,
}

public interface IDevice {
public interface IDevice
{
Vector3 GetLocalPosition(ControllerSide side);
Quaternion GetLocalRotation(ControllerSide side);
float GetHold(ControllerSide side);
Expand Down
10 changes: 5 additions & 5 deletions Assets/VrGrabber/Scripts/VrgNodeTracker.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
using UnityEngine.XR;

public class VrgNodeTracker : MonoBehaviour {
public class VrgNodeTracker : MonoBehaviour
{
[SerializeField]
XRNode node = XRNode.LeftHand;

private void Update() {
void Update()
{
transform.SetPositionAndRotation(InputTracking.GetLocalPosition(node), InputTracking.GetLocalRotation(node));
}
}
24 changes: 16 additions & 8 deletions Assets/VrGrabber/Scripts/VrgOculusTouchDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,42 @@
namespace VrGrabber
{

public class VrgOculusTouchDevice : IDevice {
private OVRInput.Controller GetOVRController(ControllerSide side) {
public class VrgOculusTouchDevice : IDevice
{
private OVRInput.Controller GetOVRController(ControllerSide side)
{
return (side == ControllerSide.Left) ?
OVRInput.Controller.LTouch :
OVRInput.Controller.RTouch;
}

public Vector3 GetLocalPosition(ControllerSide side) {
public Vector3 GetLocalPosition(ControllerSide side)
{
return OVRInput.GetLocalControllerPosition(GetOVRController(side));
}

public Quaternion GetLocalRotation(ControllerSide side) {
public Quaternion GetLocalRotation(ControllerSide side)
{
return OVRInput.GetLocalControllerRotation(GetOVRController(side));
}

public float GetHold(ControllerSide side) {
public float GetHold(ControllerSide side)
{
return OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, GetOVRController(side));
}

public bool GetHover(ControllerSide side) {
public bool GetHover(ControllerSide side)
{
return OVRInput.Get(OVRInput.Touch.PrimaryThumbstick, GetOVRController(side));
}

public bool GetClick(ControllerSide side) {
public bool GetClick(ControllerSide side)
{
return OVRInput.Get(OVRInput.Button.PrimaryThumbstick, GetOVRController(side));
}

public Vector2 GetCoord(ControllerSide side) {
public Vector2 GetCoord(ControllerSide side)
{
return OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, GetOVRController(side));
}
}
Expand Down
63 changes: 40 additions & 23 deletions Assets/VrGrabber/Scripts/VrgWinMRMotionControllerDevice.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using System;
using UnityEngine;
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.XR.WSA.Input;

namespace VrGrabber
{

public class VrgWinMRMotionControllerDevice : IDevice {
public bool GetClick(ControllerSide side) {
switch (side) {
public class VrgWinMRMotionControllerDevice : IDevice
{
public bool GetClick(ControllerSide side)
{
switch (side)
{
case ControllerSide.Left:
return Input.GetKey(KeyCode.JoystickButton16);
case ControllerSide.Right:
Expand All @@ -18,34 +20,45 @@ public bool GetClick(ControllerSide side) {
}
}

public Vector2 GetCoord(ControllerSide side) {
public Vector2 GetCoord(ControllerSide side)
{
var interactionStates = InteractionManager.GetCurrentReading();
foreach (var state in interactionStates) {
if (side == ControllerSide.Left && state.source.handedness == InteractionSourceHandedness.Left
|| side == ControllerSide.Right && state.source.handedness == InteractionSourceHandedness.Right) {
foreach (var state in interactionStates)
{
if (side == ControllerSide.Left && state.source.handedness == InteractionSourceHandedness.Left ||
side == ControllerSide.Right && state.source.handedness == InteractionSourceHandedness.Right)
{
return state.touchpadPosition;
}
}
return Vector2.zero;
}

public float GetHold(ControllerSide side) {
public float GetHold(ControllerSide side)
{
var interactionStates = InteractionManager.GetCurrentReading();
foreach (var state in interactionStates) {
if (side == ControllerSide.Left && state.source.handedness == InteractionSourceHandedness.Left
|| side == ControllerSide.Right && state.source.handedness == InteractionSourceHandedness.Right) {
if (state.grasped) {
return 1.0f;
} else {
return 0.0f;
foreach (var state in interactionStates)
{
if (side == ControllerSide.Left && state.source.handedness == InteractionSourceHandedness.Left ||
side == ControllerSide.Right && state.source.handedness == InteractionSourceHandedness.Right)
{
if (state.grasped)
{
return 1f;
}
else
{
return 0f;
}
}
}
return 0.0f;
}

public bool GetHover(ControllerSide side) {
switch (side) {
public bool GetHover(ControllerSide side)
{
switch (side)
{
case ControllerSide.Left:
return Input.GetKey(KeyCode.JoystickButton18);
case ControllerSide.Right:
Expand All @@ -55,8 +68,10 @@ public bool GetHover(ControllerSide side) {
}
}

public Vector3 GetLocalPosition(ControllerSide side) {
switch (side) {
public Vector3 GetLocalPosition(ControllerSide side)
{
switch (side)
{
case ControllerSide.Left:
return InputTracking.GetLocalPosition(XRNode.LeftHand);
case ControllerSide.Right:
Expand All @@ -66,8 +81,10 @@ public Vector3 GetLocalPosition(ControllerSide side) {
}
}

public Quaternion GetLocalRotation(ControllerSide side) {
switch (side) {
public Quaternion GetLocalRotation(ControllerSide side)
{
switch (side)
{
case ControllerSide.Left:
return InputTracking.GetLocalRotation(XRNode.LeftHand);
case ControllerSide.Right:
Expand Down

0 comments on commit f1b533d

Please sign in to comment.