I_Jemin

Done: VR Eye UI interaction

Add demo object for VR eye interaction
This diff could not be displayed because it is too large.
fileFormatVersion: 2
guid: 14f7e3e1cdfe84d9e863cb8db7ef6a9f
folderAsset: yes
timeCreated: 1512283602
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ColorChanage : MonoBehaviour {
public Image target;
public void SetWhite()
{
target.color = Color.white;
}
public void SetRed()
{
target.color = Color.red;
}
public void SetRandomColor()
{
target.color = Random.ColorHSV();
}
}
fileFormatVersion: 2
guid: 133d0a875b0a248f78d1a42196c9f49a
timeCreated: 1512274876
guid: 2d6c2dd67ddb4436cabe16ca3449ade3
timeCreated: 1512280867
licenseType: Pro
MonoImporter:
externalObjects: {}
......
......@@ -118,8 +118,7 @@ public class Gun : MonoBehaviour
// 찍어내기(찍어낼 피탄효과 원본, 위치, 회전)
// Quaternion.LookRotation(방향) => 해당 방향을 보는 쪽으로 회전을 만들어줌
// hit.normal = 충돌각 (정확하게는 충돌한 표면이 바라보는 방향)
GameObject impactInstance
= Instantiate(impactPrefab, hit.point, Quaternion.LookRotation(hit.normal));
Instantiate(impactPrefab, hit.point, Quaternion.LookRotation(hit.normal));
// 만약 상대방이 IDamageable 로서 가져와진다면...
// 상대방이 무조건 IDamageable 이 강제하는
......
......@@ -5,7 +5,7 @@ using UnityEngine;
// VR 컨트롤러의 인풋을 받아 Gun 을 제어하는 스크립트
public class GunController : MonoBehaviour {
/* VR 입력을 받아 처리해야 하는 클래스는 VRInputController 싱긑톤의 두 함수만 체크 하면 된다 */
/* VR 입력을 받아 처리해야 하는 클래스는 VRInput의 두 함수만 체크 하면 된다 */
// 단 두개의 함수 GetGripButton 와 GetTriggerButton
public Gun gun;
......
using UnityEngine;
using UnityEngine.UI;
public class Reticle : MonoBehaviour
{
[SerializeField] private float m_DefaultDistance = 5f; // The default distance away from the camera the reticle is placed.
[SerializeField] private bool m_UseNormal; // Whether the reticle should be placed parallel to a surface.
[SerializeField] private Image m_Image; // Reference to the image component that represents the reticle.
[SerializeField] private Transform m_ReticleTransform; // We need to affect the reticle's transform.
[SerializeField] private Transform m_Camera; // The reticle is always placed relative to the camera.
private Vector3 m_OriginalScale; // Since the scale of the reticle changes, the original scale needs to be stored.
private Quaternion m_OriginalRotation; // Used to store the original rotation of the reticle.
public bool UseNormal
{
get { return m_UseNormal; }
set { m_UseNormal = value; }
}
public Transform ReticleTransform { get { return m_ReticleTransform; } }
private void Awake()
{
// Store the original scale and rotation.
m_OriginalScale = m_ReticleTransform.localScale;
m_OriginalRotation = m_ReticleTransform.localRotation;
}
public void Hide()
{
m_Image.enabled = false;
}
public void Show()
{
m_Image.enabled = true;
}
// This overload of SetPosition is used when the the VREyeRaycaster hasn't hit anything.
public void SetPosition ()
{
// Set the position of the reticle to the default distance in front of the camera.
m_ReticleTransform.position = m_Camera.position + m_Camera.forward * m_DefaultDistance;
// Set the scale based on the original and the distance from the camera.
m_ReticleTransform.localScale = m_OriginalScale * m_DefaultDistance;
// The rotation should just be the default.
m_ReticleTransform.localRotation = m_OriginalRotation;
}
// This overload of SetPosition is used when the VREyeRaycaster has hit something.
public void SetPosition (RaycastHit hit)
{
m_ReticleTransform.position = hit.point;
m_ReticleTransform.localScale = m_OriginalScale * hit.distance;
// If the reticle should use the normal of what has been hit...
if (m_UseNormal)
// ... set it's rotation based on it's forward vector facing along the normal.
m_ReticleTransform.rotation = Quaternion.FromToRotation (Vector3.forward, hit.normal);
else
// However if it isn't using the normal then it's local rotation should be as it was originally.
m_ReticleTransform.localRotation = m_OriginalRotation;
}
}
......@@ -9,11 +9,10 @@ public class VREyeRaycaster : MonoBehaviour
[SerializeField] private Transform m_Camera;
[SerializeField] public LayerMask m_ExclusionLayers; // Layers to exclude from the raycast.
[SerializeField] private Reticle m_Reticle; // The reticle, if applicable.
[SerializeField] private float m_RayLength = 500f;
[SerializeField] private bool m_ShowDebugRay; // Optionally show the debug ray. [SerializeField] private float m_RayLength = 500f; // How far into the scene the ray is cast.
private VRInteratable m_CurrentInteractible; //The current interactive item
private VRInteratable m_LastInteractible; //The last interactive item
......@@ -21,6 +20,16 @@ public class VREyeRaycaster : MonoBehaviour
void Update()
{
EyeRaycast();
if(VRInput.GetTriggerButton(VRInput.Hand.Right))
{
// Xbox 나 VR 컨트롤러의 'A' 키를 누르면 인터렉터블 오브젝트의 OnClick 이벤트를 발동시킴
// TODO: VR 컨트롤러의 트리거 버튼 클릭으로 대체
if(m_CurrentInteractible && Input.GetButtonDown("Fire1"))
{
m_CurrentInteractible.OnClick();
}
}
}
......@@ -50,22 +59,18 @@ public class VREyeRaycaster : MonoBehaviour
m_LastInteractible = interactible;
}
// Something was hit, set at the hit position.
if (m_Reticle)
m_Reticle.SetPosition(hit);
if (OnRaycasthit != null)
OnRaycasthit(hit);
}
else
{
if(m_LastInteractible && m_CurrentInteractible)
{
m_LastInteractible.OnVREyeExit();
}
m_LastInteractible = null;
m_CurrentInteractible = null;
// Position the reticle at default distance.
if (m_Reticle)
m_Reticle.SetPosition();
}
}
}
......
......@@ -95,4 +95,6 @@ public static class VRInput {
return false;
}
//TODO GetTriggerDown 과 GetTriggerUp 만들기
}
......
......@@ -6,18 +6,26 @@ using UnityEngine.Events;
public class VRInteratable : MonoBehaviour {
[SerializeField]
private UnityEvent onVRTriggerClick;
private UnityEvent onClick;
[SerializeField]
private UnityEvent onVREyeEnter;
public void OnTriggerClick()
[SerializeField]
private UnityEvent onVREyeExit;
public void OnClick()
{
onVRTriggerClick.Invoke();
onClick.Invoke();
}
public void OnVREyeEnter()
{
onVREyeEnter.Invoke();
}
public void OnVREyeExit()
{
onVREyeExit.Invoke();
}
}
......