2015-09-20 08:21:29 +08:00
|
|
|
|
/// Credit Ralph Barbagallo (www.flarb.com /www.ralphbarbagallo.com / @flarb)
|
|
|
|
|
/// Sourced from - http://forum.unity3d.com/threads/vr-cursor-possible-unity-4-6-gui-bug-or-is-it-me
|
|
|
|
|
|
|
|
|
|
namespace UnityEngine.UI.Extensions
|
|
|
|
|
{
|
|
|
|
|
[AddComponentMenu("UI/Extensions/VR Cursor")]
|
|
|
|
|
public class VRCursor : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public float xSens;
|
|
|
|
|
public float ySens;
|
|
|
|
|
|
|
|
|
|
private Collider currentCollider;
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
Vector3 thisPosition;
|
|
|
|
|
|
2020-10-09 00:07:39 +08:00
|
|
|
|
thisPosition.x = UIExtensionsInputManager.MousePosition.x * xSens;
|
|
|
|
|
thisPosition.y = UIExtensionsInputManager.MousePosition.y * ySens - 1;
|
2015-09-20 08:21:29 +08:00
|
|
|
|
thisPosition.z = transform.position.z;
|
|
|
|
|
|
|
|
|
|
transform.position = thisPosition;
|
|
|
|
|
|
|
|
|
|
VRInputModule.cursorPosition = transform.position;
|
|
|
|
|
|
2020-10-09 00:07:39 +08:00
|
|
|
|
if (UIExtensionsInputManager.GetMouseButtonDown(0) && currentCollider)
|
2015-09-20 08:21:29 +08:00
|
|
|
|
{
|
|
|
|
|
VRInputModule.PointerSubmit(currentCollider.gameObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnTriggerEnter(Collider other)
|
|
|
|
|
{
|
|
|
|
|
//print("OnTriggerEnter other " + other.gameObject);
|
|
|
|
|
VRInputModule.PointerEnter(other.gameObject);
|
|
|
|
|
currentCollider = other;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnTriggerExit(Collider other)
|
|
|
|
|
{
|
|
|
|
|
//print("OnTriggerExit other " + other.gameObject);
|
|
|
|
|
VRInputModule.PointerExit(other.gameObject);
|
|
|
|
|
currentCollider = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|