/// <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);
                    }
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Toggle viewing custom materials and plane borders on button press
 /// </summary>
 /// <param name="controllerId">The id of the controller.</param>
 /// <param name="button">The button that is being released.</param>
 private void HandleOnButtonUp(byte controllerId, MLInputControllerButton button)
 {
     if (_controllerConnectionHandler.IsControllerValid(controllerId) && button == MLInputControllerButton.Bumper)
     {
         _visualizer.ToggleShowingPlanes();
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Handles the event for button down. Starts or stops recording.
 /// </summary>
 /// <param name="controllerId">The id of the controller.</param>
 /// <param name="button">The button that is being pressed.</param>
 private void OnButtonDown(byte controllerId, MLInputControllerButton button)
 {
     if (_controllerConnectionHandler.IsControllerValid(controllerId) && MLInputControllerButton.HomeTap == button)
     {
         if (_homePresses < 7)
         {
             _homePresses++;
         }
         else // After all world markers are instantiated, Home button enables and disables recording
         {
             if (!_isCapturing)
             {
                 EnableMLCamera();
                 StartCapture();
             }
             else
             {
                 EndCapture();
                 DisableMLCamera();
             }
         }
     }
     if (_controllerConnectionHandler.IsControllerValid(controllerId) && MLInputControllerButton.Bumper == button)
     {
         if (!_isCapturing)
         {
             // StartCapture();
         }
         else
         {
             OnRawVideoDataReceived?.Invoke(_cached_extras, _cached_frameData, _cached_frameMetadata);
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Toggle viewing custom materials and plane borders on button press
 /// </summary>
 /// <param name="controllerId">The id of the controller.</param>
 /// <param name="button">The button that is being released.</param>
 private void HandleOnButtonUp(byte controllerId, MLInputControllerButton button)
 {
     if (_controllerConnectionHandler.IsControllerValid(controllerId) && button == MLInputControllerButton.Bumper)
     {
         _visualizer.CycleMode();
     }
 }
    // Update is called once per frame
    void Update()
    {
        if (!_controllerConnectionHandler.IsControllerValid() || subMenuInUse)
        {
            return;
        }
        if (!centerButton.activeSelf && clickStyle == MenuClickStyle.Trigger)
        {
            return;
        }
        GameObject currentButton = getHoveredButton();

        // If hover style, check if there is a button to confirm
        if (clickStyle == MenuClickStyle.Hover && currentButton == null)
        {
            if (pressedButton != null)
            {
                if (Time.time > pressThresholdTime)
                {
                    // Press that button
                    pressedButton.GetComponent <Button>().onClick.Invoke();
                }
            }
            pressedDown   = false;
            hoveredButton = null;
            SetActiveMenu(false);
        }
        else if (currentButton != null)
        {
            hoveredButton = currentButton;
        }
    }
Esempio n. 6
0
        /// <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);
                    }
                }
            }
        }
 void Update()
 {
     if (_controllerConnectionHandler.IsControllerValid())
     {
         _vignette.VignettePower = (1 - _controllerConnectionHandler.ConnectedController.TriggerValue) * VIGNETTE_SCALE;
         UpdateStatusText();
     }
 }
 // Update is called once per frame
 void Update()
 {
     if (_controllerConnectionHandler.IsControllerValid(_MLInputController.Id))
     {
         controllerObject.transform.position = _MLInputController.Position;
         controllerObject.transform.rotation = _MLInputController.Orientation;
     }
 }
 /// <summary>
 /// Update controller input based feedback.
 /// </summary>
 void Update()
 {
     UpdateTriggerVisuals();
     UpdateTouchpadIndicator();
     #if !UNITY_EDITOR
     SetVisibility(_controllerConnectionHandler.IsControllerValid());
     #endif
 }
Esempio n. 10
0
    private void HandleOnButtonDown(byte controllerId, MLInputControllerButton button)
    {
        if (_controllerConnectionHandler.IsControllerValid() && _controllerConnectionHandler.ConnectedController.Id == controllerId &&
            button == MLInputControllerButton.Bumper)
        {
            Debug.Log("bumper down");

            ExperienceManager.Instance.OnReset();
        }
    }
Esempio n. 11
0
    // Update is called once per frame
    void Update()
    {
        // Controller model transform
        if (_controllerConnectionHandler.IsControllerValid(_MLInputController.Id))
        {
            controllerObject.transform.position = _MLInputController.Position;
            controllerObject.transform.rotation = _MLInputController.Orientation;
        }

        // Controller pointer
        RaycastHit hit;

        if (Physics.Raycast(controllerObject.transform.position, controllerObject.transform.forward, out hit, 10))
        {
            DirectorMenuButton button = hit.transform.GetComponent <DirectorMenuButton>();

            if (button != null)
            {
                if (_lastButtonHit == null)
                {
                    if (button.OnRaycastEnter != null)
                    {
                        button.OnRaycastEnter(hit.point, button.transform);
                    }
                    _lastButtonHit = button;
                }
                else if (_lastButtonHit == button)
                {
                    if (_lastButtonHit.OnRaycastContinue != null)
                    {
                        _lastButtonHit.OnRaycastContinue(hit.point, _lastButtonHit.transform.GetChild(0));
                    }
                }
                else
                {
                    if (_lastButtonHit.OnRaycastExit != null)
                    {
                        _lastButtonHit.OnRaycastExit(hit.point, _lastButtonHit.transform);
                    }
                    _lastButtonHit = null;
                }
            }
            else
            {
                if (_lastButtonHit != null)
                {
                    if (_lastButtonHit.OnRaycastExit != null)
                    {
                        _lastButtonHit.OnRaycastExit(hit.point, _lastButtonHit.transform);
                    }
                    _lastButtonHit = null;
                }
            }
        }
    }
 /// <summary>
 /// Handler for controller trigger down
 /// </summary>
 /// <param name="controllerId">Controller ID</param>
 /// <param name="triggerValue">Trigger Value (unused)</param>
 private void HandleTriggerDown(byte controllerId, float triggerValue)
 {
     if (_controllerConnectionHandler.IsControllerValid(controllerId))
     {
         if (OnBeginDrag != null)
         {
             OnBeginDrag();
         }
         _isDragging = true;
     }
 }
Esempio n. 13
0
 private void HandleOnButtonDown(byte controllerId, MLInputControllerButton button)
 {
     if (controllerDynamic == null)
     {
         return;
     }
     if (_controllerConnectionHandler.IsControllerValid() && _controllerConnectionHandler.ConnectedController.Id == controllerId &&
         button == MLInputControllerButton.Bumper)
     {
         OnButtonChanged(controllerDynamic, true, "bumper", true, CurrentButtonStates);
     }
 }
Esempio n. 14
0
    private void HandleOnButtonDown(byte controllerId, MLInputControllerButton button)
    {
        if (_controllerConnectionHandler.IsControllerValid() && _controllerConnectionHandler.ConnectedController.Id == controllerId &&
            button == MLInputControllerButton.Bumper && _placing)
        {
            // iterates to the next touch mode
            int pos = ((int)_mode + 1) % 3;
            _mode = (touchMode)pos;

            _instructions.text = _modeText[pos] + _moveText;
        }
    }
Esempio n. 15
0
 private void HandleControllerButtonDown(byte controllerId, MLInputControllerButton button)
 {
     if (_controllerConnectionHandler.IsControllerValid(controllerId) && _lastButtonHit != null && !_isGrabbing)
     {
         if (_lastButtonHit.OnControllerButtonDown != null)
         {
             _lastButtonHit.OnControllerButtonDown(button);
         }
         _pointerLight.color = _pointerLightColorHitPress;
         _isGrabbing         = true;
     }
 }
Esempio n. 16
0
        /// <summary>
        /// If the home button is pressed, reload this scene. If the bumper is pressed, EMPTY.
        /// </summary>
        /// <param name="controllerId"></param>
        /// <param name="button"></param>
        private void HandleOnButtonDown(byte controllerId, MLInputControllerButton button)
        {
            if (_controllerConnectionHandler.IsControllerValid() && _controllerConnectionHandler.ConnectedController.Id
                == controllerId && button == MLInputControllerButton.HomeTap)
            {
                if (menuActive == true)
                {
                    menuActive = false;
                    menuPanel.SetActive(false);
                    inPlacementState = true;
                    regularCanvas.SetActive(true);
                }
                else if (menuActive == false)
                {
                    menuActive = true;
                    menuPanel.SetActive(true);
                    inPlacementState = false;
                    regularCanvas.SetActive(false);
                }
            }

            if (_controllerConnectionHandler.IsControllerValid() && _controllerConnectionHandler.ConnectedController.Id == controllerId && button == MLInputControllerButton.Bumper)
            {
                if (bumperFirstPress == true)
                {
                    bumperFirstPress = false;
                }

                switch (bumperindex)                 //omg. my mind. i love me.
                {
                case 0:
                    bumperindex++;
                    _viewLabel.text = "Now viewing: Axes";
                    break;

                case 1:
                    bumperindex++;
                    _viewLabel.text = "Now viewing: Unit Vectors ";
                    break;

                case 2:
                    bumperindex     = 0;
                    _viewLabel.text = "Now viewing: Components";
                    break;

                default:
                    Debug.Log("uh. theres a mistake in ur bumper loop");
                    break;
                }
            }
        }
Esempio n. 17
0
 /// <summary>
 /// Updates effects on different input responses via input polling mechanism.
 /// </summary>
 void Update()
 {
     if (_controllerConnectionHandler.IsControllerValid())
     {
         MLInputController controller = _controllerConnectionHandler.ConnectedController;
         _modelRenderer.material.color = _origColor;
         UpdateTouchIndicator(_touch1Indicator, controller.Touch1Active, controller.Touch1PosAndForce);
         UpdateTouchIndicator(_touch2Indicator, controller.Touch2Active, controller.Touch2PosAndForce);
         UpdateHighlights();
     }
     else
     {
         _modelRenderer.material.color = Color.red;
     }
 }
Esempio n. 18
0
    private void OnButtonDown(byte controllerId, MLInputControllerButton button)
    {
        if (ControllerConnectionHandler.IsControllerValid(controllerId))
        {
            if (button == MLInputControllerButton.Bumper)
            {
                if (JohnLemon != null)
                {
                    WaypointsList.AddWaypoints(JohnLemon.transform);
                    // Quaternion rotation = Quaternion.Euler(0, raycast.transform.rotation.eulerAngles.y, 0);
                    //Matrix4x4 worldTransform = pcfTransform.localToWorldMatrix * WaypointsList.Waypoints[WaypointsList.Waypoints.Count - 1];

                    Pose       pose    = WaypointsList.GetWayPoint(WaypointsList.Waypoints.Count - 1);
                    GameObject gameObj = Instantiate(WaypointObjPrefab, pose.position, pose.rotation);
                }
            }
            else if (button == MLInputControllerButton.HomeTap)
            {
                PlayerMovement.PlayBack(WaypointsList);
                string json = JsonUtility.ToJson(WaypointsList);
                Debug.Log("Write JSON:" + json);
                System.IO.File.WriteAllText(@"/documents/C1/waypoints.json", json);
            }
        }
    }
Esempio n. 19
0
 /// <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;
     }
 }
Esempio n. 20
0
        /// <summary>
        /// Update the icon and status color depending on the controller connected.
        /// </summary>
        private void UpdateStatus()
        {
            if (_controllerConnectionHandler.enabled)
            {
                if (_controllerConnectionHandler.IsControllerValid())
                {
                    _spriteRenderer.color = Color.green;

                    switch (_controllerConnectionHandler.ConnectedController.Type)
                    {
                    case MLInputControllerType.Control:
                    {
                        _spriteRenderer.sprite = _controllerIcon;
                        break;
                    }

                    case MLInputControllerType.MobileApp:
                    {
                        _spriteRenderer.sprite = _mobileAppIcon;
                        break;
                    }
                    }
                }
                else
                {
                    _spriteRenderer.color = Color.yellow;
                }
            }
            else
            {
                _spriteRenderer.color = Color.red;
            }
        }
Esempio n. 21
0
 /// <summary>
 /// Keeps track of when the touchpad is currently pressed
 /// </summary>
 private void Update()
 {
     if (_controllerConnectionHandler != null && _controllerConnectionHandler.IsControllerValid())
     {
         touchpadEvents.pressed = _controllerConnectionHandler.ConnectedController.Touch1Active;
     }
 }
Esempio n. 22
0
 /// <summary>
 /// Handles the event for trigger down.
 /// </summary>
 /// <param name="controllerId">The id of the controller.</param>
 /// <param name="triggerValue">The value of the trigger.</param>
 private void HandleOnTriggerDown(byte controllerId, float triggerValue)
 {
     if (_hasStarted && MLImageTracker.IsStarted && _controllerConnectionHandler.IsControllerValid(controllerId))
     {
         if (MLImageTracker.GetTrackerStatus())
         {
             MLImageTracker.Disable();
             _trackerStatusLabel.text = "Tracker Status: Disabled";
         }
         else
         {
             MLImageTracker.Enable();
             _trackerStatusLabel.text = "Tracker Status: Enabled";
         }
     }
 }
Esempio n. 23
0
 /// <summary>
 /// Handles the event for button down.
 /// </summary>
 /// <param name="controllerId">The id of the controller.</param>
 /// <param name="button">The button that is being pressed.</param>
 private void OnButtonDown(byte controllerId, MLInputControllerButton button)
 {
     if (_controllerConnectionHandler.IsControllerValid(controllerId) && MLInputControllerButton.Bumper == button && !_isCapturing)
     {
         TriggerAsyncCapture();
     }
 }
 private void HandleOnButtonDown(byte controllerId, MLInputControllerButton button)
 {
     if (_controllerConnectionHandler.IsControllerValid(controllerId))
     {
         if (button == MLInputControllerButton.HomeTap)
         {
             if (state != "root")
             {
                 state = "root";
                 ToggleMenu(true);
             }
         }
         if (button == MLInputControllerButton.Bumper)
         {
             float currentVideoBool = videoMaterial.GetFloat("_VideoBool");
             if (currentVideoBool == 1.0f)
             {
                 videoMaterial.SetFloat("_VideoBool", 0.0f);
             }
             else
             {
                 videoMaterial.SetFloat("_VideoBool", 1.0f);
             }
         }
     }
 }
 private void OnButtonDown(byte controllerId, MLInputControllerButton button)
 {
     if (_controllerConnectionHandler.IsControllerValid(controllerId) && button == MLInputControllerButton.HomeTap)
     {
         BumperPress();
     }
 }
        /// <summary>
        /// Initialize variables, callbacks and check null references.
        /// </summary>
        void Start()
        {
            _controllerConnectionHandler = GetComponent <ControllerConnectionHandler>();

            #if !UNITY_EDITOR
            if (!_controllerModel)
            {
                Debug.LogError("Error: ControllerVisualizer._controllerModel is not set, disabling script.");
                enabled = false;
                return;
            }
            if (!_trigger)
            {
                Debug.LogError("Error: ControllerVisualizer._trigger is not set, disabling script.");
                enabled = false;
                return;
            }
            if (!_touchpad)
            {
                Debug.LogError("Error: ControllerVisualizer._touchpad is not set, disabling script.");
                enabled = false;
                return;
            }
            if (!_homeButton)
            {
                Debug.LogError("Error: ControllerVisualizer._homeButton is not set, disabling script.");
                enabled = false;
                return;
            }
            if (!_bumperButton)
            {
                Debug.LogError("Error: ControllerVisualizer._bumperButton is not set, disabling script.");
                enabled = false;
                return;
            }
            if (!_touchIndicatorTransform)
            {
                Debug.LogError("Error: ControllerVisualizer._touchIndicatorTransform is not set, disabling script.");
                enabled = false;
                return;
            }

            SetVisibility(_controllerConnectionHandler.IsControllerValid());
#else
            SetVisibility(true);
#endif

            MLInput.OnControllerButtonUp   += HandleOnButtonUp;
            MLInput.OnControllerButtonDown += HandleOnButtonDown;

            _triggerMaterial      = FindMaterial(_trigger);
            _touchpadMaterial     = FindMaterial(_touchpad);
            _homeButtonMaterial   = FindMaterial(_homeButton);
            _bumperButtonMaterial = FindMaterial(_bumperButton);

            // Calculate the radius of the touchpad's mesh
            Mesh mesh = _touchpad.GetComponent <MeshFilter>().mesh;
            _touchpadRadius = Vector3.Scale(mesh.bounds.extents, _touchpad.transform.lossyScale).x;
        }
 /*
  * void HandleInitialized(MLResult status)
  * {
  *  MLPersistentCoordinateFrames.OnInitialized -= HandleInitialized;
  *
  *  if (status.IsOk)
  *  {
  *      PerformPersistenceStartup();
  *  }
  * }
  *
  * private void PerformPersistenceStartup()
  * {
  *  List<MLContentBinding> allBindings = MLPersistentStore.AllBindings;
  *  foreach (MLContentBinding binding in allBindings)
  *  {
  *      if (binding.GameObject.transform.name.Contains("Rack1") || binding.GameObject.transform.name.Contains("Rack2"))
  *      {
  *          GameObject.Find("DebugText").GetComponent<Text>().text += binding.GameObject.transform.name + ": ";
  *          GameObject.Find("DebugText").GetComponent<Text>().text += binding.GameObject.transform.position;
  *          GameObject.Find(binding.GameObject.transform.name).transform.position = binding.GameObject.transform.position;
  *          GameObject.Find(binding.GameObject.transform.name).transform.rotation = binding.GameObject.transform.rotation;
  *      }
  *  }
  * }
  */
 /// <summary>
 /// Handles the event for button down.
 /// </summary>
 /// <param name="controllerId">The id of the controller.</param>
 /// <param name="button">The button that is being released.</param>
 private void HandleOnButtonDown(byte controllerId, MLInputControllerButton button)
 {
     if (_controllerConnectionHandler.IsControllerValid(controllerId) && button == MLInputControllerButton.Bumper)
     {
         _viewMode = (ViewMode)((int)(_viewMode + 1) % Enum.GetNames(typeof(ViewMode)).Length);
     }
     UpdateVisualizers();
 }
 /// <summary>
 /// Handles the event for button down.
 /// </summary>
 /// <param name="controller_id">The id of the controller.</param>
 /// <param name="button">The button that is being pressed.</param>
 private void HandleOnButtonDown(byte controllerId, MLInputControllerButton button)
 {
     if (_controllerConnectionHandler.IsControllerValid() && _controllerConnectionHandler.ConnectedController.Id == controllerId &&
         button == MLInputControllerButton.Bumper)
     {
         NextPlacementObject();
     }
 }
Esempio n. 29
0
        /// <summary>
        /// Listens for Bumper and Home Tap.
        /// </summary>
        /// <param name="controllerId">Controller ID</param>
        /// <param name="button">Controller Button</param>
        void HandleControllerButtonDown(byte controllerId, MLInputControllerButton button)
        {
            if (!_controller.IsControllerValid(controllerId))
            {
                return;
            }

            if (button == MLInputControllerButton.Bumper)
            {
                Vector3 position = _controller.transform.position + _controller.transform.forward * _distance;
                CreateContent(position, _controller.transform.rotation);
            }
            else if (button == MLInputControllerButton.HomeTap)
            {
                _pcfVisualizer.ToggleDebug();
            }
        }
 /// <summary>
 /// Handles the event for button down. Changes from bounded to boundless and viceversa
 /// when pressing home button
 /// </summary>
 /// <param name="controllerId">The id of the controller.</param>
 /// <param name="button">The button that is being released.</param>
 private void OnButtonDown(byte controllerId, MLInputControllerButton button)
 {
     if (_controllerConnectionHandler.IsControllerValid(controllerId) && button == MLInputControllerButton.HomeTap)
     {
         _bounded = !_bounded;
         UpdateBounds();
     }
 }