Last active
December 20, 2018 12:50
-
-
Save nkjzm/7010a311ce7e042bb97aab5a30bc54ba to your computer and use it in GitHub Desktop.
OculusGoのコントローラーをUnity上でエミュレートする ref: https://qiita.com/nkjzm/items/83d3ab0862fbfef86b63
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Vector2 Get(Axis2D virtualMask, Controller controllerMask = Controller.Active) | |
{ | |
return GetResolvedAxis2D(virtualMask, RawAxis2D.None, controllerMask); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OVRInputEmulator | |
{ | |
// このメソッドと入れ替える | |
public static Vector2 Get(OVRInput.Axis2D virtualMask, OVRInput.Controller controllerMask = OVRInput.Controller.Active) | |
{ | |
return GvrControllerInput.GetDevice(GvrControllerHand.Dominant).TouchPos; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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