Initialer Upload neues Unity-Projekt
This commit is contained in:
1317
Assets/Oculus/VR/Scripts/OVRVirtualKeyboard/OVRVirtualKeyboard.cs
Normal file
1317
Assets/Oculus/VR/Scripts/OVRVirtualKeyboard/OVRVirtualKeyboard.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09cced76cc649e444abf5f01db84a585
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
[Obsolete]
|
||||
[ExecuteInEditMode]
|
||||
[HelpURL("https://developer.oculus.com/reference/unity/latest/class_o_v_r_virtual_keyboard_controller_input_handler")]
|
||||
public class OVRVirtualKeyboardControllerInputHandler : MonoBehaviour
|
||||
{
|
||||
void Awake()
|
||||
{
|
||||
DestroyImmediate(this);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 361ce7a1a5551c24badfb5e31a467aaf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
[Obsolete]
|
||||
[ExecuteInEditMode]
|
||||
[HelpURL("https://developer.oculus.com/reference/unity/latest/class_o_v_r_virtual_keyboard_hand_input_handler")]
|
||||
public class OVRVirtualKeyboardHandInputHandler : MonoBehaviour
|
||||
{
|
||||
void Awake()
|
||||
{
|
||||
DestroyImmediate(this);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ebea44303b77ad4abd1700cb283ba6b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,263 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[RequireComponent(typeof(OVRVirtualKeyboardSampleInputHandler))]
|
||||
[HelpURL("https://developer.oculus.com/reference/unity/latest/class_o_v_r_virtual_keyboard_sample_controls")]
|
||||
public class OVRVirtualKeyboardSampleControls : MonoBehaviour
|
||||
{
|
||||
private struct OVRVirtualKeyboardBackup
|
||||
{
|
||||
private readonly InputField _textCommitField;
|
||||
private readonly Vector3 _position;
|
||||
private readonly Quaternion _rotation;
|
||||
private readonly Vector3 _scale;
|
||||
private readonly Transform _rightControllerDirectTransform;
|
||||
private readonly Transform _rightControllerRootTransform;
|
||||
private readonly Transform _leftControllerDirectTransform;
|
||||
private readonly Transform _leftControllerRootTransform;
|
||||
private readonly bool _controllerRayInteraction;
|
||||
private readonly bool _controllerDirectInteraction;
|
||||
private readonly OVRHand _handLeft;
|
||||
private readonly OVRHand _handRight;
|
||||
private readonly bool _handRayInteraction;
|
||||
private readonly bool _handDirectInteraction;
|
||||
private readonly OVRPhysicsRaycaster _controllerRaycaster;
|
||||
private readonly OVRPhysicsRaycaster _handRaycaster;
|
||||
|
||||
public OVRVirtualKeyboardBackup(OVRVirtualKeyboard keyboard)
|
||||
{
|
||||
_textCommitField = keyboard.TextCommitField;
|
||||
_position = keyboard.transform.position;
|
||||
_rotation = keyboard.transform.rotation;
|
||||
_scale = keyboard.transform.localScale;
|
||||
|
||||
_rightControllerDirectTransform = keyboard.rightControllerDirectTransform;
|
||||
_rightControllerRootTransform = keyboard.rightControllerRootTransform;
|
||||
_leftControllerDirectTransform = keyboard.leftControllerDirectTransform;
|
||||
_leftControllerRootTransform = keyboard.leftControllerRootTransform;
|
||||
_controllerRayInteraction = keyboard.controllerRayInteraction;
|
||||
_controllerDirectInteraction = keyboard.controllerDirectInteraction;
|
||||
_controllerRaycaster = keyboard.controllerRaycaster;
|
||||
|
||||
_handLeft = keyboard.handLeft;
|
||||
_handRight = keyboard.handRight;
|
||||
_handRayInteraction = keyboard.handRayInteraction;
|
||||
_handDirectInteraction = keyboard.handDirectInteraction;
|
||||
_handRaycaster = keyboard.handRaycaster;
|
||||
}
|
||||
|
||||
public void RestoreTo(OVRVirtualKeyboard keyboard)
|
||||
{
|
||||
keyboard.TextCommitField = _textCommitField;
|
||||
keyboard.transform.SetPositionAndRotation(_position, _rotation);
|
||||
keyboard.transform.localScale = _scale;
|
||||
|
||||
keyboard.rightControllerDirectTransform = _rightControllerDirectTransform;
|
||||
keyboard.rightControllerRootTransform = _rightControllerRootTransform;
|
||||
keyboard.leftControllerDirectTransform = _leftControllerDirectTransform;
|
||||
keyboard.leftControllerRootTransform = _leftControllerRootTransform;
|
||||
keyboard.controllerRayInteraction = _controllerRayInteraction;
|
||||
keyboard.controllerDirectInteraction = _controllerDirectInteraction;
|
||||
keyboard.controllerRaycaster = _controllerRaycaster;
|
||||
|
||||
keyboard.handLeft = _handLeft;
|
||||
keyboard.handRight = _handRight;
|
||||
keyboard.handRayInteraction = _handRayInteraction;
|
||||
keyboard.handDirectInteraction = _handDirectInteraction;
|
||||
keyboard.handRaycaster = _handRaycaster;
|
||||
}
|
||||
}
|
||||
|
||||
private const float THUMBSTICK_DEADZONE = 0.2f;
|
||||
|
||||
[SerializeField]
|
||||
private Button ShowButton;
|
||||
|
||||
[SerializeField]
|
||||
private Button MoveButton;
|
||||
|
||||
[SerializeField]
|
||||
private Button HideButton;
|
||||
|
||||
[SerializeField]
|
||||
private Button MoveNearButton;
|
||||
|
||||
[SerializeField]
|
||||
private Button MoveFarButton;
|
||||
|
||||
[SerializeField]
|
||||
private Button DestroyKeyboardButton;
|
||||
|
||||
[SerializeField]
|
||||
private OVRVirtualKeyboard keyboard;
|
||||
|
||||
private OVRVirtualKeyboardSampleInputHandler inputHandler;
|
||||
|
||||
private bool isMovingKeyboard_ = false;
|
||||
private bool isMovingKeyboardFinished_ = false;
|
||||
private float keyboardMoveDistance_ = 0.0f;
|
||||
private float keyboardScale_ = 1.0f;
|
||||
private OVRVirtualKeyboardBackup keyboardBackup;
|
||||
|
||||
void Start()
|
||||
{
|
||||
inputHandler = GetComponent<OVRVirtualKeyboardSampleInputHandler>();
|
||||
|
||||
// If System Keyboard is enabled at the same time as Virtual Keyboard
|
||||
// prevent the system keyboard from opening with input field focus
|
||||
keyboard.TextCommitField.keyboardType = (TouchScreenKeyboardType)(-1);
|
||||
|
||||
ShowKeyboard();
|
||||
|
||||
keyboard.KeyboardHiddenEvent.AddListener(OnHideKeyboard);
|
||||
|
||||
MoveNearButton.onClick.AddListener(MoveKeyboardNear);
|
||||
MoveFarButton.onClick.AddListener(MoveKeyboardFar);
|
||||
DestroyKeyboardButton.onClick.AddListener(DestroyKeyboard);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (keyboard == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
keyboard.KeyboardHiddenEvent.RemoveListener(OnHideKeyboard);
|
||||
MoveNearButton.onClick.RemoveListener(MoveKeyboardNear);
|
||||
MoveFarButton.onClick.RemoveListener(MoveKeyboardFar);
|
||||
DestroyKeyboardButton.onClick.RemoveListener(DestroyKeyboard);
|
||||
}
|
||||
|
||||
public void ShowKeyboard()
|
||||
{
|
||||
if (keyboard == null)
|
||||
{
|
||||
var go = new GameObject();
|
||||
keyboard = go.AddComponent<OVRVirtualKeyboard>();
|
||||
keyboardBackup.RestoreTo(keyboard);
|
||||
inputHandler.OVRVirtualKeyboard = keyboard;
|
||||
}
|
||||
|
||||
keyboard.gameObject.SetActive(true);
|
||||
UpdateButtonInteractable();
|
||||
}
|
||||
|
||||
public void MoveKeyboard()
|
||||
{
|
||||
if (!keyboard.gameObject.activeSelf) return;
|
||||
isMovingKeyboard_ = true;
|
||||
var kbTransform = keyboard.transform;
|
||||
keyboardMoveDistance_ = (inputHandler.InputRayPosition - kbTransform.position).magnitude;
|
||||
keyboardScale_ = kbTransform.localScale.x;
|
||||
UpdateButtonInteractable();
|
||||
keyboard.InputEnabled = false;
|
||||
}
|
||||
|
||||
public void MoveKeyboardNear()
|
||||
{
|
||||
if (!keyboard.gameObject.activeSelf) return;
|
||||
keyboard.UseSuggestedLocation(OVRVirtualKeyboard.KeyboardPosition.Near);
|
||||
}
|
||||
|
||||
public void MoveKeyboardFar()
|
||||
{
|
||||
if (!keyboard.gameObject.activeSelf) return;
|
||||
keyboard.UseSuggestedLocation(OVRVirtualKeyboard.KeyboardPosition.Far);
|
||||
}
|
||||
|
||||
public void HideKeyboard()
|
||||
{
|
||||
keyboard.gameObject.SetActive(false);
|
||||
isMovingKeyboard_ = false;
|
||||
UpdateButtonInteractable();
|
||||
}
|
||||
|
||||
public void DestroyKeyboard()
|
||||
{
|
||||
if (keyboard != null)
|
||||
{
|
||||
keyboardBackup = new OVRVirtualKeyboardBackup(keyboard);
|
||||
GameObject.Destroy(keyboard.gameObject);
|
||||
keyboard = null;
|
||||
UpdateButtonInteractable();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnHideKeyboard()
|
||||
{
|
||||
UpdateButtonInteractable();
|
||||
}
|
||||
|
||||
private void UpdateButtonInteractable()
|
||||
{
|
||||
var kbExists = keyboard != null;
|
||||
var kbActiveAndNotMoving = kbExists && keyboard.gameObject.activeSelf && !isMovingKeyboard_;
|
||||
ShowButton.interactable = !kbExists || !keyboard.gameObject.activeSelf;
|
||||
MoveButton.interactable = kbActiveAndNotMoving;
|
||||
MoveNearButton.interactable = kbActiveAndNotMoving;
|
||||
MoveFarButton.interactable = kbActiveAndNotMoving;
|
||||
HideButton.interactable = kbActiveAndNotMoving;
|
||||
DestroyKeyboardButton.interactable = kbExists;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
var isPressed = OVRInput.Get(
|
||||
OVRInput.Button.One | // right hand pinch
|
||||
OVRInput.Button.Three | // left hand pinch
|
||||
OVRInput.Button.PrimaryIndexTrigger |
|
||||
OVRInput.Button.SecondaryIndexTrigger,
|
||||
OVRInput.Controller.All);
|
||||
if (isMovingKeyboardFinished_ && !isPressed)
|
||||
{
|
||||
keyboard.InputEnabled = true;
|
||||
isMovingKeyboard_ = false;
|
||||
isMovingKeyboardFinished_ = false;
|
||||
UpdateButtonInteractable();
|
||||
}
|
||||
|
||||
if (isMovingKeyboard_ && !isMovingKeyboardFinished_)
|
||||
{
|
||||
keyboardMoveDistance_ *= 1.0f + inputHandler.AnalogStickY * 0.01f;
|
||||
keyboardMoveDistance_ = Mathf.Clamp(keyboardMoveDistance_, 0.1f, 100.0f);
|
||||
|
||||
keyboardScale_ += inputHandler.AnalogStickX * 0.01f;
|
||||
keyboardScale_ = Mathf.Clamp(keyboardScale_, 0.25f, 2.0f);
|
||||
|
||||
var rotation = inputHandler.InputRayRotation;
|
||||
var kbTransform = keyboard.transform;
|
||||
kbTransform.SetPositionAndRotation(
|
||||
inputHandler.InputRayPosition + keyboardMoveDistance_ * (rotation * Vector3.forward),
|
||||
rotation);
|
||||
kbTransform.localScale = Vector3.one * keyboardScale_;
|
||||
|
||||
if (isPressed)
|
||||
{
|
||||
// Delay the true finish by a frame
|
||||
isMovingKeyboardFinished_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37bf64640c1708d45a7c15255f5fd55a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class OVRVirtualKeyboardSampleInputHandler : MonoBehaviour
|
||||
{
|
||||
private const float RAY_MAX_DISTANCE = 100.0f;
|
||||
private const float THUMBSTICK_DEADZONE = 0.2f;
|
||||
private const float COLLISION_BOUNDS_ADDED_BLEED_PERCENT = 0.1f;
|
||||
private const float LINEPOINTER_THINNING_THRESHOLD = 0.015f;
|
||||
|
||||
private static float ApplyDeadzone(float value)
|
||||
{
|
||||
if (value > THUMBSTICK_DEADZONE)
|
||||
return (value - THUMBSTICK_DEADZONE) / (1.0f - THUMBSTICK_DEADZONE);
|
||||
else if (value < -THUMBSTICK_DEADZONE)
|
||||
return (value + THUMBSTICK_DEADZONE) / (1.0f - THUMBSTICK_DEADZONE);
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
public float AnalogStickX => ApplyDeadzone(OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick).x +
|
||||
OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick).x);
|
||||
|
||||
public float AnalogStickY => ApplyDeadzone(OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick).y +
|
||||
OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick).y);
|
||||
|
||||
public Vector3 InputRayPosition => inputModule.rayTransform.position;
|
||||
|
||||
public Quaternion InputRayRotation =>
|
||||
interactionDevice_ == OVRInput.Controller.LHand
|
||||
? inputModule.rayTransform.rotation * Quaternion.Euler(Vector3.forward * 180)
|
||||
: // Flip input rotation if left hand input
|
||||
inputModule.rayTransform.rotation;
|
||||
|
||||
public OVRVirtualKeyboard OVRVirtualKeyboard;
|
||||
|
||||
[SerializeField]
|
||||
private OVRRaycaster raycaster;
|
||||
|
||||
[SerializeField]
|
||||
private OVRInputModule inputModule;
|
||||
|
||||
[SerializeField]
|
||||
private LineRenderer leftLinePointer;
|
||||
|
||||
[SerializeField]
|
||||
private LineRenderer rightLinePointer;
|
||||
|
||||
private OVRInput.Controller? interactionDevice_;
|
||||
private float linePointerInitialWidth_;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rightLinePointer.enabled = leftLinePointer.enabled = false;
|
||||
linePointerInitialWidth_ = Math.Max(rightLinePointer.startWidth, leftLinePointer.startWidth);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateInteractionAnchor();
|
||||
UpdateLineRenderer();
|
||||
}
|
||||
|
||||
private void UpdateLineRenderer()
|
||||
{
|
||||
leftLinePointer.enabled = false;
|
||||
rightLinePointer.enabled = false;
|
||||
|
||||
UpdateLineRendererFromSource(OVRVirtualKeyboard.InputSource.ControllerLeft);
|
||||
UpdateLineRendererFromSource(OVRVirtualKeyboard.InputSource.ControllerRight);
|
||||
UpdateLineRendererFromSource(OVRVirtualKeyboard.InputSource.HandLeft);
|
||||
UpdateLineRendererFromSource(OVRVirtualKeyboard.InputSource.HandRight);
|
||||
}
|
||||
|
||||
private void UpdateLineRendererFromSource(OVRVirtualKeyboard.InputSource source)
|
||||
{
|
||||
Transform inputTransform = null;
|
||||
switch (source)
|
||||
{
|
||||
case OVRVirtualKeyboard.InputSource.ControllerLeft:
|
||||
inputTransform = OVRInput.IsControllerConnected(OVRInput.Controller.LTouch) &&
|
||||
#if UNITY_EDITOR
|
||||
(!OVRVirtualKeyboard.handLeft || !OVRVirtualKeyboard.handLeft.IsTracked)
|
||||
#else
|
||||
((OVRInput.GetControllerIsInHandState(OVRInput.Hand.HandLeft) == OVRInput.ControllerInHandState.NoHand) ||
|
||||
(OVRInput.GetControllerIsInHandState(OVRInput.Hand.HandLeft) == OVRInput.ControllerInHandState.ControllerInHand))
|
||||
#endif
|
||||
? OVRVirtualKeyboard.leftControllerDirectTransform : null;
|
||||
break;
|
||||
case OVRVirtualKeyboard.InputSource.ControllerRight:
|
||||
inputTransform = OVRInput.IsControllerConnected(OVRInput.Controller.RTouch) &&
|
||||
#if UNITY_EDITOR
|
||||
(!OVRVirtualKeyboard.handRight || !OVRVirtualKeyboard.handRight.IsTracked)
|
||||
#else
|
||||
((OVRInput.GetControllerIsInHandState(OVRInput.Hand.HandRight) == OVRInput.ControllerInHandState.NoHand) ||
|
||||
(OVRInput.GetControllerIsInHandState(OVRInput.Hand.HandRight) == OVRInput.ControllerInHandState.ControllerInHand))
|
||||
#endif
|
||||
? OVRVirtualKeyboard.rightControllerDirectTransform : null;
|
||||
|
||||
break;
|
||||
case OVRVirtualKeyboard.InputSource.HandLeft:
|
||||
inputTransform = (OVRVirtualKeyboard.handLeft.IsPointerPoseValid)
|
||||
? OVRVirtualKeyboard.handLeft.PointerPose
|
||||
: null;
|
||||
break;
|
||||
case OVRVirtualKeyboard.InputSource.HandRight:
|
||||
inputTransform = (OVRVirtualKeyboard.handRight.IsPointerPoseValid)
|
||||
? OVRVirtualKeyboard.handRight.PointerPose
|
||||
: null;
|
||||
break;
|
||||
}
|
||||
|
||||
if (inputTransform == null || inputTransform.position == Vector3.zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var inputPosition = inputTransform.position;
|
||||
|
||||
bool isLeft = (source == OVRVirtualKeyboard.InputSource.ControllerLeft ||
|
||||
source == OVRVirtualKeyboard.InputSource.HandLeft);
|
||||
LineRenderer linePointer = (isLeft) ? leftLinePointer : rightLinePointer;
|
||||
|
||||
linePointer.startWidth = linePointerInitialWidth_;
|
||||
if (OVRVirtualKeyboard && OVRVirtualKeyboard.isActiveAndEnabled && OVRVirtualKeyboard.Collider)
|
||||
{
|
||||
// get the local input point, but apply scaling to account for the scaled collider bounds
|
||||
var localPoint = OVRVirtualKeyboard.transform.InverseTransformPoint(inputPosition) * OVRVirtualKeyboard.transform.localScale.x;
|
||||
// Check if input ray is within the collider bounds.
|
||||
var interactionBounds = new Bounds
|
||||
{
|
||||
size = OVRVirtualKeyboard.Collider.bounds.size
|
||||
};
|
||||
// grow the interaction bounds beyond the collision bounds
|
||||
interactionBounds.Expand(Vector3.one * COLLISION_BOUNDS_ADDED_BLEED_PERCENT);
|
||||
// if input is with bounds, don't render the line
|
||||
if (interactionBounds.Contains(localPoint))
|
||||
{
|
||||
linePointer.enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var closestPoint = interactionBounds.ClosestPoint(localPoint);
|
||||
Vector3 offset = closestPoint - localPoint;
|
||||
// if the input is outside of bounds, but within the thinning threshold, lerp the width based on distance
|
||||
var distanceToInteractionBounds = offset.magnitude;
|
||||
if (distanceToInteractionBounds < LINEPOINTER_THINNING_THRESHOLD)
|
||||
{
|
||||
linePointer.startWidth = Mathf.Lerp(0, linePointerInitialWidth_, distanceToInteractionBounds / LINEPOINTER_THINNING_THRESHOLD);
|
||||
}
|
||||
}
|
||||
linePointer.endWidth = linePointer.startWidth;
|
||||
linePointer.enabled = true;
|
||||
linePointer.SetPosition(0, inputTransform.position);
|
||||
|
||||
var ray = new Ray(inputPosition, inputTransform.rotation * Vector3.forward);
|
||||
if (OVRVirtualKeyboard.Collider && OVRVirtualKeyboard.Collider.Raycast(ray, out var hit, RAY_MAX_DISTANCE))
|
||||
{
|
||||
linePointer.SetPosition(1, hit.point);
|
||||
}
|
||||
else
|
||||
{
|
||||
linePointer.SetPosition(1, inputPosition + ray.direction * 2.5f);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateInteractionAnchor()
|
||||
{
|
||||
OVRInput.Controller activeController = OVRInput.Controller.None;
|
||||
|
||||
var leftControllerExists = OVRVirtualKeyboard.leftControllerRootTransform != null;
|
||||
var leftControllerActive = leftControllerExists && OVRInput.GetDown(OVRInput.RawButton.LIndexTrigger);
|
||||
activeController = (leftControllerActive) ? OVRInput.Controller.LTouch : activeController;
|
||||
|
||||
var rightControllerExists = OVRVirtualKeyboard.rightControllerRootTransform != null;
|
||||
var rightControllerActive = rightControllerExists && OVRInput.GetDown(OVRInput.RawButton.RIndexTrigger);
|
||||
activeController = (rightControllerActive) ? OVRInput.Controller.RTouch : activeController;
|
||||
|
||||
var handLeftExists = OVRVirtualKeyboard.handLeft != null;
|
||||
var handLeftIsActive =
|
||||
handLeftExists && OVRVirtualKeyboard.handLeft.GetFingerIsPinching(OVRHand.HandFinger.Index);
|
||||
activeController = (handLeftIsActive) ? OVRInput.Controller.LHand : activeController;
|
||||
|
||||
var handRightExists = OVRVirtualKeyboard.handRight != null;
|
||||
var handRightIsActive =
|
||||
handRightExists && OVRVirtualKeyboard.handRight.GetFingerIsPinching(OVRHand.HandFinger.Index);
|
||||
activeController = (handRightIsActive) ? OVRInput.Controller.RHand : activeController;
|
||||
|
||||
if (activeController == OVRInput.Controller.None)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Set transforms for Unity UI interaction
|
||||
var dominantHandIsLeft =
|
||||
(activeController == OVRInput.Controller.LHand || activeController == OVRInput.Controller.LTouch);
|
||||
raycaster.pointer = (dominantHandIsLeft)
|
||||
? OVRVirtualKeyboard.handLeft.gameObject
|
||||
: OVRVirtualKeyboard.handRight.gameObject;
|
||||
interactionDevice_ = activeController;
|
||||
inputModule.rayTransform = activeController switch
|
||||
{
|
||||
OVRInput.Controller.LHand => OVRVirtualKeyboard.handLeft.PointerPose,
|
||||
OVRInput.Controller.LTouch => OVRVirtualKeyboard.handLeft.transform,
|
||||
OVRInput.Controller.RHand => OVRVirtualKeyboard.handRight.PointerPose,
|
||||
_ => OVRVirtualKeyboard.handRight.transform
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc63033c3cdd4ad09f74f921a53d6321
|
||||
timeCreated: 1658867665
|
||||
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Obsolete]
|
||||
[ExecuteInEditMode]
|
||||
public class OVRVirtualKeyboardSampleWPMPrompt : MonoBehaviour
|
||||
{
|
||||
void Awake()
|
||||
{
|
||||
DestroyImmediate(this);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ad6f774c54d4181bd7a2c868a39c8c8
|
||||
timeCreated: 1675880354
|
||||
Reference in New Issue
Block a user