Exemplo n.º 1
0
 /// <summary> Refresh information texts. </summary>
 private void RefreshInfoTexts()
 {
     mainInfoText.text =
         "controller count: " + NRInput.GetAvailableControllersCount().ToString() + "\n"
         + "type: " + NRInput.GetControllerType().ToString() + "\n"
         + "current debug hand: " + m_CurrentDebugHand.ToString() + "\n"
         + "position available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_POSITION).ToString() + "\n"
         + "rotation available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_ROTATION).ToString() + "\n"
         + "gyro available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_GYRO).ToString() + "\n"
         + "accel available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_ACCEL).ToString() + "\n"
         + "mag available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_MAG).ToString() + "\n"
         + "battery available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_BATTERY).ToString() + "\n"
         + "vibration available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_HAPTIC_VIBRATE).ToString() + "\n"
         + "rotation: " + NRInput.GetRotation(m_CurrentDebugHand).ToString("F3") + "\n"
         + "position: " + NRInput.GetPosition(m_CurrentDebugHand).ToString("F3") + "\n"
         + "touch: " + NRInput.GetTouch(m_CurrentDebugHand).ToString("F3") + "\n"
         + "trigger button: " + NRInput.GetButton(m_CurrentDebugHand, ControllerButton.TRIGGER).ToString() + "\n"
         + "home button: " + NRInput.GetButton(m_CurrentDebugHand, ControllerButton.HOME).ToString() + "\n"
         + "app button: " + NRInput.GetButton(m_CurrentDebugHand, ControllerButton.APP).ToString() + "\n"
         + "grip button: " + NRInput.GetButton(m_CurrentDebugHand, ControllerButton.GRIP).ToString() + "\n"
         + "touchpad button: " + NRInput.GetButton(m_CurrentDebugHand, ControllerButton.TOUCHPAD_BUTTON).ToString() + "\n"
         + "gyro: " + NRInput.GetGyro(m_CurrentDebugHand).ToString("F3") + "\n"
         + "accel: " + NRInput.GetAccel(m_CurrentDebugHand).ToString("F3") + "\n"
         + "mag: " + NRInput.GetMag(m_CurrentDebugHand).ToString("F3") + "\n"
         + "battery: " + NRInput.GetControllerBattery(m_CurrentDebugHand);
     extraInfoText.text = m_ExtraInfoStr;
     //Debug.Log("istouching:" + NRInput.IsTouching() + " value:" + NRInput.GetTouch(m_CurrentDebugHand).ToString("F3"));
     PrintInputState();
 }
    //使用Joystick输入
    private void UpdateJoystickAxis()
    {
        var   touchpos = NRInput.GetTouch();
        float xAxis    = touchpos.x;
        float yAxis    = touchpos.y;

        if (Mathf.Abs(yAxis) > 0.1f)
        {
            targetControlZDistance += yAxis * distanceIncrementOnSwipe * Time.deltaTime;
            targetControlZDistance  = Mathf.Clamp(targetControlZDistance,
                                                  distanceFromControllerMin,
                                                  distanceFromControllerMax);
            controlZDistance = targetControlZDistance;
        }
        if (Mathf.Abs(xAxis) > 0.8f)
        {
            if (enableScale)
            {
                if (xAxis < 0)
                {
                    transform.localScale = Vector3.Lerp(transform.localScale, minScale, 1f * Time.deltaTime);
                }
                else
                {
                    transform.localScale = Vector3.Lerp(transform.localScale, maxScale, 0.1f * Time.deltaTime);
                }
            }
            else if (enableRotate)
            {
                touchPosXRemap = -Mathf.Sign(xAxis) * 0.01f * (objectInverted ? -1f : 1f);
                verifyRotation = verifyRotation * Quaternion.AngleAxis(touchPosXRemap * Mathf.Rad2Deg, Vector3.up);
            }
        }
    }
Exemplo n.º 3
0
        private void UpdateScroll()
        {
            if (controlZoom == false)
            {
                if (m_PreviousPos == Vector2.zero)
                {
                    return;
                }
                Vector2 deltaMove = NRInput.GetTouch() - m_PreviousPos;
                m_PreviousPos = NRInput.GetTouch();

                modelTarget.Rotate(m_AroundLocalAxis, deltaMove.x * m_TouchScrollSpeed * Time.deltaTime, Space.Self);
            }
            else
            {
                if (m_PreviousPos == Vector2.zero)
                {
                    return;
                }
                Vector2 deltaMove = NRInput.GetTouch() - m_PreviousPos;
                m_PreviousPos = NRInput.GetTouch();

                modelTarget.position = new Vector3(0f, 0f, modelTarget.position.z + deltaMove.y * m_TouchZoomScrollSpeed * Time.deltaTime);
                //  modelTarget.position = new Vector3(modelTarget.position.z + deltaMove.x * m_TouchZoomScrollSpeed * Time.deltaTime, 0f,0f);
            }
        }
Exemplo n.º 4
0
 private void PrintInputState()
 {
     Debug.LogFormat("istouching:{0} getbutton app:{1} trigger:{2} home:{3} \n" +
                     "getbuttondown app:{4} trigger:{5} home:{6} \n" +
                     "getbuttonup app:{7} trigger:{8} home:{9} \n" +
                     "origin touch:[{10}] gettouch:{11}", NRInput.IsTouching(), NRInput.GetButton(ControllerButton.APP), NRInput.GetButton(ControllerButton.TRIGGER), NRInput.GetButton(ControllerButton.HOME)
                     , NRInput.GetButtonDown(ControllerButton.APP), NRInput.GetButtonDown(ControllerButton.TRIGGER), NRInput.GetButtonDown(ControllerButton.HOME)
                     , NRInput.GetButtonUp(ControllerButton.APP), NRInput.GetButtonUp(ControllerButton.TRIGGER), NRInput.GetButtonUp(ControllerButton.HOME)
                     , NRVirtualDisplayer.SystemButtonState.ToString(), NRInput.GetTouch(m_CurrentDebugHand).ToString("F3"));
 }
Exemplo n.º 5
0
        /// <summary> Updates the scroll. </summary>
        private void UpdateScroll()
        {
            if (m_PreviousPos == Vector2.zero)
            {
                return;
            }
            Vector2 deltaMove = NRInput.GetTouch() - m_PreviousPos;

            m_PreviousPos = NRInput.GetTouch();
            modelTarget.Rotate(m_AroundLocalAxis, deltaMove.x * m_TouchScrollSpeed * Time.deltaTime, Space.Self);
        }
Exemplo n.º 6
0
 /// <summary> Updates this object. </summary>
 private void Update()
 {
     if (NRInput.GetButtonDown(ControllerButton.TRIGGER))
     {
         m_PreviousPos = NRInput.GetTouch();
     }
     else if (NRInput.GetButton(ControllerButton.TRIGGER))
     {
         UpdateScroll();
     }
     else if (NRInput.GetButtonUp(ControllerButton.TRIGGER))
     {
         m_PreviousPos = Vector2.zero;
     }
 }
Exemplo n.º 7
0
    //使用touchpad输入
    private void UpdateTouchPad()
    {
        var touchpos = NRInput.GetTouch(ControllerHandEnum.Right);

        xAxis = touchpos.x;
        yAxis = touchpos.y;
        if (xAxis != 0f || yAxis != 0f)
        {
            if (lastTouchPos == Vector2.zero)
            {
                OnTouchDown(xAxis, yAxis);
            }
            deltaTouch     = (lastTouchPos == Vector2.zero) ? Vector2.zero : new Vector2(xAxis - lastTouchPos.x, yAxis - lastTouchPos.y);
            lastTouchPos.x = xAxis;
            lastTouchPos.y = yAxis;
            if (IsRotating)
            {
                transform.Rotate(-arCam.up, deltaTouch.x * rotateSensitivity, Space.World);
                transform.Rotate(arCam.right, deltaTouch.y * rotateSensitivity, Space.World);
            }
        }
        else
        {
            if (lastTouchPos != Vector2.zero)
            {
                OnTouchUp();
            }
            velocity_x += acceler_x * Time.deltaTime;
            velocity_y += acceler_y * Time.deltaTime;
            if (Mathf.Sign(velocity_x) == Mathf.Sign(acceler_x))
            {
                velocity_x = 0f;
            }
            if (Mathf.Sign(velocity_y) == Mathf.Sign(acceler_y))
            {
                velocity_y = 0f;
            }
            IsRotating = (velocity_x != 0f || velocity_y != 0f);
            if (IsRotating)
            {
                transform.Rotate(-arCam.up, velocity_x * rotateSensitivity * Time.deltaTime, Space.World);
                transform.Rotate(arCam.right, velocity_y * rotateSensitivity * Time.deltaTime, Space.World);
            }
        }
    }
    //使用touchpad输入
    private void UpdateTouchPad()
    {
        var   touchpos = NRInput.GetTouch();
        float xAxis    = touchpos.x;
        float yAxis    = touchpos.y;

        if (xAxis != 0f || yAxis != 0f)
        {
            deltaTouch     = (lastTouchPos == Vector2.zero) ? Vector2.zero : new Vector2(xAxis - lastTouchPos.x, yAxis - lastTouchPos.y);
            lastTouchPos.x = xAxis;
            lastTouchPos.y = yAxis;

            //缩放和移动同时只执行一个
            touchDownPositionY      = Mathf.Abs(deltaTouch.x) < 2f * Mathf.Abs(deltaTouch.y) ? deltaTouch.y : 0f;
            targetControlZDistance += touchDownPositionY * distanceIncrementOnSwipe * Time.deltaTime * 50f;
            targetControlZDistance  = Mathf.Clamp(targetControlZDistance,
                                                  distanceFromControllerMin,
                                                  distanceFromControllerMax);
            controlZDistance = targetControlZDistance;

            if (touchDownPositionY == 0f)
            {
                if (enableScale)
                {
                    if (deltaTouch.x < 0)
                    {
                        transform.localScale = Vector3.Lerp(transform.localScale, minScale, scaleSensitivity * SCALE_MINUS_SPEED * Time.deltaTime * (-deltaTouch.x));
                    }
                    else
                    {
                        transform.localScale = Vector3.Lerp(transform.localScale, maxScale, scaleSensitivity * SCALE_ADD_SPEED * Time.deltaTime * deltaTouch.x);
                    }
                }
                else if (enableRotate)
                {
                    touchPosXRemap = -deltaTouch.x * (objectInverted ? -1f : 1f);
                    verifyRotation = verifyRotation * Quaternion.AngleAxis(touchPosXRemap * Mathf.Rad2Deg, Vector3.up);
                }
            }
        }
        else
        {
            lastTouchPos = Vector2.zero;
        }
    }
