コード例 #1
0
ファイル: Interactable.cs プロジェクト: icyAce/MapsSDK-Unity
        /// <summary>
        /// pointer up event has fired
        /// </summary>
        /// <param name="eventData"></param>
        public void OnPointerUp(MixedRealityPointerEventData eventData)
        {
            pointerInputAction = eventData.MixedRealityInputAction;
            if ((!CanInteract() && !HasPress))
            {
                return;
            }

            if (ShouldListen(eventData.MixedRealityInputAction))
            {
                SetPress(false);
                eventData.Use();
            }
        }
コード例 #2
0
        public IEnumerator TestInputActionMenuInput()
        {
            // Load interactable prefab
            Interactable interactable;
            Transform    translateTargetObject;

            InstantiatePressButtonPrefab(
                new Vector3(0.0f, 0.0f, 0.5f),
                DefaultRotation,
                out interactable,
                out translateTargetObject);

            // Subscribe to interactable's on click so we know the click went through
            bool wasClicked = false;

            interactable.OnClick.AddListener(() => { wasClicked = true; });

            var  pressReceiver = interactable.AddReceiver <InteractableOnPressReceiver>();
            bool wasPressed    = false;

            pressReceiver.OnPress.AddListener(() => { wasPressed = true; Debug.Log("pressReciever wasPressed true"); });
            bool wasReleased = false;

            pressReceiver.OnRelease.AddListener(() => { wasReleased = true; Debug.Log("pressReciever wasReleased true"); });

            Vector3 targetStartPosition = translateTargetObject.localPosition;

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            // Find the menu action from the input system profile
            MixedRealityInputAction menuAction = CoreServices.InputSystem.InputSystemProfile.InputActionsProfile.InputActions.Where(m => m.Description == "Menu").FirstOrDefault();

            Assert.NotNull(menuAction.Description, "Couldn't find menu input action in input system profile.");

            // Set the interactable to respond to a 'menu' input action
            interactable.InputAction = menuAction;

            // Find an input source to associate with the input event (doesn't matter which one)
            IMixedRealityInputSource defaultInputSource = CoreServices.InputSystem.DetectedInputSources.FirstOrDefault();

            Assert.NotNull(defaultInputSource, "At least one input source must be present for this test to work.");

            yield return(RunGlobalClick(defaultInputSource, menuAction, targetStartPosition, translateTargetObject));

            Assert.True(wasPressed, "interactable not pressed");
            Assert.True(wasReleased, "interactable not released");
            Assert.True(wasClicked, "Interactable was not clicked.");

            GameObject.Destroy(interactable.gameObject);
        }
コード例 #3
0
        /// <summary>
        /// Used to initialize/reset the event and populate the data.
        /// </summary>
        /// <param name="pointer"></param>
        /// <param name="inputAction"></param>
        /// <param name="handedness"></param>
        /// <param name="inputSource"></param>
        /// <param name="count"></param>
        public void Initialize(IMixedRealityPointer pointer, MixedRealityInputAction inputAction, Handedness handedness = Handedness.None, IMixedRealityInputSource inputSource = null, int count = 0)
        {
            if (inputSource != null)
            {
                Initialize(inputSource, handedness, inputAction);
            }
            else
            {
                Initialize(pointer.InputSourceParent, handedness, inputAction);
            }

            Pointer = pointer;
            Count   = count;
        }
コード例 #4
0
ファイル: Interactable.cs プロジェクト: icyAce/MapsSDK-Unity
        /// <summary>
        /// Pointer down event has fired
        /// </summary>
        /// <param name="eventData"></param>
        public void OnPointerDown(MixedRealityPointerEventData eventData)
        {
            pointerInputAction = eventData.MixedRealityInputAction;
            if (!CanInteract())
            {
                return;
            }

            if (ShouldListen(eventData.MixedRealityInputAction))
            {
                SetPress(true);
                eventData.Use();
            }
        }
コード例 #5
0
        private IEnumerator RunGlobalClick(IMixedRealityInputSource defaultInputSource,
                                           MixedRealityInputAction inputAction,
                                           Vector3 targetStartPosition,
                                           Transform translateTargetObject,
                                           bool shouldTranslate = true)
        {
            yield return(TestInputUtilities.ExecuteGlobalClick(defaultInputSource, inputAction, () =>
            {
                return TestButtonUtilities.CheckButtonTranslation(targetStartPosition, translateTargetObject, shouldTranslate);
            }));

            // Wait for at button release animation to finish
            yield return(new WaitForSeconds(TestButtonUtilities.ButtonReleaseAnimationDelay));
        }
コード例 #6
0
        private void UpdateTeleport()
        {
            if (MRTKOculusConfig.Instance.ActiveTeleportPointerMode == MRTKOculusConfig.TeleportPointerMode.None)
            {
                return;
            }

            MixedRealityInputAction teleportAction = MixedRealityInputAction.None;

            IMixedRealityTeleportPointer teleportPointer = TeleportPointer;

            // Check if we're focus locked or near something interactive to avoid teleporting unintentionally.
            bool anyPointersLockedWithHand = false;

            for (int i = 0; i < InputSource?.Pointers?.Length; i++)
            {
                if (InputSource.Pointers[i] == null)
                {
                    continue;
                }
                if (InputSource.Pointers[i] is IMixedRealityNearPointer)
                {
                    var nearPointer = (IMixedRealityNearPointer)InputSource.Pointers[i];
                    anyPointersLockedWithHand |= nearPointer.IsNearObject;
                }
                anyPointersLockedWithHand |= InputSource.Pointers[i].IsFocusLocked;

                // If official teleport mode and we have a teleport pointer registered, we get the input action to trigger it.
                if (MRTKOculusConfig.Instance.ActiveTeleportPointerMode == MRTKOculusConfig.TeleportPointerMode.Official &&
                    InputSource.Pointers[i] is IMixedRealityTeleportPointer)
                {
                    teleportPointer = (TeleportPointer)InputSource.Pointers[i];
                    teleportAction  = ((TeleportPointer)teleportPointer).TeleportInputAction;
                }
            }

            // We close middle finger to signal spider-man gesture, and as being ready for teleport
            bool isReadyForTeleport = !anyPointersLockedWithHand && IsPositionAvailable && IsInTeleportPose;

            // If not ready for teleport, we raise a cancellation event to prevent accidental teleportation.
            if (!isReadyForTeleport && teleportPointer != null)
            {
                CoreServices.TeleportSystem?.RaiseTeleportCanceled(teleportPointer, null);
            }

            Vector2 stickInput = isReadyForTeleport ? Vector2.up : Vector2.zero;

            RaiseTeleportInput(isIndexGrabbing ? Vector2.zero : stickInput, teleportAction, isReadyForTeleport);
        }
コード例 #7
0
        public void OnGestureCompleted(InputEventData eventData)
        {
            Debug.Log($"OnGestureCompleted [{Time.frameCount}]: {eventData.MixedRealityInputAction.Description}");

            MixedRealityInputAction action = eventData.MixedRealityInputAction;

            if (action == holdAction)
            {
                SetIndicator(holdIndicator, "Hold: completed", defaultMaterial);
            }
            else if (action == tapAction)
            {
                SetIndicator(selectIndicator, "Select: completed", selectMaterial);
            }
        }
コード例 #8
0
        protected virtual void Awake()
        {
            if (States == null)
            {
                States = States.GetDefaultInteractableStates();
            }
            InputAction = ResolveInputAction(InputActionId);
            SetupEvents();
            SetupThemes();
            SetupStates();

            if (StartDimensionIndex > 0)
            {
                SetDimensionIndex(StartDimensionIndex);
            }
        }
コード例 #9
0
        public void OnGestureCompleted(InputEventData <Vector3> eventData)
        {
            Debug.Log($"OnGestureCompleted [{Time.frameCount}]: {eventData.MixedRealityInputAction.Description}");

            MixedRealityInputAction action = eventData.MixedRealityInputAction;

            if (action == manipulationAction)
            {
                SetIndicator(manipulationIndicator, $"Manipulation: completed {eventData.InputData}", defaultMaterial, eventData.InputData);
            }
            else if (action == navigationAction)
            {
                SetIndicator(navigationIndicator, $"Navigation: completed {eventData.InputData}", defaultMaterial, eventData.InputData);
                HideRails();
            }
        }
コード例 #10
0
        protected virtual void Awake()
        {
            if (States == null)
            {
                States = GetDefaultInteractableStates();
            }

            InputAction = ResolveInputAction(InputActionId);

            RefreshSetup();

            if (StartDimensionIndex > 0)
            {
                SetDimensionIndex(StartDimensionIndex);
            }
        }
コード例 #11
0
    public void Initialize(
        WasmBehaviour wasm,
        MixedRealityInputAction grabAction,
        MixedRealityInputAction useAction)
    {
        this.wasm = wasm;

        grabHandler = gameObject.AddComponent<CustomActionHandler>();
        grabHandler.InputAction = grabAction;
        grabHandler.SetFocusRequired(true);
        grabHandler.OnInputActionStarted += GrabHandler_OnInputActionStarted;

        useHandler = gameObject.AddComponent<CustomActionHandler>();
        useHandler.InputAction = useAction;
        // useHandler.SetFocusRequired(false);
        useHandler.OnInputActionStarted += UseHandler_OnInputActionStarted;
    }
        private IEnumerator FireSpeechCommand(string voiceCommand, MixedRealityInputAction inputAction, IMixedRealityInputSource inputSource = null)
        {
            if (inputSource == null)
            {
                // Find an input source to associate with the input event (doesn't matter which one)
                IMixedRealityInputSource defaultInputSource = CoreServices.InputSystem.DetectedInputSources.FirstOrDefault();
                Assert.NotNull(defaultInputSource, "At least one input source must be present for this test to work.");
                inputSource = defaultInputSource;
            }

            // Raise a voice select input event, then wait for transition to take place
            // Wait for at least one frame explicitly to ensure the input goes through
            SpeechCommands commands = new SpeechCommands(voiceCommand, KeyCode.None, inputAction);

            CoreServices.InputSystem.RaiseSpeechCommandRecognized(inputSource, RecognitionConfidenceLevel.High, new System.TimeSpan(100), System.DateTime.Now, commands);
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());
        }
コード例 #13
0
        /// <summary>
        /// Fires a global input click event by given input source and for given input action type.
        /// If testExec is not null, the function will execute in between the input down and input up raised events.
        /// The testExec function parameter is useful for executing tests and asserts in between raised events.
        /// </summary>
        public static IEnumerator ExecuteGlobalClick(IMixedRealityInputSource defaultInputSource,
                                                     MixedRealityInputAction inputAction,
                                                     Func <IEnumerator> testExec = null)
        {
            // Raise a select down input event, then wait for transition to take place
            // Wait for at least one frame explicitly to ensure the input goes through
            CoreServices.InputSystem.RaiseOnInputDown(defaultInputSource, Handedness.Right, inputAction);
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            if (testExec != null)
            {
                yield return(testExec());
            }

            // Raise a select up input event, then wait for transition to take place
            CoreServices.InputSystem.RaiseOnInputUp(defaultInputSource, Handedness.Right, inputAction);
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());
        }
コード例 #14
0
 /// <summary>
 /// The constructor for a new Interaction Mapping definition
 /// </summary>
 /// <param name="id">Identity for mapping</param>
 /// <param name="description">The description of the interaction mapping.</param> 
 /// <param name="axisType">The axis that the mapping operates on, also denotes the data type for the mapping</param>
 /// <param name="inputType">The physical input device / control</param>
 /// <param name="keyCode">Optional KeyCode value to get input from Unity's old input system</param>
 public MixedRealityInteractionMapping(uint id, string description, AxisType axisType, DeviceInputType inputType, KeyCode keyCode)
 {
     this.id = id;
     this.description = description;
     this.axisType = axisType;
     this.inputType = inputType;
     inputAction = MixedRealityInputAction.None;
     this.keyCode = keyCode;
     axisCodeX = string.Empty;
     axisCodeY = string.Empty;
     rawData = null;
     boolData = false;
     floatData = 0f;
     vector2Data = Vector2.zero;
     positionData = Vector3.zero;
     rotationData = Quaternion.identity;
     poseData = MixedRealityPose.ZeroIdentity;
     changed = false;
 }
コード例 #15
0
        private int RenderRuleInputAction(int ruleActionId, out MixedRealityInputAction action)
        {
            action = MixedRealityInputAction.None;
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(RuleActionContent, GUILayout.Width(128));
            EditorGUI.BeginChangeCheck();
            ruleActionId = EditorGUILayout.IntPopup(ruleActionId, ruleActionLabels, ruleActionIds, GUILayout.ExpandWidth(true));

            for (int i = 0; i < MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions.Length; i++)
            {
                if (ruleActionId == (int)MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[i].Id)
                {
                    action = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[i];
                }
            }

            EditorGUILayout.EndHorizontal();
            return(ruleActionId);
        }
コード例 #16
0
        public void OnGestureCanceled(InputEventData eventData)
        {
            Debug.Log($"OnGestureCanceled [{Time.frameCount}]: {eventData.MixedRealityInputAction.Description}");

            MixedRealityInputAction action = eventData.MixedRealityInputAction;

            if (action == holdAction)
            {
                SetIndicator(holdIndicator, "Hold: canceled", defaultMaterial);
            }
            else if (action == manipulationAction)
            {
                SetIndicator(manipulationIndicator, "Manipulation: canceled", defaultMaterial);
            }
            else if (action == navigationAction)
            {
                SetIndicator(navigationIndicator, "Navigation: canceled", defaultMaterial);
                HideRails();
            }
        }
        private void ResetCriteria()
        {
            selectedBaseActionId      = 0;
            selectedRuleActionId      = 0;
            currentBaseAction         = MixedRealityInputAction.None;
            currentRuleAction         = MixedRealityInputAction.None;
            currentBoolCriteria       = false;
            currentSingleAxisCriteria = 0f;
            currentDualAxisCriteria   = Vector2.zero;
            currentVectorCriteria     = Vector3.zero;
            currentQuaternionCriteria = Quaternion.identity;
            currentPoseCriteria       = MixedRealityPose.ZeroIdentity;

            digitalFoldouts    = new bool[inputActionRulesDigital.arraySize];
            singleAxisFoldouts = new bool[inputActionRulesSingleAxis.arraySize];
            dualAxisFoldouts   = new bool[inputActionRulesDualAxis.arraySize];
            vectorFoldouts     = new bool[inputActionRulesVectorAxis.arraySize];
            quaternionFoldouts = new bool[inputActionRulesQuaternionAxis.arraySize];
            poseFoldouts       = new bool[inputActionRulesPoseAxis.arraySize];
        }
        private IEnumerator RunGlobalClick(IMixedRealityInputSource defaultInputSource,
                                           MixedRealityInputAction inputAction,
                                           Vector3 targetStartPosition,
                                           Transform translateTargetObject,
                                           bool shouldTranslate = true)
        {
            // Raise a select down input event, then wait for transition to take place
            // Wait for at least one frame explicitly to ensure the input goes through
            CoreServices.InputSystem.RaiseOnInputDown(defaultInputSource, Handedness.Right, inputAction);
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            yield return(CheckButtonTranslation(targetStartPosition, translateTargetObject, shouldTranslate));

            // Raise a select up input event, then wait for transition to take place
            CoreServices.InputSystem.RaiseOnInputUp(defaultInputSource, Handedness.Right, inputAction);
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            // Wait for at button release animation to finish
            yield return(new WaitForSeconds(ButtonReleaseAnimationDelay));
        }
コード例 #19
0
        public void OnPointerClicked(MixedRealityPointerEventData eventData)
        {
            // let the Input Handlers know what the pointer action is
            if (eventData != null)
            {
                pointerInputAction = eventData.MixedRealityInputAction;
            }

            // check to see if is global or focus - or - if is global, pointer event does not fire twice  - or - input event is not taking these actions already
            if (!CanInteract() || (IsGlobal && (inputTimer != null || GlobalClickOrder[1] == 1)))
            {
                return;
            }

            if (StateManager != null)
            {
                if (eventData != null && ShouldListen(eventData.MixedRealityInputAction))
                {
                    if (GlobalClickOrder[1] == 0)
                    {
                        GlobalClickOrder[0] = 1;
                    }
                    IncreaseDimensionIndex();
                    SendOnClick(eventData.Pointer);
                    SetVisited(true);
                    StartInputTimer(false);
                }
                else if (eventData == null && (HasFocus || IsGlobal)) // handle brute force
                {
                    if (GlobalClickOrder[1] == 0)
                    {
                        GlobalClickOrder[0] = 1;
                    }
                    IncreaseDimensionIndex();
                    StartGlobalVisual(false);
                    SendOnClick(null);
                    SetVisited(true);
                    StartInputTimer(false);
                }
            }
        }
コード例 #20
0
 /// <summary>
 /// The constructor for a new Interaction Mapping definition
 /// </summary>
 /// <param name="id">Identity for mapping</param>
 /// <param name="description">The description of the interaction mapping.</param> 
 /// <param name="axisType">The axis that the mapping operates on, also denotes the data type for the mapping</param>
 /// <param name="inputType">The physical input device / control</param>
 /// <param name="inputAction">The logical MixedRealityInputAction that this input performs</param>
 /// <param name="keyCode">Optional KeyCode value to get input from Unity's old input system</param>
 /// <param name="axisCodeX">Optional horizontal or single axis value to get axis data from Unity's old input system.</param>
 /// <param name="axisCodeY">Optional vertical axis value to get axis data from Unity's old input system.</param>
 /// <param name="invertXAxis">Optional horizontal axis invert option.</param>
 /// <param name="invertYAxis">Optional vertical axis invert option.</param> 
 public MixedRealityInteractionMapping(uint id, string description, AxisType axisType, DeviceInputType inputType, MixedRealityInputAction inputAction, KeyCode keyCode = KeyCode.None, string axisCodeX = "", string axisCodeY = "", bool invertXAxis = false, bool invertYAxis = false)
 {
     this.id = id;
     this.description = description;
     this.axisType = axisType;
     this.inputType = inputType;
     this.inputAction = inputAction;
     this.keyCode = keyCode;
     this.axisCodeX = axisCodeX;
     this.axisCodeY = axisCodeY;
     this.invertXAxis = invertXAxis;
     this.invertYAxis = invertYAxis;
     rawData = null;
     boolData = false;
     floatData = 0f;
     vector2Data = Vector2.zero;
     positionData = Vector3.zero;
     rotationData = Quaternion.identity;
     poseData = MixedRealityPose.ZeroIdentity;
     changed = false;
 }
コード例 #21
0
        /// <inheritdoc />
        public override void SetupDefaultInteractions(Handedness controllerHandedness)
        {
            AssignControllerMappings(DefaultInteractions);
            if (InputSystem?.InputSystemProfile.GesturesProfile != null)
            {
                for (int i = 0; i < InputSystem.InputSystemProfile.GesturesProfile.Gestures.Length; i++)
                {
                    var gesture = InputSystem.InputSystemProfile.GesturesProfile.Gestures[i];

                    switch (gesture.GestureType)
                    {
                    case GestureInputType.Hold:
                        holdingAction = gesture.Action;
                        break;

                    case GestureInputType.Manipulation:
                        manipulationAction = gesture.Action;
                        break;
                    }
                }
            }
        }
コード例 #22
0
        public void OnGestureStarted(InputEventData eventData)
        {
            Debug.Log($"OnGestureStarted [{Time.frameCount}]: {eventData.MixedRealityInputAction.Description}");

            MixedRealityInputAction action = eventData.MixedRealityInputAction;

            if (action == holdAction)
            {
                SetIndicator(holdIndicator, "Hold: started", holdMaterial);
            }
            else if (action == manipulationAction)
            {
                SetIndicator(manipulationIndicator, $"Manipulation: started {Vector3.zero}", manipulationMaterial, Vector3.zero);
            }
            else if (action == navigationAction)
            {
                SetIndicator(navigationIndicator, $"Navigation: started {Vector3.zero}", navigationMaterial, Vector3.zero);
                ShowRails(Vector3.zero);
            }

            SetIndicator(selectIndicator, "Select:", defaultMaterial);
        }
        private int RenderBaseInputAction(int baseActionId, out MixedRealityInputAction action, bool isLocked = false)
        {
            using (new GUIEnabledWrapper(isInitialized, false))
            {
                action = MixedRealityInputAction.None;
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(BaseActionContent);
                EditorGUI.BeginChangeCheck();

                if (!isLocked)
                {
                    baseActionId = EditorGUILayout.IntPopup(baseActionId, baseActionLabels, baseActionIds, GUILayout.ExpandWidth(true));
                }

                var inputActions = GetInputActions();
                for (int i = 0; i < inputActions.Length; i++)
                {
                    if (baseActionId == (int)inputActions[i].Id)
                    {
                        action = inputActions[i];
                    }
                }

                if (action != MixedRealityInputAction.None)
                {
                    GetCompatibleActions(action);
                }

                if (isLocked)
                {
                    EditorGUILayout.LabelField(action.Description, EditorStyles.boldLabel, GUILayout.ExpandWidth(true));
                }

                EditorGUILayout.EndHorizontal();
            }

            return(baseActionId);
        }
コード例 #24
0
        /// <inheritdoc />
        public override void SetupDefaultInteractions(Handedness controllerHandedness)
        {
            AssignControllerMappings(DefaultInteractions);
            if (MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled &&
                MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.GesturesProfile != null)
            {
                for (int i = 0; i < MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.GesturesProfile.Gestures.Length; i++)
                {
                    var gesture = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.GesturesProfile.Gestures[i];

                    switch (gesture.GestureType)
                    {
                    case GestureInputType.Hold:
                        holdingAction = gesture.Action;
                        break;

                    case GestureInputType.Manipulation:
                        manipulationAction = gesture.Action;
                        break;
                    }
                }
            }
        }
コード例 #25
0
        /// <inheritdoc />
        public override void SetupDefaultInteractions()
        {
            base.SetupDefaultInteractions();

            if (CoreServices.InputSystem?.InputSystemProfile.GesturesProfile != null)
            {
                var gestures = CoreServices.InputSystem.InputSystemProfile.GesturesProfile.Gestures;
                for (int i = 0; i < gestures.Length; i++)
                {
                    var gesture = gestures[i];

                    switch (gesture.GestureType)
                    {
                    case GestureInputType.Hold:
                        holdingAction = gesture.Action;
                        break;

                    case GestureInputType.Manipulation:
                        manipulationAction = gesture.Action;
                        break;
                    }
                }
            }
        }
コード例 #26
0
        /// <summary>
        /// Generates an interactable from primitives and assigns a select action.
        /// </summary>
        private void AssembleInteractableButton(out Interactable interactable, out Transform translateTargetObject, string selectActionDescription = "Select")
        {
            // Assemble an interactable out of a set of primitives
            // This will be the button housing
            var interactableObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder);

            interactableObject.name = "RuntimeInteractable";
            interactableObject.transform.position    = new Vector3(0.05f, 0.05f, 0.625f);
            interactableObject.transform.localScale  = new Vector3(0.15f, 0.025f, 0.15f);
            interactableObject.transform.eulerAngles = new Vector3(90f, 0f, 180f);

            // This will be the part that gets scaled
            GameObject childObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
            var        renderer    = childObject.GetComponent <Renderer>();

            renderer.material.color  = DefaultColor;
            renderer.material.shader = StandardShaderUtility.MrtkStandardShader;

            childObject.transform.parent        = interactableObject.transform;
            childObject.transform.localScale    = new Vector3(0.9f, 1f, 0.9f);
            childObject.transform.localPosition = new Vector3(0f, 1.5f, 0f);
            childObject.transform.localRotation = Quaternion.identity;
            // Only use a collider on the main object
            GameObject.Destroy(childObject.GetComponent <Collider>());

            translateTargetObject = childObject.transform;

            // Add an interactable
            interactable = interactableObject.AddComponent <Interactable>();

            var themeDefinition = ThemeDefinition.GetDefaultThemeDefinition <ScaleOffsetColorTheme>().Value;

            // themeDefinition.Easing.Enabled = false;
            // Set the offset state property (index = 1) to move on the Pressed state (index = 2)
            themeDefinition.StateProperties[1].Values = new List <ThemePropertyValue>()
            {
                new ThemePropertyValue()
                {
                    Vector3 = Vector3.zero
                },
                new ThemePropertyValue()
                {
                    Vector3 = Vector3.zero
                },
                new ThemePropertyValue()
                {
                    Vector3 = new Vector3(0.0f, -0.32f, 0.0f)
                },
                new ThemePropertyValue()
                {
                    Vector3 = Vector3.zero
                },
            };
            // Set the color state property (index = 2) values
            themeDefinition.StateProperties[2].Values = new List <ThemePropertyValue>()
            {
                new ThemePropertyValue()
                {
                    Color = DefaultColor
                },
                new ThemePropertyValue()
                {
                    Color = FocusColor
                },
                new ThemePropertyValue()
                {
                    Color = Color.green
                },
                new ThemePropertyValue()
                {
                    Color = DisabledColor
                },
            };

            Theme testTheme = ScriptableObject.CreateInstance <Theme>();

            testTheme.States      = interactable.States;
            testTheme.Definitions = new List <ThemeDefinition>()
            {
                themeDefinition
            };

            interactable.Profiles = new List <InteractableProfileItem>()
            {
                new InteractableProfileItem()
                {
                    Themes = new List <Theme>()
                    {
                        testTheme
                    },
                    Target = translateTargetObject.gameObject,
                },
            };

            // Set the interactable to respond to the requested input action
            MixedRealityInputAction selectAction = CoreServices.InputSystem.InputSystemProfile.InputActionsProfile.InputActions.Where(m => m.Description == selectActionDescription).FirstOrDefault();

            Assert.NotNull(selectAction.Description, "Couldn't find " + selectActionDescription + " input action in input system profile.");
            interactable.InputAction = selectAction;
        }
コード例 #27
0
        /// <summary>
        /// Based on inputAction and state, should this interaction listen to this input?
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        protected virtual bool ShouldListen(MixedRealityInputAction action)
        {
            bool isListening = HasFocus || IsGlobal;

            return(action == InputAction && isListening);
        }
コード例 #28
0
        public void OnGui(Rect rect, SerializedProperty property, GUIContent content, AxisType axisConstraintFilter = AxisType.None)
        {
            var label = EditorGUI.BeginProperty(rect, content, property);

            var id             = property.FindPropertyRelative("id");
            var profileGuid    = property.FindPropertyRelative("profileGuid");
            var description    = property.FindPropertyRelative("description");
            var axisConstraint = property.FindPropertyRelative("axisConstraint");

            if (string.IsNullOrWhiteSpace(profileGuid.stringValue))
            {
                profileGuid.stringValue = DefaultGuidString;
            }

            var currentAction = new MixedRealityInputAction(Guid.Parse(profileGuid.stringValue), (uint)id.intValue, description.stringValue, (AxisType)axisConstraint.intValue);

            if (allInputActionProfiles == null)
            {
                allInputActionProfiles = ScriptableObjectExtensions.GetAllInstances <MixedRealityInputActionsProfile>();
            }

            var dropdownMenu = new GenericMenu {
                allowDuplicateNames = true
            };

            dropdownMenu.AddItem(new GUIContent("None"), false, data => ResetAction(), null);

            foreach (var inputActionProfile in allInputActionProfiles)
            {
                dropdownMenu.AddSeparator($"{inputActionProfile.name}/");

                foreach (var inputAction in inputActionProfile.InputActions)
                {
                    if (axisConstraintFilter != AxisType.None &&
                        axisConstraintFilter != inputAction.AxisConstraint)
                    {
                        if (inputAction == currentAction)
                        {
                            ResetAction();
                        }

                        continue;
                    }

                    dropdownMenu.AddItem(
                        new GUIContent($"{inputActionProfile.name}/{inputAction.Description}"),
                        inputAction == currentAction,
                        OnItemSelect,
                        null);

                    void OnItemSelect(object _)
                    {
                        id.intValue             = (int)inputAction.Id;
                        description.stringValue = inputAction.Description;
                        axisConstraint.intValue = (int)inputAction.AxisConstraint;
                        profileGuid.stringValue = inputAction.ProfileGuid.ToString("N");
                        property.serializedObject.ApplyModifiedProperties();
                        GUI.changed = true;
                    }
                }
            }

            void ResetAction()
            {
                id.intValue             = 0;
                description.stringValue = "None";
                axisConstraint.intValue = 0;
                profileGuid.stringValue = DefaultGuidString;
                property.serializedObject.ApplyModifiedProperties();
                GUI.changed = true;
            }

            var prefix = EditorGUI.PrefixLabel(rect, label);

            if (EditorGUI.DropdownButton(prefix, new GUIContent(description.stringValue), FocusType.Passive))
            {
                dropdownMenu.DropDown(prefix);
            }

            EditorGUI.EndProperty();
        }
コード例 #29
0
 /// <summary>
 /// Release this pointer. This sends pointer clicked and pointer up events across the input system.
 /// </summary>
 /// <param name="mixedRealityInputAction">The input action that corresponds to the released button or axis.</param>
 /// <param name="handedness">Optional handedness of the source that released the pointer.</param>
 public void RaisePointerUp(MixedRealityInputAction mixedRealityInputAction, Handedness handedness = Handedness.None, IMixedRealityInputSource inputSource = null)
 {
     MixedRealityToolkit.InputSystem.RaisePointerClicked(this, mixedRealityInputAction, 0, handedness, inputSource);
     MixedRealityToolkit.InputSystem.RaisePointerUp(this, mixedRealityInputAction, handedness, inputSource);
 }
        private static void RenderList(SerializedProperty list)
        {
            EditorGUILayout.Space();
            GUILayout.BeginVertical();

            if (GUILayout.Button(AddButtonContent, EditorStyles.miniButton))
            {
                list.arraySize += 1;
                var speechCommand = list.GetArrayElementAtIndex(list.arraySize - 1);
                var keyword       = speechCommand.FindPropertyRelative("keyword");
                keyword.stringValue = string.Empty;
                var keyCode = speechCommand.FindPropertyRelative("keyCode");
                keyCode.intValue = (int)KeyCode.None;
                var action   = speechCommand.FindPropertyRelative("action");
                var actionId = action.FindPropertyRelative("id");
                actionId.intValue = 0;
            }

            GUILayout.Space(12f);

            if (list == null || list.arraySize == 0)
            {
                EditorGUILayout.HelpBox("Create a new Speech Command.", MessageType.Warning);
                GUILayout.EndVertical();
                return;
            }

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            var labelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 36f;
            EditorGUILayout.LabelField(KeywordContent, GUILayout.ExpandWidth(true));
            EditorGUILayout.LabelField(KeyCodeContent, GUILayout.Width(64f));
            EditorGUILayout.LabelField(ActionContent, GUILayout.Width(64f));
            EditorGUILayout.LabelField(string.Empty, GUILayout.Width(24f));
            EditorGUIUtility.labelWidth = labelWidth;
            GUILayout.EndHorizontal();

            for (int i = 0; i < list.arraySize; i++)
            {
                EditorGUILayout.BeginHorizontal();
                SerializedProperty speechCommand = list.GetArrayElementAtIndex(i);
                var keyword = speechCommand.FindPropertyRelative("keyword");
                EditorGUILayout.PropertyField(keyword, GUIContent.none, GUILayout.ExpandWidth(true));
                var keyCode = speechCommand.FindPropertyRelative("keyCode");
                EditorGUILayout.PropertyField(keyCode, GUIContent.none, GUILayout.Width(64f));
                var action            = speechCommand.FindPropertyRelative("action");
                var actionId          = action.FindPropertyRelative("id");
                var actionDescription = action.FindPropertyRelative("description");
                var actionConstraint  = action.FindPropertyRelative("axisConstraint");

                EditorGUI.BeginChangeCheck();
                actionId.intValue = EditorGUILayout.IntPopup(GUIContent.none, actionId.intValue, actionLabels, actionIds, GUILayout.Width(64f));

                if (EditorGUI.EndChangeCheck())
                {
                    MixedRealityInputAction inputAction = actionId.intValue == 0 ? MixedRealityInputAction.None : MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1];
                    actionDescription.stringValue   = inputAction.Description;
                    actionConstraint.enumValueIndex = (int)inputAction.AxisConstraint;
                }

                if (GUILayout.Button(MinusButtonContent, EditorStyles.miniButtonRight, GUILayout.Width(24f)))
                {
                    list.DeleteArrayElementAtIndex(i);
                }

                EditorGUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();
            GUILayout.EndVertical();
        }