Ejemplo n.º 1
0
    /// <summary>
    /// 平移裁剪框
    /// </summary>
    /// <param name="eventData"></param>
    private void Move(NavigationEventData eventData)
    {
        Vector3 moveVector = Vector3.one;
        float   deltaX     = 8 * eventData.CumulativeDelta.x;
        float   deltaY     = 8 * eventData.CumulativeDelta.y;

        if (Math.Abs(eventData.CumulativeDelta.x) >= Math.Abs(eventData.CumulativeDelta.y))
        {
            //当水平移动分量大于垂直分量时,水平平移
            moveVector = new Vector3(deltaX, 0, 0);
        }
        else
        {
            //当垂直移动分量大于水平分量时,垂直平移
            moveVector = new Vector3(0, deltaY, 0);
        }

        //计算边界,重新调整位移
        moveVector = RecalculateMoveVector(moveVector);

        RectTransform rectTransform = gameObject.GetComponent <RectTransform>();

        gameObject.GetComponent <RectTransform>().localPosition = new Vector3(
            rectTransform.localPosition.x + moveVector.x,
            rectTransform.localPosition.y + moveVector.y,
            rectTransform.localPosition.z + moveVector.z);
    }
Ejemplo n.º 2
0
 public void OnNavigationCanceled(NavigationEventData eventData)
 {
     if (Isinteractable(eventData.selectedObject))
     {
         NavigationCanceled(eventData.selectedObject, eventData);
     }
 }
Ejemplo n.º 3
0
    void INavigationHandler.OnNavigationUpdated(NavigationEventData eventData)
    {
        if (isMove)
        {
            /* TODO: DEVELOPER CODING EXERCISE 2.c */

            // 2.c: Calculate a float rotationFactor based on eventData's NormalizedOffset.x multiplied by RotationSensitivity.
            // This will help control the amount of rotation.
            float rotationFactor = eventData.NormalizedOffset.x * RotationSensitivity;

            transform.Rotate(new Vector3(0, -1 * rotationFactor, 0));
        }

        if (isZoom)
        {
            float sliderOffset = eventData.NormalizedOffset.x * sliderSensitivity;
            if (transform.localScale.x - maxSize >= eps)
            {
                transform.localScale = new Vector3(maxSize, maxSize, maxSize);
            }
            else if (minSize - transform.localScale.x >= eps)
            {
                transform.localScale = new Vector3(minSize, minSize, minSize);
            }
            else
            {
                float NewX = transform.localScale.x + sliderOffset;
                float NewY = transform.localScale.y + sliderOffset;
                float NewZ = transform.localScale.z + sliderOffset;
                transform.localScale = new Vector3(NewX, NewY, NewZ);
            }
        }
    }
Ejemplo n.º 4
0
 void INavigationHandler.OnNavigationStarted(NavigationEventData eventData)
 {
     if (MyUIManager.Instance.CurrentModelEditMode == MyUIManager.ModelEditType.Rotate)
     {
         InputManager.Instance.PushModalInputHandler(gameObject);
     }
 }
 public void OnNavigationStarted(NavigationEventData eventData)
 {
     if (IsEnabled && OnStart != null)
     {
         OnStart();
     }
 }
Ejemplo n.º 6
0
 // Use this event to check if the hand has left the tracking field.
 public void OnNavigationCanceled(NavigationEventData eventData)
 {
     if (NavigationCanceled != null)
     {
         NavigationCanceled();
     }
 }
Ejemplo n.º 7
0
    void INavigationHandler.OnNavigationUpdated(NavigationEventData eventData)
    {
        if (gestureType == GestureType.Zoom)
        {
            float sliderOffset = eventData.NormalizedOffset.x * RotationSensitivity;
            print(sliderOffset);
            GameObject model = GameObject.FindGameObjectWithTag("Model");

            if (model.transform.localScale.x - maxSize >= eps)
            {
                model.transform.localScale = new Vector3(maxSize, maxSize, maxSize);
            }
            else if (minSize - model.transform.localScale.x >= eps)
            {
                model.transform.localScale = new Vector3(minSize, minSize, minSize);
            }
            else
            {
                float NewX = model.transform.localScale.x + sliderOffset;
                float NewY = model.transform.localScale.y + sliderOffset;
                float NewZ = model.transform.localScale.z + sliderOffset;
                model.transform.localScale = new Vector3(NewX, NewY, NewZ);
            }
        }
        if (gestureType == GestureType.Rotate)
        {
            float rotationFactor = eventData.NormalizedOffset.x * RotationSensitivity;
            transform.Rotate(new Vector3(0, -1 * rotationFactor, 0));
        }
    }