Exemplo n.º 9
0
 private void JudgeDrop()
 {
     if (!IsMoveable)
     {
         return;
     }
     if (!IsBeingSelected)
     {
         return;
     }
     if (NRInput.GetButtonDown(ControllerButton.TRIGGER))
     {
         m_TriggerDownTime = Time.time;
         m_TouchDownPos    = NRInput.GetTouch();
     }
     if (NRInput.GetButton(ControllerButton.TRIGGER) && !m_TouchMoved)
     {
         m_TouchMoved = Vector2.Distance(NRInput.GetTouch(), m_TouchDownPos) > JUDGE_TOUCH_MOVED_DISTANCE;
     }
     if (NRInput.GetButtonUp(ControllerButton.TRIGGER))
     {
         if ((Time.time - m_TriggerDownTime) < SelectingRaycaster.clickInterval)
         {
             forceDeselectOnce = true;
         }
         if (NRInput.GetControllerType() == ControllerType.CONTROLLER_TYPE_PHONE && m_TouchMoved)
         {
             forceDeselectOnce = false;
         }
         m_TouchMoved = false;
     }
     else if (NRInput.GetButtonUp(ControllerButton.HOME))
     {
         forceDeselectOnce = true;
     }
     if (forceDeselectOnce)
     {
         forceDeselectOnce = false;
         Deselected();
     }
 }
Exemplo n.º 10
0
        private void Update()
        {
#if UNITY_EDITOR
            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                LoadNextScene();
            }

            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                LoadLastScene();
            }
#endif
            if (NRInput.GetTouch().x > 0.8f)
            {
                LoadNextScene();
            }
            if (NRInput.GetTouch().x < -0.8f)
            {
                LoadLastScene();
            }
        }
Exemplo n.º 11
0
    private void UpdateJoystick()
    {
        var touch = NRInput.GetTouch(ControllerHandEnum.Right);

        xAxis          = touch.x;
        yAxis          = touch.y;
        currentSpeed.x = Mathf.SmoothDamp(currentSpeed.x, xAxis, ref velocity.x, smoothingTime);
        currentSpeed.y = Mathf.SmoothDamp(currentSpeed.y, yAxis, ref velocity.y, smoothingTime);

        //currentSpeed.x = Mathf.Lerp(currentSpeed.x, mXAxis, Time.deltaTime * 4f);
        //currentSpeed.y = Mathf.Lerp(currentSpeed.y, mYAxis, Time.deltaTime * 4f);
        IsRotating = false;
        if (Mathf.Abs(currentSpeed.x) > 0.4f)
        {
            IsRotating = true;
            transform.Rotate(arCam.up, currentSpeed.x * rotateSpeed * Time.deltaTime, Space.World);
        }
        else if (Mathf.Abs(currentSpeed.y) > 0.4f)
        {
            IsRotating = true;
            transform.Rotate(arCam.right, currentSpeed.y * rotateSpeed * Time.deltaTime, Space.World);
        }
    }
Exemplo n.º 12
0
 private void RefreshInfoTexts()
 {
     mainInfoText.text =
         "controller count: " + NRInput.GetAvailableControllersCount().ToString() + "\n"
         + "type: " + NRInput.GetControllerType().ToString() + "\n"
         + "domain hand: " + NRInput.DomainHand.ToString() + "\n"
         + "position available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_POSITION).ToString() + "\n"
         + "rotation available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_ROTATION).ToString() + "\n"
         + "gyro available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_GYRO).ToString() + "\n"
         + "accel available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_ACCEL).ToString() + "\n"
         + "mag available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_MAG).ToString() + "\n"
         + "battery available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_BATTERY).ToString() + "\n"
         + "vibration available: " + NRInput.GetControllerAvailableFeature(ControllerAvailableFeature.CONTROLLER_AVAILABLE_FEATURE_HAPTIC_VIBRATE).ToString() + "\n"
         + "rotation: " + NRInput.GetRotation().ToString("F3") + "\n"
         + "position: " + NRInput.GetPosition().ToString("F3") + "\n"
         + "touch: " + NRInput.GetTouch().ToString("F3") + "\n"
         + "trigger, home, app: " + NRInput.GetButton(ControllerButton.TRIGGER).ToString() + NRInput.GetButton(ControllerButton.HOME).ToString() + NRInput.GetButton(ControllerButton.APP).ToString() + "\n"
         + "gyro: " + NRInput.GetGyro().ToString("F3") + "\n"
         + "accel: " + NRInput.GetAccel().ToString("F3") + "\n"
         + "mag: " + NRInput.GetMag().ToString("F3") + "\n"
         + "battery: " + NRInput.GetControllerBattery();
     extraInfoText.text = m_ExtraInfoStr;
 }
Exemplo n.º 13
0
        public void Update()
        {
            Swipe = SwipeDirection.None;

            if (NRInput.IsTouching())
            {
                if (Mathf.Abs(_startTime) < float.Epsilon)
                {
                    _startTime     = Time.time;
                    _startPosition = NRInput.GetTouch();
                }

                _endPosition = NRInput.GetTouch();
                return;
            }

            if (Mathf.Abs(_startTime) < float.Epsilon)
            {
                return;
            }

            var direction = _endPosition - _startPosition;

            if (direction.magnitude >= _swipeDistanceThreshold)
            {
                if (Mathf.Abs(direction.x) > Mathf.Abs(direction.y))
                {
                    Swipe = direction.x < 0 ? SwipeDirection.Left : SwipeDirection.Right;
                }
                else
                {
                    Swipe = direction.y < 0 ? SwipeDirection.Down : SwipeDirection.Up;
                }
            }

            _startTime = 0f;
        }
Exemplo n.º 14
0
 Vector2 IInputController.GetTouch(ControllerType type) => NRInput.GetTouch();
Exemplo n.º 15
0
        private void Update()
        {
            brain1 = GameObject.Find("Brain");
            solar  = GameObject.Find("Rotate");
            var rotate = solar.GetComponent <Button>();
            var button = brain1.GetComponent <Button>();

            //  var button2 =
            button.onClick.AddListener(() => {
                if (brn == false)
                {
                    brn            = true;
                    brnenum        = brnlist.Brain2;
                    brainText.text = "Brain 2";
                }
                else
                {
                    brn            = false;
                    brnenum        = brnlist.Brain1;
                    brainText.text = "Brain 1";
                }
            });

            rotate.onClick.AddListener(() => {
                if (controlZoom == false)
                {
                    controlZoom     = true;
                    buttonText.text = "Zoom";
                }
                else
                {
                    controlZoom     = false;
                    buttonText.text = "Rotate";
                }
            });

            switch (brnenum)
            {
            case brnlist.Brain1:
                brain1.SetActive(true);
                brain2.SetActive(false);
                break;

            case brnlist.Brain2:
                brain1.SetActive(false);
                brain2.SetActive(true);
                break;
            }
            if (NRInput.GetButtonDown(ControllerButton.TRIGGER))
            {
                m_PreviousPos = NRInput.GetTouch();
            }
            else if (NRInput.GetButton(ControllerButton.TRIGGER))
            {
                UpdateScroll();
            }
            else if (NRInput.GetButtonUp(ControllerButton.TRIGGER))
            {
                m_PreviousPos = Vector2.zero;
            }
        }