// Update is called once per frame void Update() { if (active) { MLInputController controller = _controllerConnectionHandler.ConnectedController; float sliderBarWidth = playbackSlider.transform.Find("BaseBar").GetComponent <RectTransform>().rect.width *playbackSlider.transform.Find("BaseBar").localScale.x; if (!controller.Touch1Active) { thumbDown = false; } else if (thumbDown) { float delta = controller.Touch1PosAndForce.x - previousThumbX; previousThumbX = controller.Touch1PosAndForce.x; playbackSlider.transform.Find("Slider").localPosition = playbackSlider.transform.Find("Slider").localPosition + new Vector3(200 * delta, 0, 0); if (playbackSlider.transform.Find("Slider").localPosition.x > sliderBarWidth / 2) { playbackSlider.transform.Find("Slider").localPosition = new Vector3(375, 0, 0); } else if (playbackSlider.transform.Find("Slider").localPosition.x < -sliderBarWidth / 2) { playbackSlider.transform.Find("Slider").localPosition = new Vector3(-375, 0, 0); } sliderPosition = playbackSlider.transform.Find("Slider").transform.localPosition.x; //UpdateSliderValueLogarithm(playbackSlider.transform.Find("Slider").localPosition.x / sliderBarWidth + 0.5f); UpdateSliderValueLinear(playbackSlider.transform.Find("Slider").localPosition.x / sliderBarWidth + 0.5f); } else if (_controllerConnectionHandler.ConnectedController.Touch1Active) { thumbDown = true; previousThumbX = controller.Touch1PosAndForce.x; } } }
/// <summary> /// Find the point on the slider that's closest to the line defined by /// the controller's position and direction. /// </summary> /// <param name="controller">Information on the controller</param> private void HandleControllerDrag(MLInputController controller) { // Line 1 is the Controller's ray Vector3 P1World = controller.Position; Vector3 V1World = controller.Orientation * Vector3.forward; // Put controller position and orientation into slider space, as relative end points are in slider space Vector3 P1 = transform.InverseTransformPoint(P1World); Vector3 V1 = transform.InverseTransformVector(V1World); // Line 2 is the slider Vector3 P2 = _beginRelative; Vector3 V2 = _endRelative - _beginRelative; Vector3 deltaP = P2 - P1; float V21 = Vector3.Dot(V2, V1); float V11 = Vector3.Dot(V1, V1); float V22 = Vector3.Dot(V2, V2); float tNum = Vector3.Dot(deltaP, V21 * V1 - V11 * V2); float tDen = V22 * V11 - V21 * V21; // Lines are parallel if (Mathf.Approximately(tDen, 0.0f)) { return; } // closest point on Line 2 to Line 1 is P2 + t * V2 // but we're only concerned with t Value = tNum / tDen; }
void Awake() { MLInput.Start(); // to start receiving input from the controller // MLInput.OnControllerButtonDown += OnButtonDown; // set button down listener //MLInput.OnControllerButtonDown += OnButtonDown; // Bumper button _controller = MLInput.GetController(MLInput.Hand.Left); }
private void OnTriggerDown(byte controllerId, float triggerValue) { GameObject ball = Instantiate(_shootingPrefab); script = controller.GetComponent <ControllerConnectionHandler>(); MLInputController connectedController = script.ConnectedController; connectedController.StartFeedbackPatternVibe(_pattern, _intensity); audioSource.PlayOneShot(createAudio); ball.SetActive(true); float ballsize = MAX_BALL_SIZE; ball.transform.localScale = new Vector3(ballsize, ballsize, ballsize); // ball.transform.position = _camera.gameObject.transform.position; Vector3 vec = new Vector3(racket.transform.position.x, racket.transform.position.y - 0.3f, racket.transform.position.z); ball.transform.position = vec; Rigidbody rigidBody = ball.GetComponent <Rigidbody>(); if (rigidBody == null) { rigidBody = ball.AddComponent <Rigidbody>(); } // rigidBody.AddForce(racket.transform.up * -SHOOTING_FORCE); // Destroy(ball, BALL_LIFE_TIME); }
/// <summary> /// Handles the event for button up. /// </summary> /// <param name="controller_id">The id of the controller.</param> /// <param name="button">The button that is being released.</param> private void HandleOnButtonUp(byte controllerId, MLInputControllerButton button) { MLInputController controller = _controllerConnectionHandler.ConnectedController; if (controller != null && controller.Id == controllerId && button == MLInputControllerButton.Bumper) { // Demonstrate haptics using callbacks. controller.StartFeedbackPatternVibe(MLInputControllerFeedbackPatternVibe.ForceUp, MLInputControllerFeedbackIntensity.Medium); if (!Started) { Started = true; ballInstance.GetComponent <Rigidbody>().useGravity = true; InfoText.text = "Press Bumper to restart"; } else { InfoText.text = "Place your track down, and press the bumper to start."; ballInstance.GetComponent <Rigidbody>().useGravity = true; ballInstance.position = StartPoint; Started = false; } } }
/// <summary> /// Update the touchpad's indicator: (location, directions, color). /// Also updates the color of the touchpad, based on pressure. /// </summary> private void UpdateTouchpadIndicator() { if (!_controllerConnectionHandler.IsControllerValid()) { return; } MLInputController controller = _controllerConnectionHandler.ConnectedController; Vector3 updatePosition = new Vector3(controller.Touch1PosAndForce.x, 0.0f, controller.Touch1PosAndForce.y); float touchY = _touchIndicatorTransform.localPosition.y; _touchIndicatorTransform.localPosition = new Vector3(updatePosition.x * _touchpadRadius, touchY, updatePosition.z * _touchpadRadius); if (controller.Touch1Active) { _touchIndicatorTransform.gameObject.SetActive(true); float angle = Mathf.Atan2(controller.Touch1PosAndForce.x, controller.Touch1PosAndForce.y); _touchIndicatorTransform.localRotation = Quaternion.Euler(0, angle * Mathf.Rad2Deg, 0); } else { _touchIndicatorTransform.gameObject.SetActive(false); } float force = controller.Touch1PosAndForce.z; _touchpadMaterial.color = Color.Lerp(_defaultColor, _activeColor, force); }
private void HandleControlConnected(byte controlId) { //we just want to work with the control: MLInputController connectedControl = MLInput.GetController(controlId); switch (handedness) { case ControlHandedness.Any: Initialize(MLInput.GetController(controlId)); break; case ControlHandedness.Left: if (connectedControl.Hand == MLInput.Hand.Left) { Initialize(MLInput.GetController(controlId)); } break; case ControlHandedness.Right: if (connectedControl.Hand == MLInput.Hand.Right) { Initialize(MLInput.GetController(controlId)); } break; } }
/// <summary> /// Initialize variables, callbacks and check null references. /// </summary> void Start() { MLResult result = MLInput.Start(); if (!result.IsOk) { Debug.LogError("Error ControllerTransform starting MLInput, disabling script."); enabled = false; return; } _camera = Camera.main; MLInputController controller = MLInput.GetController(_hand); if (controller != null && controller.Connected && ((uint)(controller.Type) & (uint)(_devices)) != 0) { _mlInputController = controller; } else { _mlInputController = null; } MLInput.OnControllerConnected += HandleOnControllerConnected; MLInput.OnControllerDisconnected += HandleOnControllerDisconnected; }
// Start is called before the first frame update void Start() { positions = new List <Vector3>(); _controllerConnectionHandler = FindObjectOfType <ControllerConnectionHandler>(); controller = _controllerConnectionHandler.ConnectedController; controllerStats = Vector3.zero; }
// Start is called before the first frame update void Start() { MLInput.Start(); controller = MLInput.GetController(MLInput.Hand.Left); controller.OnButtonDown += HandleButtonDown; currentMenu = objectsToPlace[0]; }
void Awake() { MLInput.Start(); MLInput.OnControllerButtonDown += OnButtonDown; MLInput.OnControllerButtonUp += OnButtonUp; _controller = MLInput.GetController(MLInput.Hand.Left); }
void Awake() { MLInput.Start(); MLInput.OnControllerButtonDown += OnButtonDown; MLInput.OnControllerButtonUp += OnButtonUp; soldier.SetActive(false); _controller = MLInput.GetController(MLInput.Hand.Left); zoominDic.Add(CameraState.OverviewMain, CameraState.CloseUpMain); zoominDic.Add(CameraState.CloseUpMain, CameraState.FirstPersonMain); zoominDic.Add(CameraState.OverviewIslandOne, CameraState.CloseUpIslandOne); zoominDic.Add(CameraState.CloseUpIslandOne, CameraState.FirstPersonIslandOne); zoominDic.Add(CameraState.OverviewIslandTwo, CameraState.CloseUpIslandTwo); zoominDic.Add(CameraState.CloseUpIslandTwo, CameraState.FirstPersonIslandTwo); zoominDic.Add(CameraState.OverviewResIslandOne, CameraState.CloseUpResIslandOne); zoominDic.Add(CameraState.OverviewResIslandTwo, CameraState.CloseUpResIslandTwo); zoomoutDic.Add(CameraState.FirstPersonMain, CameraState.CloseUpMain); zoomoutDic.Add(CameraState.CloseUpMain, CameraState.OverviewMain); zoomoutDic.Add(CameraState.FirstPersonIslandOne, CameraState.CloseUpIslandOne); zoomoutDic.Add(CameraState.CloseUpIslandOne, CameraState.OverviewIslandOne); zoomoutDic.Add(CameraState.FirstPersonIslandTwo, CameraState.CloseUpIslandTwo); zoomoutDic.Add(CameraState.CloseUpIslandTwo, CameraState.OverviewIslandTwo); zoomoutDic.Add(CameraState.CloseUpResIslandOne, CameraState.OverviewResIslandOne); zoomoutDic.Add(CameraState.CloseUpResIslandTwo, CameraState.OverviewResIslandTwo); zoomoutReadyTM = zoomoutReady.GetComponent <TextMeshPro>(); zoomoutReadyTM.text = "Zoomout Ready"; zoomoutReady.SetActive(false); }
// Start is called before the first frame update void Start() { controller = FindObjectOfType <ControllerConnectionHandler>().ConnectedController; MLInput.OnControllerTouchpadGestureEnd += ChangeView; foreach (GameObject obj in FrontDisplayViews) { obj.SetActive(false); } if (FrontDisplayViews.Length == 0) { FrontDisplayViews = new GameObject[transform.childCount]; for (var i = 0; i < FrontDisplayViews.Length; i++) { FrontDisplayViews[i] = transform.GetChild(i).gameObject; } } if (FrontDisplayViews.Length > 0) { FrontDisplayViews[0].SetActive(true); for (var i = 1; i < FrontDisplayViews.Length; i++) { FrontDisplayViews[i].SetActive(false); } } currentIndex = 0; }
void Start() { //Start receiving input by the Control MLInput.Start(); MLInput.OnControllerButtonDown += OnButtonDown; _controller = MLInput.GetController(MLInput.Hand.Left); }
/// <summary> /// Handles the event for controller disconnected. /// Remove controller reference if controller id matches /// with disconnected controller. /// </summary> /// <param name="controllerId"> The id of the controller. </param> private void HandleOnControllerDisconnected(byte controllerId) { if (_mlInputController != null && _mlInputController.Id == controllerId) { _mlInputController = null; } }
// Handles the Frame Event private void UpdateMarker() { MLInputController controller = _controllerConnectionHandler.ConnectedController; cursorObject.transform.position = controller.Position; cursorObject.transform.rotation = controller.Orientation; }
// Use this for initialization void Start() { MLInput.Start(); controller = MLInput.GetController(MLInput.Hand.Left); Debug.Log(controller.Position); Debug.Log(controller.Orientation); }
public bool IsTriggerDown() { MLInputController mlInputController = ControllerConnectionHandler.ConnectedController; if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.F)) { _lastTriggerTime = Time.realtimeSinceStartup; return(true); } if (mlInputController == null) { return(false); } bool isTriggerDown = mlInputController.TriggerValue > 0.2f; float timeSinceLastOne = Time.realtimeSinceStartup - _lastTriggerTime; bool shouldTrigger = isTriggerDown && timeSinceLastOne > TriggerThrottleTime; if (shouldTrigger) { _lastTriggerTime = Time.realtimeSinceStartup; } return(shouldTrigger); }
//Private Methods: private void GetControl() { for (int i = 0; i < 2; ++i) { MLInputController control = MLInput.GetController(i); if (control.Type == MLInputControllerType.Control) { switch (handedness) { case ControlHandedness.Any: Initialize(control); break; case ControlHandedness.Left: if (control.Hand == MLInput.Hand.Left) { Initialize(control); } break; case ControlHandedness.Right: if (control.Hand == MLInput.Hand.Right) { Initialize(control); } break; } } } }
/// <summary> /// Validate variables /// </summary> void Start() { if (null == _visualizer) { Debug.LogError("MasterMaterialController._visualizer not set, disabling script"); enabled = false; return; } _materialControllers = GetComponents <MaterialController>(); if (_materialControllers.Length < 1) { Debug.LogError("MasterMaterialController._materialControllers is empty, disabling script."); enabled = false; return; } MLResult result = MLInput.Start(); if (!result.IsOk) { Debug.LogError("Error MasterMaterialController starting MLInput, disabling script."); enabled = false; return; } _statusText.text = ""; _controller = MLInput.GetController(MLInput.Hand.Left); MLInput.OnControllerButtonUp += HandleOnButtonUp; }
/// <summary> /// Updates text to specify the latest status of the controller. /// </summary> void Update() { if (_controllerConnectionHandler.enabled) { if (_controllerConnectionHandler.IsControllerValid()) { MLInputController controller = _controllerConnectionHandler.ConnectedController; if (controller.Type == MLInputControllerType.Control) { _controllerStatusText.text = "Controller Connected"; _controllerStatusText.color = Color.green; } else if (controller.Type == MLInputControllerType.MobileApp) { _controllerStatusText.text = "MCA Connected"; _controllerStatusText.color = Color.green; } else { _controllerStatusText.text = "Unknown"; _controllerStatusText.color = Color.red; } } else { _controllerStatusText.text = "Disconnected"; _controllerStatusText.color = Color.yellow; } } else { _controllerStatusText.text = "Input Failed to Start"; _controllerStatusText.color = Color.red; } }
/// <summary> /// Handles the event for controller connected. /// Assign controller to connected controller if desired hand matches /// with new connected controller. /// </summary> /// <param name="controllerId"> The id of the controller. </param> private void HandleOnControllerConnected(byte controllerId) { if (_hand == MLInput.GetController(controllerId).Hand) { _mlInputController = MLInput.GetController(controllerId); } }
/// <summary> /// Handles the event for trigger down. /// </summary> /// <param name="controller_id">The id of the controller.</param> /// <param name="value">The value of the trigger button.</param> private void HandleOnTriggerDown(byte controllerId, float value) { MLInputController controller = _controllerConnectionHandler.ConnectedController; if (controller != null && controller.Id == controllerId) { MLInputControllerFeedbackIntensity intensity = (MLInputControllerFeedbackIntensity)((int)(value * 2.0f)); controller.StartFeedbackPatternVibe(MLInputControllerFeedbackPatternVibe.Buzz, intensity); //public void SetParent(GameObject Cube) //{ // //Makes the GameObject "newParent" the parent of the GameObject "player". // controller.transform.parent = Cube.transform; // //Display the parent's name in the console. // Debug.Log("Player's Parent: " + controller.transform.parent.name); // // Check if the new parent has a parent GameObject. // if (Cube.transform.parent != null) // { // //Display the name of the grand parent of the player. // Debug.Log("Player's Grand parent: " + controller.transform.parent.parent.name); // } //} } }
/// <summary> /// Initialize variables, callbacks and check null references. /// </summary> void Start() { MLResult result = MLInput.Start(); if (!result.IsOk) { Debug.LogError("Error ControllerFeedbackExample starting MLInput, disabling script."); enabled = false; return; } MLInputController controller = MLInput.GetController(_hand); if (controller != null && controller.Connected && (controller.Type == MLInputControllerType.Control)) { _mlInputController = controller; } else { _mlInputController = null; } MLInput.OnControllerConnected += HandleOnControllerConnected; MLInput.OnControllerDisconnected += HandleOnControllerDisconnected; MLInput.OnControllerButtonUp += HandleOnButtonUp; MLInput.OnControllerButtonDown += HandleOnButtonDown; MLInput.OnTriggerDown += HandleOnTriggerDown; }
private void HandleOnTriggerDown(byte controllerId, float value) { MLInputController controller = _controllerConnectionHandler.ConnectedController; if (controller != null && controller.Id == controllerId) { MLInputControllerFeedbackIntensity intensity = (MLInputControllerFeedbackIntensity)((int)(value * 2.0f)); controller.StartFeedbackPatternVibe(MLInputControllerFeedbackPatternVibe.Buzz, intensity); Vector3 newPieceLocation = ControllerLocation; Vector3 newPieceRotation = ControllerRotation; //Vector3 newPieceLocation = ControllerLocation; //Vector3 newPieceRotation = ControllerRotation; if (!StartPlaced && !touchingObject) { StartPoint = newPieceLocation; ballInstance = Instantiate(Ball, newPieceLocation, Quaternion.identity); StartPlaced = true; InfoText.text = "Set end point"; } else if (!EndPlaced && !touchingObject) { EndPoint = newPieceLocation; Instantiate(EndModel, newPieceLocation, Quaternion.identity); EndPlaced = true; InfoText.text = "Place your track down, and press the bumper to start."; isReadyToStart = true; } else if (!Started && !touchingObject) { Instantiate(SelectedPrefab, newPieceLocation, Quaternion.Euler(newPieceRotation)); } } }
void Start() { //Start receiving input by the Control MLInput.Start(); _controller = MLInput.GetController(MLInput.Hand.Left); _renderer = GetComponent <Renderer>(); }
/// <summary> /// Update the touchpad's indicator: (location, directions, color). /// Also updates the color of the touchpad, based on pressure. /// </summary> private void UpdateTouchpadIndicator() { if (!_controllerConnectionHandler.IsControllerValid()) { return; } MLInputController controller = _controllerConnectionHandler.ConnectedController; Vector3 updatePosition = new Vector3(controller.Touch1PosAndForce.x, 0.0f, controller.Touch1PosAndForce.y); float touchY = _touchIndicatorTransform.localPosition.y; _touchIndicatorTransform.localPosition = new Vector3(updatePosition.x * _touchpadRadius / MagicLeapDevice.WorldScale, touchY, updatePosition.z * _touchpadRadius / MagicLeapDevice.WorldScale); source.pitch = Mathf.Pow(2, (updatePosition.x * 10 + updatePosition.z * -4) / 12.0f); if (controller.Touch1Active) { controller.StartFeedbackPatternVibe(MLInputControllerFeedbackPatternVibe.Tick, MLInputControllerFeedbackIntensity.Medium); _touchIndicatorTransform.gameObject.SetActive(true); float angle = Mathf.Atan2(controller.Touch1PosAndForce.x, controller.Touch1PosAndForce.y); _touchIndicatorTransform.localRotation = Quaternion.Euler(0, angle * Mathf.Rad2Deg, 0); } else { _touchIndicatorTransform.gameObject.SetActive(false); } float force = controller.Touch1PosAndForce.z; _touchpadMaterial.color = Color.Lerp(_defaultColor, _activeColor, force); }
/// <summary> /// Update controller input based feedback. /// </summary> void Update() { if (_controllerConnectionHandler.IsControllerValid()) { MLInputController controller = _controllerConnectionHandler.ConnectedController; //controller_acceleration = (gameObject.GetComponent<Rigidbody>().velocity - controller_velocity) / Time.deltaTime; //text.text = "last_velocity" + controller_velocity.ToString() + "\n" // + "v" + gameObject.GetComponent<Rigidbody>().velocity + "\n" // + "acce:" + controller_acceleration.magnitude.ToString(); //controller_velocity = (gameObject.GetComponent<Rigidbody>().velocity); if (controller.Type == MLInputControllerType.Control) { // For Control, raw input is enough transform.localPosition = controller.Position; transform.localRotation = controller.Orientation; } else if (controller.Type == MLInputControllerType.MobileApp) { // For Mobile App, there is no positional data and orientation needs calibration transform.position = _camera.transform.position + (_camera.transform.forward * MOBILEAPP_FORWARD_DISTANCE_FROM_CAMERA * MagicLeapDevice.WorldScale) + (Vector3.up * MOBILEAPP_UP_DISTANCE_FROM_CAMERA * MagicLeapDevice.WorldScale); if (_isCalibrated) { transform.localRotation = _calibrationOrientation * controller.Orientation; } else { transform.LookAt(transform.position + Vector3.up, -Camera.main.transform.forward); } } } }
/// <summary> /// Update controller input based feedback. /// </summary> void Update() { if (_controllerConnectionHandler.IsControllerValid()) { MLInputController controller = _controllerConnectionHandler.ConnectedController; if (controller.Type == MLInputControllerType.Control) { // For Control, raw input is enough transform.localPosition = controller.Position; transform.localRotation = controller.Orientation; } else if (controller.Type == MLInputControllerType.MobileApp) { // For Mobile App, there is no positional data and orientation needs calibration transform.position = _camera.transform.position + (_camera.transform.forward * MOBILEAPP_FORWARD_DISTANCE_FROM_CAMERA * MagicLeapDevice.WorldScale) + (Vector3.up * MOBILEAPP_UP_DISTANCE_FROM_CAMERA * MagicLeapDevice.WorldScale); if (_isCalibrated) { transform.rotation = _calibrationOrientation * controller.Orientation; } else { transform.LookAt(transform.position + Vector3.up, -Camera.main.transform.forward); } } } }
/// <summary> /// Handles the event for trigger down. /// </summary> /// <param name="controller_id">The id of the controller.</param> /// <param name="value">The value of the trigger button.</param> private void HandleOnTriggerDown(byte controllerId, float value) { bool isEditor = false; #if UNITY_EDITOR isEditor = true; #endif MLInputController controller = _controllerConnectionHandler?.ConnectedController; if ((controller != null && controller.Id == controllerId) || isEditor) { gameData.Player.Score += Random.Range(1, 100); gameData.Player.MinutesPlayed += Random.Range(1, 100); try { serializerManager.SaveGameData(gameData); // reload JSON data from filesystem gameData = serializerManager.LoadGameData(); PopulateUIGameData(); } catch (System.Exception e) { serializedData.text = e.Message; serializerStatus.text = "Error"; } } }