Created
November 25, 2018 08:53
-
-
Save yakimelon/dc0b5a03b12847d9d646a3fb38edad81 to your computer and use it in GitHub Desktop.
This file contains 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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using VRM; | |
public class InputListener : MonoBehaviour { | |
public GameObject LeftHand; | |
public GameObject Camera; | |
public GameObject Character; | |
public bool IsTouchPadClicked; | |
private readonly CharacterMoveCalculator _characterMoveCalculator = new CharacterMoveCalculator(); | |
void Update () { | |
// TODO: デバッグ用確認処理 | |
if (Input.GetKeyDown(KeyCode.RightArrow)) { | |
Camera.transform.rotation *= Quaternion.Euler(0, 30, 0); | |
Quaternion rotate = Quaternion.Euler(0, 30, 0); | |
LeftHand.transform.RotateAround(Camera.transform.position, Vector3.up, rotate.y); | |
} | |
if (Input.GetKeyDown(KeyCode.LeftArrow)) { | |
Camera.transform.rotation *= Quaternion.Euler(0, -30, 0); | |
Quaternion rotate = Quaternion.Euler(0, -30, 0); | |
LeftHand.transform.RotateAround(Camera.transform.position, Vector3.up, rotate.y); | |
} | |
// タッチパッドの左右を押された瞬間に角度変更 | |
if (OVRInput.GetDown(OVRInput.Button.PrimaryTouchpad)) { | |
IsTouchPadClicked = true; | |
RotationCharacter(); | |
} | |
// タッチパッドを上下を押されている間キャラを移動する | |
if (IsTouchPadClicked) { | |
MoveCharacter(); | |
Character.GetComponent<Animator>().SetBool("Walking", true); | |
} | |
if (OVRInput.GetUp(OVRInput.Button.PrimaryTouchpad)) { | |
IsTouchPadClicked = false; | |
Character.GetComponent<Animator>().SetBool("Walking", false); | |
} | |
// 表情制御 | |
if (OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger)) { | |
Character.GetComponent<VRMBlendShapeProxy>().SetValue(BlendShapePreset.Joy, 1); | |
} else { | |
Character.GetComponent<VRMBlendShapeProxy>().SetValue(BlendShapePreset.Joy, 0); | |
} | |
} | |
// キャラを移動させる | |
private void MoveCharacter() { | |
Vector2 pt = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad); | |
Vector3 moveVector = _characterMoveCalculator.FetchMoveVector(pt); | |
Camera.transform.Translate(moveVector); | |
// TODO: 正しいベクトルに進んでいない -> Cubeが正しい方向を向いていないから | |
LeftHand.transform.Translate(moveVector); | |
} | |
// キャラを回転させる | |
private void RotationCharacter() { | |
Vector2 pt = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad); | |
float angle = _characterMoveCalculator.FetchMoveAngle(pt); | |
Camera.transform.rotation *= Quaternion.Euler(0, angle, 0); | |
LeftHand.transform.RotateAround(Camera.transform.position, Vector3.up, angle); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment