Skip to content

Instantly share code, notes, and snippets.

@nkjzm
Last active December 20, 2018 12:50
Show Gist options
  • Save nkjzm/7010a311ce7e042bb97aab5a30bc54ba to your computer and use it in GitHub Desktop.
Save nkjzm/7010a311ce7e042bb97aab5a30bc54ba to your computer and use it in GitHub Desktop.
OculusGoのコントローラーをUnity上でエミュレートする ref: https://qiita.com/nkjzm/items/83d3ab0862fbfef86b63
public static Vector2 Get(Axis2D virtualMask, Controller controllerMask = Controller.Active)
{
return GetResolvedAxis2D(virtualMask, RawAxis2D.None, controllerMask);
}
public class OVRInputEmulator
{
// このメソッドと入れ替える
public static Vector2 Get(OVRInput.Axis2D virtualMask, OVRInput.Controller controllerMask = OVRInput.Controller.Active)
{
return GvrControllerInput.GetDevice(GvrControllerHand.Dominant).TouchPos;
}
}
#if UNITY_EDITOR
using System;
using System.Reflection;
using UnityEditor;
[InitializeOnLoad]
public class OVRInputReplacer
{
static OVRInputReplacer()
{
// タッチパッド上の座標
ReplaceMethod(typeof(OVRInput), typeof(OVRInputEmulator), "Get", new System.Type[] { typeof(OVRInput.Axis2D), typeof(OVRInput.Controller) });
}
static void ReplaceMethod(System.Type originType, System.Type replaceType, string methodName, System.Type[] types)
{
var origin = originType.GetMethod(methodName, types);
var replace = replaceType.GetMethod(methodName, types);
ReplaceFunctionPointer(origin, replace);
}
static void ReplaceFunctionPointer(MethodInfo originalMethod, MethodInfo replaceMethod)
{
unsafe
{
var originalPointer = originalMethod.MethodHandle.Value.ToPointer();
var replacePointer = replaceMethod.MethodHandle.Value.ToPointer();
*((int*)new IntPtr(((int*)originalPointer + 1)).ToPointer()) = *((int*)new IntPtr(((int*)replacePointer + 1)).ToPointer());
}
}
}
#endif
var pos = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment