/// <summary> /// Called when the object transitions from one <see cref="GrabState"/> to another. /// </summary> /// <param name="state">The state the object should transition to.</param> private void ChangeObjectState(GrabState state) { _currentGrabState = state; switch (state) { // Inform the object that it has been ungrabbed and set it to not be kinematic. case GrabState.Idle: IsObjectGrabbing = false; _grabbedObject.ObjectUngrabbed(); _grabbedObjectRigidBody.isKinematic = false; break; // When the user starts grabbing the object, save the object and store its animation values. case GrabState.Grabbing: IsObjectGrabbing = true; _grabbedObject = _focusedGameObject; _grabbedObject.ObjectGrabbing(); _grabbedObjectRigidBody = _focusedGameObject.GetComponent <Rigidbody>(); _grabbedObjectRigidBody.isKinematic = true; _startObjectRotation = _grabbedObject.transform.rotation; _startControllerRotation = ControllerManager.Instance.Rotation; _startPosition = _grabbedObject.transform.position; _grabAnimationProgress = 0f; break; // When the object becomes grabbed to the controller, call the grabbed method and set the object's position to the hand. case GrabState.Grabbed: ControllerManager.Instance.TriggerHapticPulse(2000); _grabbedObject.ObjectGrabbed(); _grabbedObject.transform.position = ControllerManager.Instance.Position; break; } }
/// <summary> /// Store the values attached to focused object. /// </summary> /// <param name="focusedObject">The new focused object to store.</param> private void SetNewFocusedObject(GameObject focusedObject) { _focusedGameObject = focusedObject.GetComponent <GazeGrabbableObject>(); _objectGazeStickinessSeconds = _focusedGameObject.GazeStickinessSeconds; _animationCurve = _focusedGameObject.AnimationCurve; _flyToControllerTimeSeconds = _focusedGameObject.FlyToControllerTimeSeconds; _focusedGameObjectTime = Time.time; }
/// <summary> /// Updates the currently focused <see cref="GazeGrabbableObject"/> and keeps it focused for the time set by the object, <see cref="GazeGrabbableObject.GazeStickinessSeconds"/>. /// </summary> private void UpdateFocusedObject() { // Check whether Tobii XR has any focused objects. foreach (var focusedCandidate in TobiiXR.FocusedObjects) { var focusedObject = focusedCandidate.GameObject; // The candidate list is ordered so that the most likely object is first in the list. // So let's try to find the first focused object that also has the GazeGrabbableObject component and save it. if (focusedObject != null && focusedObject.GetComponent <GazeGrabbableObject>()) { SetNewFocusedObject(focusedObject); break; } } // If enough time has passed since the object was last focused, mark it as not focused. if (Time.time > _focusedGameObjectTime + _objectGazeStickinessSeconds) { _focusedGameObjectTime = float.NaN; _focusedGameObject = null; _objectGazeStickinessSeconds = 0f; } }