/// <summary>
        /// Creates a new DirectInteractor.
        /// </summary>
        public static DirectInteractor CreateDirectInteractor()
        {
            GameObject interactorGO = new GameObject("XR Interactor");

            CreateGOSphereCollider(interactorGO);
            DirectInteractor interactor = interactorGO.AddComponent <DirectInteractor>();
            XRController     controller = interactorGO.GetComponent <XRController>();

            controller.enableInputTracking = false;

            return(interactor);
        }
        private IEnumerator UngrabGrabAndRelease()
        {
            Interactable.ForceStopInteracting();

            XRBaseInteractor interactor = Interactable.selectingInteractor;

            yield return(new WaitUntil(() => Interactable.isHovered == false && Interactable.isSelected == false));

            if (interactor != null)
            {
                DirectInteractor directInteractor = (DirectInteractor)interactor;
                directInteractor.AttemptGrab();

                yield return(null);

                Interactable.ForceStopInteracting();
            }
        }
Beispiel #3
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.ObjectField(EditorGUIUtility.TrTempContent("Script"), MonoScript.FromMonoBehaviour((DirectInteractor)target), typeof(DirectInteractor), false);
            EditorGUI.EndDisabledGroup();

            foreach (Object targetObject in serializedObject.targetObjects)
            {
                DirectInteractor interactor = (DirectInteractor)targetObject;

                if (interactor.GetComponent <XRController>() == null && interactor.GetComponent <ActionBasedController>() == null)
                {
                    EditorGUILayout.HelpBox(Tooltips.MissingRequiredController, MessageType.Warning, true);
                    break;
                }
            }

            EditorGUILayout.PropertyField(interactionManager, Tooltips.InteractionManager);
            EditorGUILayout.PropertyField(interactionLayerMask, Tooltips.InteractionLayerMask);
            EditorGUILayout.PropertyField(attachTransform, Tooltips.AttachTransform);

            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(selectActionTrigger, Tooltips.SelectActionTrigger);
            EditorGUILayout.PropertyField(startingSelectedInteractable, Tooltips.StartingSelectedInteractable);


            if (startingSelectedInteractable.objectReferenceValue != null && (selectActionTrigger.enumValueIndex == 2 || selectActionTrigger.enumValueIndex == 3))
            {
                EditorGUILayout.HelpBox(Tooltips.StartingInteractableWarning, MessageType.Warning, true);
            }

            EditorGUILayout.PropertyField(hideControllerOnSelect, Tooltips.HideControllerOnSelect);
            EditorGUILayout.PropertyField(precisionGrab, Tooltips.PrecisionGrab);

            EditorGUILayout.Space();

            playAudioClipOnSelectEntered.isExpanded = EditorGUILayout.Foldout(playAudioClipOnSelectEntered.isExpanded, EditorGUIUtility.TrTempContent("Audio Events"), true);

            if (playAudioClipOnSelectEntered.isExpanded)
            {
                EditorGUILayout.PropertyField(playAudioClipOnSelectEntered, Tooltips.PlayAudioClipOnSelectEntered);

                if (playAudioClipOnSelectEntered.boolValue)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(audioClipForOnSelectEntered, Tooltips.AudioClipForOnSelectEntered);
                    EditorGUI.indentLevel--;
                }

                EditorGUILayout.PropertyField(playAudioClipOnSelectExited, Tooltips.PlayAudioClipOnSelectExited);

                if (playAudioClipOnSelectExited.boolValue)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(audioClipForOnSelectExited, Tooltips.AudioClipForOnSelectExited);
                    EditorGUI.indentLevel--;
                }

                EditorGUILayout.PropertyField(playAudioClipOnHoverEntered, Tooltips.PlayAudioClipOnHoverEntered);

                if (playAudioClipOnHoverEntered.boolValue)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(audioClipForOnHoverEntered, Tooltips.AudioClipForOnHoverEntered);
                    EditorGUI.indentLevel--;
                }

                EditorGUILayout.PropertyField(playAudioClipOnHoverExited, Tooltips.PlayAudioClipOnHoverExited);

                if (playAudioClipOnHoverExited.boolValue)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(audioClipForOnHoverExited, Tooltips.AudioClipForOnHoverExited);
                    EditorGUI.indentLevel--;
                }
            }

            EditorGUILayout.Space();

            playHapticsOnSelectEntered.isExpanded = EditorGUILayout.Foldout(playHapticsOnSelectEntered.isExpanded, EditorGUIUtility.TrTempContent("Haptic Events"), true);

            if (playHapticsOnSelectEntered.isExpanded)
            {
                EditorGUILayout.PropertyField(playHapticsOnSelectEntered, Tooltips.PlayHapticsOnSelectEntered);

                if (playHapticsOnSelectEntered.boolValue)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(hapticSelectEnterIntensity, Tooltips.HapticSelectEnterIntensity);
                    EditorGUILayout.PropertyField(hapticSelectEnterDuration, Tooltips.HapticSelectEnterDuration);
                    EditorGUI.indentLevel--;
                }

                EditorGUILayout.PropertyField(playHapticsOnSelectExited, Tooltips.PlayHapticsOnSelectExited);

                if (playHapticsOnSelectExited.boolValue)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(hapticSelectExitIntensity, Tooltips.HapticSelectExitIntensity);
                    EditorGUILayout.PropertyField(hapticSelectExitDuration, Tooltips.HapticSelectExitDuration);
                    EditorGUI.indentLevel--;
                }

                EditorGUILayout.PropertyField(playHapticsOnHoverEntered, Tooltips.PlayHapticsOnHoverEntered);

                if (playHapticsOnHoverEntered.boolValue)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(hapticHoverEnterIntensity, Tooltips.HapticHoverEnterIntensity);
                    EditorGUILayout.PropertyField(hapticHoverEnterDuration, Tooltips.HapticHoverEnterDuration);
                    EditorGUI.indentLevel--;
                }

                EditorGUILayout.PropertyField(playHapticsOnHoverExited, Tooltips.PlayHapticsOnHoverExited);

                if (playHapticsOnHoverExited.boolValue)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(hapticHoverExitIntensity, Tooltips.HapticHoverExitIntensity);
                    EditorGUILayout.PropertyField(hapticHoverExitDuration, Tooltips.HapticHoverExitDuration);
                    EditorGUI.indentLevel--;
                }
            }

            EditorGUILayout.Space();

            onHoverEnter.isExpanded = EditorGUILayout.Foldout(onHoverEnter.isExpanded, EditorGUIUtility.TrTempContent("Interactor Events"), true);

            if (onHoverEnter.isExpanded)
            {
                // UnityEvents have not yet supported Tooltips
                EditorGUILayout.PropertyField(onHoverEnter);
                EditorGUILayout.PropertyField(onHoverExit);
                EditorGUILayout.PropertyField(onSelectEnter);
                EditorGUILayout.PropertyField(onSelectExit);
            }

            serializedObject.ApplyModifiedProperties();
        }