Ejemplo n.º 8
0
 public void OnNavigationCanceled(NavigationEventData eventData)
 {
     if (!MenuManager.Instance.isPlacing && !MenuManager.Instance.isRotating && !MenuManager.Instance.isScaling && !MenuManager.Instance.isRemoving)
     {
         SendMessage("NavigationFinished");
     }
 }
Ejemplo n.º 9
0
        public void OnNavigationUpdated(NavigationEventData eventData)
        {
            //move up or down
            float movingFactor = eventData.NormalizedOffset.y * NavigationSensitivity;

            transform.position = new Vector3(transform.position.x, transform.position.y + (1 * movingFactor), transform.position.z);
        }
Ejemplo n.º 10
0
    void INavigationHandler.OnNavigationUpdated(NavigationEventData eventData)
    {
        if (isSelected)
        {
            // 左右移动为旋转,上下移动为缩放
            float dx = eventData.NormalizedOffset.x;
            float dy = eventData.NormalizedOffset.y;
            if (System.Math.Abs(dx) > System.Math.Abs(dy))
            {
                // 2.c: Calculate a float rotationFactor based on eventData's NormalizedOffset.x multiplied by RotationSensitivity.
                // This will help control the amount of rotation.
                float rotationFactor = dx * RotationSensitivity;

                // 2.c: transform.Rotate around the Y axis using rotationFactor.
                transform.Rotate(new Vector3(0, -1 * rotationFactor, 0));
            }
            else
            {
                Vector3 dScale = Vector3.zero;
                //设置每一帧缩放的大小
                float scaleValue = 0.0002f;
                if (dy > 0)
                {
                    scaleValue = -1 * scaleValue;
                }
                //当缩放超出设置的最大,最小范围时直接返回
                if (transform.localScale.x > maxScale && scaleValue > 0)
                {
                    return;
                }
                if (transform.localScale.x < minScale && scaleValue < 0)
                {
                    return;
                }
                //根据比例计算每个方向上的缩放大小
                dScale.x              = scaleValue;
                dScale.y              = scaleValue;
                dScale.z              = scaleValue;
                transform.localScale += dScale;
            }
        }
        else
        {
            Vector3 currentHandPosition = Vector3.zero;
            InteractionSourceInfo sourceKind;
            inputSource.TryGetSourceKind(inputSourceId, out sourceKind);
            switch (sourceKind)
            {
            case InteractionSourceInfo.Hand:
                inputSource.TryGetGripPosition(inputSourceId, out currentHandPosition);
                break;

            case InteractionSourceInfo.Controller:
                inputSource.TryGetPointerPosition(inputSourceId, out currentHandPosition);
                break;
            }
            transform.position += (currentHandPosition - prevHandPosition) * TranslationSensitivity;
            prevHandPosition    = currentHandPosition;
        }
    }
Ejemplo n.º 11
0
 public void OnNavigationUpdated(NavigationEventData eventData)
 {
     if (!MenuManager.Instance.isPlacing && !MenuManager.Instance.isRotating && !MenuManager.Instance.isScaling && !MenuManager.Instance.isRemoving)
     {
         SendMessage("NavigationUpdated", eventData.NormalizedOffset);
     }
 }
Ejemplo n.º 12
0
        public void OnNavigationUpdated(NavigationEventData eventData)
        {
            // Check rotation to see on what axis the gesture needs to be measured
            float Rotation = UIProperties.UiPositionHelper.transform.eulerAngles.y;


            float uncalculatedValue;

            if (Rotation > 45 && Rotation < 135)
            {
                uncalculatedValue = (eventData.NormalizedOffset.x * 1f);
                CurrentValue      = lastValue + ((uncalculatedValue * -1) / 0.008f);
            }
            else if (Rotation > 255 && Rotation < 315)
            {
                uncalculatedValue = (eventData.NormalizedOffset.x * 1f);
                CurrentValue      = lastValue + (uncalculatedValue / 0.008f);
            }
            else if (Rotation > 135 && Rotation < 225)
            {
                uncalculatedValue = (eventData.NormalizedOffset.x * 1f);
                CurrentValue      = lastValue + ((uncalculatedValue * -1) / 0.008f);
            }
            else
            {
                uncalculatedValue = (eventData.NormalizedOffset.x * 1f);
                CurrentValue      = lastValue + ((uncalculatedValue) / 0.008f);
            }


            SliderPointer.localPosition = new Vector3(percentageToPosition(), SliderPointer.localPosition.y, SliderPointer.localPosition.z);
            FunctionToDo.Invoke();
        }
