Last active
July 25, 2018 10:57
-
-
Save nkjzm/1554b679989f68d36606b9ad3cdce1f1 to your computer and use it in GitHub Desktop.
Google VR SDKの入力クラスをZenjectで抽象化する ref: https://qiita.com/splas_boomerang/items/06dfeccca506808b1cbf
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
[Inject] | |
IHandController HandController = null; |
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
Container.Bind<[抽象クラス]>().To<[派生クラス]>().AsSingle(); |
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 GvrHandController : IHandController | |
{ | |
Transform controller = null; | |
public Vector3 Position { get { return (controller ?? (controller = GameObject.FindObjectOfType<GvrTrackedController>().transform)).position; } } | |
public Quaternion Orientation { get { return GvrControllerInput.Orientation; } } | |
public Vector3 Gyro { get { return GvrControllerInput.Gyro; } } | |
public Vector3 Accel { get { return GvrControllerInput.Accel; } } | |
public bool IsTouching { get { return GvrControllerInput.IsTouching; } } | |
public bool TouchDown { get { return GvrControllerInput.TouchDown; } } | |
public bool TouchUp { get { return GvrControllerInput.TouchUp; } } | |
public Vector2 TouchPos { get { return GvrControllerInput.TouchPos; } } | |
public Vector2 TouchPosCentered { get { return GvrControllerInput.TouchPosCentered; } } | |
public bool Recentered { get { return GvrControllerInput.Recentered; } } | |
public bool ClickButton { get { return GvrControllerInput.ClickButton; } } | |
public bool ClickButtonDown { get { return GvrControllerInput.ClickButtonDown; } } | |
public bool ClickButtonUp { get { return GvrControllerInput.ClickButtonUp; } } | |
public bool AppButton { get { return GvrControllerInput.AppButton; } } | |
public bool AppButtonDown { get { return GvrControllerInput.AppButtonDown; } } | |
public bool AppButtonUp { get { return GvrControllerInput.AppButtonUp; } } | |
public bool HomeButtonDown { get { return GvrControllerInput.HomeButtonDown; } } | |
public bool HomeButtonState { get { return GvrControllerInput.HomeButtonState; } } | |
} |
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
using Zenject; | |
public class HandControllerInstaller : MonoInstaller<HandControllerInstaller> | |
{ | |
public override void InstallBindings() | |
{ | |
Container.Bind<IHandController>().To<GvrHandController>().AsSingle(); | |
} | |
} |
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
using UnityEngine; | |
public interface IHandController | |
{ | |
Vector3 Position { get; } | |
Quaternion Orientation { get; } | |
Vector3 Gyro { get; } | |
Vector3 Accel { get; } | |
bool IsTouching { get; } | |
bool TouchDown { get; } | |
bool TouchUp { get; } | |
Vector2 TouchPos { get; } | |
Vector2 TouchPosCentered { get; } | |
bool Recentered { get; } | |
bool ClickButton { get; } | |
bool ClickButtonDown { get; } | |
bool ClickButtonUp { get; } | |
bool AppButton { get; } | |
bool AppButtonDown { get; } | |
bool AppButtonUp { get; } | |
bool HomeButtonDown { get; } | |
bool HomeButtonState { get; } | |
} |
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 OvrHandController : IHandController | |
{ | |
// public bool ClickButton { get { return GvrControllerInput.ClickButton; } } | |
public bool ClickButton { get { return OVRInput.Get(OVRInput.Button.PrimaryTouchpad); } } | |
} |
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
using UnityEngine; | |
using Zenject; | |
public class Test : MonoBehaviour | |
{ | |
[Inject] | |
IHandController HandController = null; | |
void Update() | |
{ | |
// 書き換え前 | |
// if (GvrControllerInput.ClickButton) | |
// 書き換え後 | |
if (HandController.ClickButton) | |
{ | |
Debug.Log("ボタンがクリックされた"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment