// Use this for initialization void Start() { if (mlController != null) { // Approach 1: Define callback function elsewhere mlController.OnMagicLeapControllerTouchpadGestureEnded += (MagicLeapController controller, MagicLeapController.GestureType gestureType, Dictionary <string, object> gestureParams) => { if (controller != GetComponent <MagicLeapController>()) { // Catch for multiple controllers return; } // Only radial scroll is implemented here as an abstraction, but you can catch others as well // by fleshing out MagicLeapController.GestureType switch (gestureType) { case MagicLeapController.GestureType.RadialScroll: MLInputControllerTouchpadGesture gesture = (MLInputControllerTouchpadGesture)gestureParams["gesture"]; TextLog("Radial Scroll: " + gesture.Direction); break; } }; // Approach 2: Define callback function elsewhere and reference it here mlController.OnMagicLeapControllerButtonStateChange += MagicLeapControllerButtonStateChange; } }
/// <summary> /// Handler when touchpad gesture continues /// </summary> /// <param name="controllerId">Controller ID</param> /// <param name="touchpadGesture">Touchpad Gesture</param> private void HandleTouchpadGestureContinue(byte controllerId, MLInputControllerTouchpadGesture touchpadGesture) { if (!_controller.IsControllerValid(controllerId)) { return; } if (_deleteAllInitiated) { if (touchpadGesture.Type == MLInputControllerTouchpadGestureType.RadialScroll) { ++_deleteAllSequenceFrameCount; if (_deleteAllSequenceFrameCount < _deleteAllSequenceMinFrames) { _statusText.text = string.Format("<color=yellow>Delete All sequence {0:P} complete.</color>", (float)(_deleteAllSequenceFrameCount) / _deleteAllSequenceMinFrames); } else { MLPersistentStore.DeleteAll(); foreach (var pointBehavior in _pointBehaviors) { Instantiate(_destroyedContentEffect, pointBehavior.transform.position, Quaternion.identity); Destroy(pointBehavior.gameObject); } _pointBehaviors.Clear(); _statusText.text = string.Format("<color=green>Delete All complete.</color>"); _deleteAllInitiated = false; } } } }
private void OnTouchpadGestureEnd(byte controllerId, MLInputControllerTouchpadGesture gesture) { if (gesture.Type.Equals(MLInputControllerTouchpadGestureType.RadialScroll)) { DebugOn = !DebugOn; ToggleTrackerVisibility(DebugOn); } if (gesture.Type.Equals(MLInputControllerTouchpadGestureType.Swipe)) { if (gesture.Direction.Equals(MLInputControllerTouchpadGestureDirection.Left)) { PreviousBubbleColor(); } if (gesture.Direction.Equals(MLInputControllerTouchpadGestureDirection.Right)) { NextBubbleColor(); } // if (gesture.Direction.Equals(MLInputControllerTouchpadGestureDirection.Up)) { // PreviousParticle(); // } // if (gesture.Direction.Equals(MLInputControllerTouchpadGestureDirection.Down)) { // NextParticle(); // } } }
private void OnTouchpadGestureEnd(byte controller_id, MLInputControllerTouchpadGesture gesture) { if (gesture.Type.Equals(MLInputControllerTouchpadGestureType.RadialScroll)) { _debugOn = !_debugOn; _fingerTracking.ToogleTrackerVisibility(_debugOn); } }
/// <summary> /// Handles the event for touchpad gesture start. Changes level of detail /// if gesture is swipe up. /// </summary> /// <param name="controllerId">The id of the controller.</param> /// <param name="gesture">The gesture getting started.</param> private void OnTouchpadGestureStart(byte controllerId, MLInputControllerTouchpadGesture gesture) { if (_controllerConnectionHandler.IsControllerValid(controllerId) && gesture.Type == MLInputControllerTouchpadGestureType.Swipe && gesture.Direction == MLInputControllerTouchpadGestureDirection.Up) { _mlSpatialMapper.levelOfDetail = ((_mlSpatialMapper.levelOfDetail == MLSpatialMapper.LevelOfDetail.Maximum) ? MLSpatialMapper.LevelOfDetail.Minimum : (_mlSpatialMapper.levelOfDetail + 1)); } }
/// <summary> /// Handles the event for touchpad gesture start. Changes level of detail /// if gesture is swipe up. /// </summary> /// <param name="controller_id">The id of the controller.</param> /// <param name="gesture">The gesture getting started.</param> private void OnTouchpadGestureStart(byte controller_id, MLInputControllerTouchpadGesture gesture) { if (gesture.Type == MLInputControllerTouchpadGestureType.Swipe && gesture.Direction == MLInputControllerTouchpadGestureDirection.Up) { _mlSpatialMapper.levelOfDetail = ((_mlSpatialMapper.levelOfDetail == MLSpatialMapper.LevelOfDetail.Maximum) ? MLSpatialMapper.LevelOfDetail.Minimum : (_mlSpatialMapper.levelOfDetail + 1)); UpdateStatusText(); } }
private void OnTouchpadGestureStart(byte controllerId, MLInputControllerTouchpadGesture gesture) { if (controllerConnectionHandler.IsControllerValid(controllerId) && gesture.Type == MLInputControllerTouchpadGestureType.Swipe && gesture.Direction == MLInputControllerTouchpadGestureDirection.Up) { renderMode = (MeshingVisualizer.RenderMode)((int)(renderMode + 1) % renderModeCount); meshingVisualizer.SetRenderers(renderMode); } }
/// <summary> /// Handler for Tap gesture. /// </summary> /// <param name="controllerId">Controller ID</param> /// <param name="touchpadGesture">Touchpad Gesture</param> private void HandleTouchpadGestureStart(byte controllerId, MLInputControllerTouchpadGesture touchpadGesture) { if (_controllerHandler.IsControllerValid() && _controllerHandler.ConnectedController.Id == controllerId && touchpadGesture.Type == MLInputControllerTouchpadGestureType.Tap && _prevButton != null) { _prevButton.Tap(); } }
private void MLInput_OnTouchpadGestureEnd(byte controller_id, MLInputControllerTouchpadGesture gesture) { Dictionary<string, object> gestureParams = new Dictionary<string, object>(); if (gesture.Type.Equals(MLInputControllerTouchpadGestureType.RadialScroll)) { gestureParams["gesture"] = gesture; if (OnMagicLeapControllerTouchpadGestureEnded != null) { OnMagicLeapControllerTouchpadGestureEnded(this, ConvertedGesture(gesture.Type), gestureParams); } } }
/// <summary> /// Handles the event for touchpad gesture start. Changes amount of triangles per /// block if gesture is swipe up. /// </summary> /// <param name="controller_id">The id of the controller.</param> /// <param name="gesture">The gesture getting started.</param> private void OnTouchpadGestureStart(byte controller_id, MLInputControllerTouchpadGesture gesture) { if (gesture.Type == MLInputControllerTouchpadGestureType.Swipe && gesture.Direction == MLInputControllerTouchpadGestureDirection.Up) { _trianglesPerBlockIndex = (uint)((_trianglesPerBlockIndex + 1) % _trianglesPerBlockSettings.Length); _spatialMapper.MLSpatialMapper.targetNumberTrianglesPerblock = (uint)(_trianglesPerBlockSettings[_trianglesPerBlockIndex]); _spatialMapper.ClearFragments(); UpdateStatusText(); } }
/// <summary> /// Handler for Gesture Start events /// </summary> /// <param name="controllerId">Controller Id</param> /// <param name="gesture">Touchpad Gesture</param> private void HandleControllerTouchpadGestureStart(byte controllerId, MLInputControllerTouchpadGesture gesture) { if (_controllerConnectionHandler != null && _controllerConnectionHandler.IsControllerValid(controllerId) && gesture.Type == MLInputControllerTouchpadGestureType.Tap) { if (OnContentDestroy != null) { OnContentDestroy(gameObject); } } }
/// <summary> /// Handler when touchpad gesture begins /// </summary> /// <param name="controllerId">Controller ID</param> /// <param name="touchpadGesture">Touchpad Gesture</param> private void HandleTouchpadGestureStart(byte controllerId, MLInputControllerTouchpadGesture touchpadGesture) { if (!_controller.IsControllerValid(controllerId)) { return; } if (touchpadGesture.Type == MLInputControllerTouchpadGestureType.RadialScroll) { _deleteAllInitiated = true; _deleteAllSequenceFrameCount = 0; } }
private void HandleControllerTouchpadGestureContinue(byte controllerId, MLInputControllerTouchpadGesture gesture) { MLInputController controller = _controllerConnectionHandler.ConnectedController; if (gesture.Direction == MLInputControllerTouchpadGestureDirection.Up) { solarSystem.scale += gesture.Speed * 1000f; } else if (gesture.Direction == MLInputControllerTouchpadGestureDirection.Up) { solarSystem.scale -= gesture.Speed * 1000f; } }
private void HandleOnTouchpadGestureEnd(byte controllerId, MLInputControllerTouchpadGesture gesture) { if (Vector3.Angle(transform.position - Camera.main.transform.position, Camera.main.transform.forward) < 15) { if (gesture.Direction == MLInputControllerTouchpadGestureDirection.Right) { CycleObject(1); } else if (gesture.Direction == MLInputControllerTouchpadGestureDirection.Left) { CycleObject(-1); } } }
/// <summary> /// Update swiping counters to update textures if swipe left or right. /// </summary> /// <param name="controllerId">The id of the controller.</param> /// <param name="gesture">Touchpad gesture getting done.</param> private void HandleOnTouchpadGestureEnd(byte controllerId, MLInputControllerTouchpadGesture gesture) { if (_controllerConnectionHandler.IsControllerValid(controllerId) && gesture.Type == MLInputControllerTouchpadGestureType.Swipe) { if (gesture.Direction == MLInputControllerTouchpadGestureDirection.Right) { --swipeRight; } else if (gesture.Direction == MLInputControllerTouchpadGestureDirection.Left) { --swipeLeft; } } }
private void ChangeView(byte controllerId, MLInputControllerTouchpadGesture touchpad) { if (touchpad.Direction == MLInputControllerTouchpadGestureDirection.Right) { controller.StartFeedbackPatternVibe(MLInputControllerFeedbackPatternVibe.Buzz, MLInputControllerFeedbackIntensity.Medium); cycleView(1); Invoke("StopVibrating", 0.5f); } else if (touchpad.Direction == MLInputControllerTouchpadGestureDirection.Left) { controller.StartFeedbackPatternVibe(MLInputControllerFeedbackPatternVibe.Buzz, MLInputControllerFeedbackIntensity.Medium); cycleView(-1); Invoke("StopVibrating", 0.5f); } }
/// <summary> /// Handler when touchpad gesture ends /// </summary> /// <param name="controllerId">Controller ID</param> /// <param name="touchpadGesture">Touchpad Gesture</param> private void HandleTouchpadGestureEnd(byte controllerId, MLInputControllerTouchpadGesture touchpadGesture) { if (!_controller.IsControllerValid(controllerId)) { return; } if (_deleteAllInitiated) { if (touchpadGesture.Type == MLInputControllerTouchpadGestureType.RadialScroll && _deleteAllSequenceFrameCount < _deleteAllSequenceMinFrames) { _statusText.text = string.Format("Delete All sequence aborted!"); _deleteAllInitiated = false; } } }
private void OnTouchContinue(byte controllerId, MLInputControllerTouchpadGesture touchpadGesture) { MLInputController controller = _controllerConnectionHandler.ConnectedController; if (isActive && controller != null && controller.Id == controllerId) { if (Mathf.Abs(controller.Touch1PosAndForce.x) + Mathf.Abs(controller.Touch1PosAndForce.z) > 1) { controller.StartFeedbackPatternVibe(MLInputControllerFeedbackPatternVibe.Tick, MLInputControllerFeedbackIntensity.High); } else if (Mathf.Abs(controller.Touch1PosAndForce.x) + Mathf.Abs(controller.Touch1PosAndForce.z) > 0) { controller.StartFeedbackPatternVibe(MLInputControllerFeedbackPatternVibe.Click, MLInputControllerFeedbackIntensity.Medium); } } }
private void switchMode(byte controllerId, MLInputControllerTouchpadGesture touchpad) { SetMode(modes[modeIndex], false); if (touchpad.Direction == MLInputControllerTouchpadGestureDirection.Up) { controller.StartFeedbackPatternVibe(MLInputControllerFeedbackPatternVibe.Buzz, MLInputControllerFeedbackIntensity.Medium); modeIndex = (modeIndex + 1) % modes.Length; GameObject.Find("StatusText").GetComponent <Text>().text = char.ToUpper(modes[modeIndex][0]) + modes[modeIndex].Substring(1); Invoke("ClearHUDText", 5); Invoke("StopVibrating", 0.5f); } else if (touchpad.Direction == MLInputControllerTouchpadGestureDirection.Down) { controller.StartFeedbackPatternVibe(MLInputControllerFeedbackPatternVibe.Buzz, MLInputControllerFeedbackIntensity.Medium); modeIndex = (modeIndex + modes.Length - 1) % modes.Length; GameObject.Find("StatusText").GetComponent <Text>().text = char.ToUpper(modes[modeIndex][0]) + modes[modeIndex].Substring(1); Invoke("ClearHUDText", 5); Invoke("StopVibrating", 0.5f); } SetMode(modes[modeIndex], true); }
private void HandleOnTouchpadGestureStart(byte controllerId, MLInputControllerTouchpadGesture gesture) { if (_controllerConnectionHandler.IsControllerValid(controllerId) && gesture.Type == MLInputControllerTouchpadGestureType.Swipe) { // Increase / Decrease the marker distance based on the swipe gesture. if (gesture.Direction == MLInputControllerTouchpadGestureDirection.Up) { if (_marker.localPosition.z < MAXIMUM_DISTANCE_METERS) { _marker.localPosition = new Vector3(0, 0, _marker.localPosition.z + ADJUSTMENT_DISTANCE_METERS); } } else if (gesture.Direction == MLInputControllerTouchpadGestureDirection.Down) { if (_marker.localPosition.z > MINIMUM_DISTANCE_METERS) { _marker.localPosition = new Vector3(0, 0, _marker.localPosition.z - ADJUSTMENT_DISTANCE_METERS); } } } }
public void CheckHasFocusBrain() { Debug.Log("Brain Split Animation Initiated"); MLInputController mlInputController = MLInput.GetController(0); MLInputControllerTouchpadGesture gesture = mlInputController.TouchpadGesture; MLInputControllerTouchpadGestureType gestureType = gesture.Type; if (gestureType == MLInputControllerTouchpadGestureType.Swipe) { brainAnimator.SetBool("SplitBrain", true); brainAnimatorUnlit.SetBool("SplitBrain", true); swipeAnim.SetActive(false); UIInstructionText.text = ""; AudioManager._instance.PlayAudio(0); gameSequenceInt++; } }
void SetButton(byte action, MLInputControllerTouchpadGesture gesture) { Debug.Log("getsure"); if (gesture.Direction == MLInputControllerTouchpadGestureDirection.Left) { buttonInd--; if (buttonInd < 0) { buttonInd = buttons.Length - 1; } SelectTarget(buttons[buttonInd]); } else if (gesture.Direction == MLInputControllerTouchpadGestureDirection.Right) { buttonInd++; if (buttonInd > buttons.Length - 1) { buttonInd = 0; } SelectTarget(buttons[buttonInd]); } }
// Update is called once per frame void Update() { if (controller == null) { return; } MLInputControllerTouchpadGesture gesture = controller.TouchpadGesture; if (gesture != null) { text.text = gesture.Radius.ToString(); } else { text.text = "Can't get the gesture of controller"; } transform.position = controller.Position + new Vector3(0.3f, 1.0f, 0.05f); transform.rotation = controller.Orientation; }