Ejemplo n.º 13
0
    void INavigationHandler.OnNavigationStarted(NavigationEventData eventData)
    {
        InputManager.Instance.PushModalInputHandler(gameObject);
        eventData.Use(); // Mark the event as used, so it doesn't fall through to other handlers.

        if (!isSelected)
        {
            inputSource   = eventData.InputSource;
            inputSourceId = eventData.SourceId;

            Vector3 currentHandPosition = Vector3.zero;
            InteractionSourceInfo sourceKind;
            inputSource.TryGetSourceKind(inputSourceId, out sourceKind);
            switch (sourceKind)
            {
            case InteractionSourceInfo.Hand:
                inputSource.TryGetGripPosition(inputSourceId, out currentHandPosition);
                break;

            case InteractionSourceInfo.Controller:
                inputSource.TryGetPointerPosition(inputSourceId, out currentHandPosition);
                break;
            }
            prevHandPosition = currentHandPosition;
        }
        //gameObject.SendMessageUpwards("OnSelect", SendMessageOptions.DontRequireReceiver);
    }
Ejemplo n.º 14
0
    void INavigationHandler.OnNavigationUpdated(NavigationEventData eventData)
    {
        Vector3[] allPoints = new Vector3[line.positionCount + 1];
        line.GetPositions(allPoints);

        float x = gameObject.transform.localPosition.x + eventData.CumulativeDelta.x;
        float y = gameObject.transform.localPosition.y + eventData.CumulativeDelta.y;
        float z = gameObject.transform.localPosition.z - 10 + eventData.CumulativeDelta.z;


        Vector3 newPoint = new Vector3(x, y, z);

        allPoints[allPoints.Length - 1] = newPoint;


        line.positionCount = allPoints.Length;
        line.SetPositions(allPoints);

        Debug.LogFormat("OnNavigationUpdated\r\nSource: {0}  SourceId: {1}\r\nCumulativeDelta: {2} {3} {4}",
                        eventData.InputSource,
                        eventData.SourceId,
                        eventData.NormalizedOffset.x,
                        eventData.NormalizedOffset.y,
                        eventData.NormalizedOffset.z);
        eventData.Use(); // Mark the event as used, so it doesn't fall through to other handlers.
    }
 void INavigationHandler.OnNavigationStarted(NavigationEventData eventData)
 {
     InputManager.Instance.PushModalInputHandler(gameObject);
     //Vector3 curpos = InputManager.Instance.GetComponent<Camera>().transform.position;
     //gameObject.transform.parent = InputManager.Instance.GetComponent<Camera>().transform;
     gameObject.transform.SetParent(cursor.transform);
 }
Ejemplo n.º 16
0
 public void OnNavigationUpdated(NavigationEventData eventData)
 {
     x = eventData.CumulativeDelta.x * 90;
     y = eventData.CumulativeDelta.y * 90;
     z = eventData.CumulativeDelta.z * 90;
     Debug.Log("x:" + x + " y:" + y + " z:" + z);
 }
Ejemplo n.º 17
0
    public void OnNavigationUpdated(NavigationEventData eventData)
    {
        rotationFactor = eventData.CumulativeDelta.x * RotationSensitivity;

        //transform.Rotate along the Y axis using rotationFactor.
        transform.Rotate(new Vector3(0, -1 * rotationFactor, 0));
    }
Ejemplo n.º 18
0
        public void OnNavigationUpdated(NavigationEventData eventData)
        {
            if (isTapped)
            {
                var rotation = new Vector3();

                var cumulativeUpdate = eventData.NormalizedOffset.x;

                switch (rotationConstraint)
                {
                case AxisAndPlaneConstraint.X_AXIS_ONLY:
                    rotation.x = cumulativeUpdate * 180f - initialEulerAngles.x;
                    break;

                case AxisAndPlaneConstraint.Z_AXIS_ONLY:
                    rotation.z = cumulativeUpdate * 180f - initialEulerAngles.z;
                    break;

                default:     // case: Y_AXIS_ONLY:
                    rotation.y = cumulativeUpdate * 180f - initialEulerAngles.y;
                    break;
                }

                initialEulerAngles += rotation;
                hostTransform.Rotate(rotation, Space.Self);
            }
        }
Ejemplo n.º 19
0
    public void OnNavigationCanceled(NavigationEventData eventData)
    {
        Debug.Log("Navigagion is canceled.");
        eventData.Use();

        //rigidbody.useGravity = true;
    }
 /// <summary>
 /// this is called if a drag gesture is recognized
 /// it is used to make the menu item more sensitive to user input
 /// it handles the case where the user taps for too long on the menu item
 /// </summary>
 /// <param name="eventData">Data of the click event</param>
 public void OnNavigationCompleted(NavigationEventData eventData)
 {
     foreach (Action action in clickListeners)
     {
         action();
     }
 }
