Open EloiStree opened 5 years ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Rewired_HandsAsJoystick_UI : Rewired_HandsAsJoystick
{
public Slider m_leftHandX;
public Slider m_leftHandY;
public Slider m_leftHandZ;
public Slider m_rightHandX;
public Slider m_rightHandY;
public Slider m_rightHandZ;
public Toggle m_triggerLeft;
public Toggle m_grabbingLeft;
public Toggle m_triggerRight;
public Toggle m_grabbingRight;
protected override float GetAxisInfo(int axisId)
{
switch (axisId)
{
case 0: return m_leftHandX.value;
case 1: return m_leftHandY.value;
case 2: return m_leftHandZ.value;
case 3: return m_rightHandX.value;
case 4: return m_rightHandY.value;
case 5: return m_rightHandZ.value;
default:
return 0f;
}
}
protected override bool GetButtonInfo(int buttonId)
{
switch (buttonId)
{
case 0: return m_triggerLeft.isOn;
case 1: return m_grabbingLeft.isOn;
case 2: return m_triggerRight.isOn;
case 3: return m_grabbingRight.isOn;
default:
return false;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rewired_HandsAsJoystick_OculusGo : Rewired_HandsAsJoystick
{
//https://developer.oculus.com/documentation/unity/latest/concepts/unity-ovrinput/
protected override float GetAxisInfo(int axisId)
{
Vector2 touchAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad);
switch (axisId)
{
case 0: return -Mathf.Abs(touchAxis.x);
case 1: return touchAxis.y;
case 2: return 0f;
case 3: return -Mathf.Abs(touchAxis.x);
case 4: return touchAxis.y;
case 5: return 0f;
default:
return 0f;
}
}
protected override bool GetButtonInfo(int buttonId)
{
switch (buttonId)
{
case 0: return OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger);
case 1: return OVRInput.Get(OVRInput.Button.PrimaryTouchpad);
case 2: return OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger);
case 3: return OVRInput.Get(OVRInput.Button.PrimaryTouchpad);
default:
return false;
}
}
}
using Rewired;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MechaFromRewired : MonoBehaviour
{
public string playerId = "Player";
private Player player;
public float m_speedRotation;
public float m_speedMoving;
void Awake()
{
player = ReInput.players.GetPlayer("Player");
}
// Update is called once per frame
void Update()
{
transform.Rotate(Vector3.up, m_speedRotation * Time.deltaTime * player.GetAxis("Rotate"), Space.Self);
transform.Translate(Vector3.forward * m_speedMoving * Time.deltaTime * player.GetAxis("Move"), Space.Self);
}
}
using Rewired;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VirtualJoystickForMecha : MonoBehaviour
{
public string playerId = "Player";
public string controllerId = "MechaJoystick";
private Player player;
public Transform root;
public Transform topOfJoystick;
public float maxRang = 0.1f;
public Vector2 currentJoystick;
void Start()
{
if (ReInput.players == null || ReInput.players.playerCount <= 0)
return;
player = ReInput.players.GetPlayer(playerId);
if (player == null)
return;
for (int i = 0; i < player.controllers.customControllerCount; i++)
{
CustomController controller = player.controllers.CustomControllers[i];
if (controller.hardwareName == controllerId)
{
controller.SetAxisUpdateCallback(GetAxisInfo);
controller.SetButtonUpdateCallback(GetButtonInfo);
}
}
}
protected bool GetButtonInfo(int buttonId)
{
return false;
}
protected float GetAxisInfo(int axisId)
{
Vector3 localPosition = root.InverseTransformPoint(topOfJoystick.position);
localPosition.y = 0;
localPosition.x = Mathf.Clamp(localPosition.x, -maxRang, maxRang);
localPosition.z = Mathf.Clamp(localPosition.z, -maxRang, maxRang);
currentJoystick.x = localPosition.x * (1f/ maxRang);
currentJoystick.y = localPosition.z * (1f / maxRang);
switch (axisId)
{
case 0: return currentJoystick.x;
case 1: return currentJoystick.y;
}
return 0f;
}
}