示例#1
0
        protected override void Start()
        {
            base.Start();

            // We need to get the secondSolverHandler ready before we tell them both to seek a tracked object.
            secondSolverHandler = gameObject.AddComponent <SolverHandler>();
            secondSolverHandler.UpdateSolvers = false;

            UpdateSecondSolverHandler();
        }
示例#2
0
        /// <inheritdoc />
        public override void SolverUpdate()
        {
            if (SolverHandler.TrackedTargetType != TrackedObjectType.HandJoint &&
                SolverHandler.TrackedTargetType != TrackedObjectType.ControllerRay)
            {
                Debug.LogWarning("Solver HandConstraint requires TrackedObjectType of type HandJoint or ControllerRay");
                return;
            }

            var prevTrackedController = trackedController;

            if (SolverHandler.CurrentTrackedHandedness != Handedness.None)
            {
                trackedController = GetController(SolverHandler.CurrentTrackedHandedness);
                bool isValidController = IsValidController(trackedController);
                if (!isValidController)
                {
                    // Attempt to switch by hands by asking solver handler to prefer the other controller if available
                    SolverHandler.PreferredTrackedHandedness = SolverHandler.CurrentTrackedHandedness.GetOppositeHandedness();
                    SolverHandler.RefreshTrackedObject();

                    trackedController = GetController(SolverHandler.CurrentTrackedHandedness);
                    isValidController = IsValidController(trackedController);
                    if (!isValidController)
                    {
                        trackedController = null;
                    }
                }

                if (isValidController && SolverHandler.TransformTarget != null)
                {
                    if (updateWhenOppositeHandNear || !IsOppositeHandNear(trackedController))
                    {
                        GoalPosition = CalculateGoalPosition();
                        GoalRotation = CalculateGoalRotation();
                    }
                }
            }
            else
            {
                trackedController = null;
            }

            // Calculate if events should be fired
            var newHandedness = trackedController == null ? Handedness.None : trackedController.ControllerHandedness;

            if (previousHandedness.IsNone() && !newHandedness.IsNone())
            {
                // Toggle cursor off for hand that is going to suppor the hand menu
                StartCoroutine(ToggleCursors(trackedController, false, true));

                OnFirstHandDetected.Invoke();
                OnHandActivate.Invoke();
            }
            else if (!previousHandedness.IsNone() && newHandedness.IsNone())
            {
                // Toggle cursors back on for the hand that is no longer supporting the solver
                StartCoroutine(ToggleCursors(prevTrackedController, true));

                // toggle cursor on for trackedHand
                OnLastHandLost.Invoke();
                OnHandDeactivate.Invoke();
            }
            else if (previousHandedness != newHandedness)
            {
                // Switching controllers. Toggle cursors back on for the previous controller and toggle off for the new supported controller
                StartCoroutine(ToggleCursors(prevTrackedController, true));
                StartCoroutine(ToggleCursors(trackedController, false, true));

                OnHandDeactivate.Invoke();
                OnHandActivate.Invoke();
            }

            previousHandedness = newHandedness;

            UpdateWorkingPositionToGoal();
            UpdateWorkingRotationToGoal();
        }