Ejemplo n.º 21
0
 public void OnNavigationUpdated(NavigationEventData eventData)
 {
     if (IsEnabled)
     {
         rotationFactor = eventData.CumulativeDelta.x * rotationSensitivity;
         transform.Rotate(new Vector3(0, -1 * rotationFactor, 0));
     }
 }
Ejemplo n.º 22
0
    // Endof InputClickerHandler Event Handler

    public void OnNavigationStarted(NavigationEventData eventData)
    {
        Debug.Log("Navigation is started.");

        InputManager.Instance.ClearModalInputStack();
        InputManager.Instance.PushModalInputHandler(this.gameObject);
        eventData.Use();
    }
Ejemplo n.º 23
0
    public void OnNavigationUpdated(NavigationEventData eventData)
    {
        InputManager.Instance.PushModalInputHandler(gameObject);

        GridParent.transform.Rotate(new Vector3(0, eventData.NormalizedOffset.x * -RotationSpeed, 0));

        eventData.Use();
    }
Ejemplo n.º 24
0
 public void OnNavigationCompleted(NavigationEventData eventData)
 {
     InputManager.Instance.PopModalInputHandler();
     if (!GridParent.transform.GetComponent <WorldAnchor>())
     {
         GridParent.transform.gameObject.AddComponent <WorldAnchor>();
     }
     eventData.Use();
 }
Ejemplo n.º 25
0
    public void OnNavigationCompleted(NavigationEventData eventData)
    {
        Debug.Log("Navigation is completed.");

        InputManager.Instance.PopModalInputHandler();
        eventData.Use();

        //rigidbody.useGravity = true;
    }
Ejemplo n.º 26
0
        protected override void NavigationUpdated(GameObject obj, NavigationEventData eventData)
        {
            FocusDetails eventFocus = (FocusDetails)FocusManager.Instance.TryGetFocusDetails(eventData);

            if (m_Focuser.Object == eventFocus.Object)
            {
                m_curHandPos = InputHelper.GetHandPos(handInputSource, handInputSourceId);
            }
        }
Ejemplo n.º 27
0
 public void OnNavigationCompleted(NavigationEventData eventData)
 {
     Debug.LogFormat("OnNavigationCompleted\r\nSource: {0}  SourceId: {1}\r\nCumulativeDelta: {2} {3} {4}",
                     eventData.InputSource,
                     eventData.SourceId,
                     eventData.NormalizedOffset.x,
                     eventData.NormalizedOffset.y,
                     eventData.NormalizedOffset.z);
 }
 public void OnNavigationCanceled(NavigationEventData eventData)
 {
     Debug.LogFormat("OnNavigationCanceled\r\nSource: {0}  SourceId: {1}\r\nCumulativeDelta: {2} {3} {4}",
                     eventData.InputSource,
                     eventData.SourceId,
                     eventData.CumulativeDelta.x,
                     eventData.CumulativeDelta.y,
                     eventData.CumulativeDelta.z);
 }
Ejemplo n.º 29
0
        // .................................................................... INTERFACE IManipulationHandler


        public void OnNavigationStarted(NavigationEventData eventData)
        {
            if (isTapped)
            {
                initialEulerAngles = new Vector3();
                InputManager.Instance.PushModalInputHandler(gameObject);
                eventData.Use();
            }
        }
Ejemplo n.º 30
0
 void INavigationHandler.OnNavigationStarted(NavigationEventData eventData)
 {
     Debug.LogFormat("OnNavigationStarted\r\nSource: {0}  SourceId: {1}\r\nCumulativeDelta: {2} {3} {4}",
                     eventData.InputSource,
                     eventData.SourceId,
                     eventData.NormalizedOffset.x,
                     eventData.NormalizedOffset.y,
                     eventData.NormalizedOffset.z);
     eventData.Use(); // Mark the event as used, so it doesn't fall through to other handlers.
 }
Ejemplo n.º 31
0
 public void OnNavigationCompleted(NavigationEventData eventData)
 {
     Debug.LogFormat("OnNavigationCompleted\r\nSource: {0}  SourceId: {1}\r\nCumulativeDelta: {2} {3} {4}",
         eventData.InputSource,
         eventData.SourceId,
         eventData.CumulativeDelta.x,
         eventData.CumulativeDelta.y,
         eventData.CumulativeDelta.z);
 }
Ejemplo n.º 32
0
 public void OnNavigationUpdated(NavigationEventData eventData)
 {
     if (LogGesturesUpdateEvents)
     {
         Debug.LogFormat("OnNavigationUpdated\r\nSource: {0}  SourceId: {1}\r\nCumulativeDelta: {2} {3} {4}",
             eventData.InputSource,
             eventData.SourceId,
             eventData.CumulativeDelta.x,
             eventData.CumulativeDelta.y,
             eventData.CumulativeDelta.z);
     }
 }