Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        Quaternion movePlane = Quaternion.LookRotation(Vector3.Cross(Camera.main.transform.right, Vector3.up), Vector3.up);

        if (HololensInput.ButtonDown(ButtonType.BButton) || Input.GetKeyDown(KeyCode.R))
        {
            Completed();
        }
        else if (HololensInput.ButtonDown(ButtonType.AButton))
        {
            direction++;
            transform.Find("PlaneDirection").gameObject.SetActive(false);
            transform.Find("RotDirection").gameObject.SetActive(false);
            transform.Find("UpDownDirection").gameObject.SetActive(false);


            if (direction == 1)
            {
                transform.Find("PlaneDirection").gameObject.SetActive(true);;
            }
            else if (direction == 2)
            {
                transform.Find("RotDirection").gameObject.SetActive(true);
            }
            else if (direction > 2)
            {
                transform.Find("UpDownDirection").gameObject.SetActive(true);
                direction = 0;
            }
        }
        else
        {
            Vector2 an = HololensInput.GetJoystick();
            Vector3 move;
            if (direction == 0)
            {
                // Vertical movement
                move = new Vector3(0.0f, an.y, 0.0f);
            }
            else if (direction == 1)
            {
                // Horizontal plane
                move = movePlane * new Vector3(an.x, 0.0f, an.y);
            }
            else
            {
                // Rotation
                move = Vector3.zero;
                obj.transform.rotation = obj.transform.rotation * Quaternion.Euler(0.0f, an.x * 45.0f * Time.deltaTime, 0.0f);
            }

            transform.position += move * anSensitivity * Time.deltaTime;
        }

        obj.transform.position = transform.position;
        transform.Find("PlaneDirection").rotation = movePlane;
    }
Esempio n. 2
0
    private bool AllowMoveEventProcessing(float time)
    {
        Vector2 joystick = HololensInput.GetJoystick();

        bool allow = !Mathf.Approximately(joystick.x, 0.0f);

        allow |= !Mathf.Approximately(joystick.y, 0.0f);
        allow |= (time > m_NextAction);
        return(allow);
    }
Esempio n. 3
0
    public override bool ShouldActivateModule()
    {
        if (!base.ShouldActivateModule())
        {
            return(false);
        }

        Vector2 joystick = HololensInput.GetJoystick();

        var shouldActivate = HololensInput.GetPressed(ButtonType.AButton);

        shouldActivate |= HololensInput.GetPressed(ButtonType.BButton);
        shouldActivate |= !Mathf.Approximately(joystick.x, 0.0f);
        shouldActivate |= !Mathf.Approximately(joystick.y, 0.0f);
        return(shouldActivate);
    }
Esempio n. 4
0
    private bool SendSubmitEventToSelectedObject()
    {
        if (eventSystem.currentSelectedGameObject == null)
        {
            return(false);
        }

        var data = GetBaseEventData();

        if (HololensInput.GetPressed(ButtonType.AButton))
        {
            ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.submitHandler);
        }

        if (HololensInput.GetPressed(ButtonType.BButton))
        {
            ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.cancelHandler);
        }
        return(data.used);
    }
Esempio n. 5
0
    private bool SendMoveEventToSelectedObject()
    {
        float time = Time.unscaledTime;

        if (!AllowMoveEventProcessing(time))
        {
            return(false);
        }

        Vector2 movement = HololensInput.GetJoystick();
        // Debug.Log(m_ProcessingEvent.rawType + " axis:" + m_AllowAxisEvents + " value:" + "(" + x + "," + y + ")");
        var axisEventData = GetAxisEventData(movement.x, movement.y, 0.6f);

        if (!Mathf.Approximately(axisEventData.moveVector.x, 0f) ||
            !Mathf.Approximately(axisEventData.moveVector.y, 0f))
        {
            ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisEventData, ExecuteEvents.moveHandler);
        }
        m_NextAction = time + 1f / m_InputActionsPerSecond;
        return(axisEventData.used);
    }
Esempio n. 6
0
        private void ProcessGestureClickPress()
        {
            PointerEventData pointerEvent  = m_GazeEventData.pointerEventData;
            GameObject       currentOverGo = pointerEvent.pointerCurrentRaycast.gameObject;

            // PointerDown notification
            if (m_GazeEventData.PressedThisFrame() || Input.GetMouseButtonDown(0) || HololensInput.GetPressed(ButtonType.AButton))
            {
                pointerEvent.eligibleForClick    = true;
                pointerEvent.delta               = Vector2.zero;
                pointerEvent.dragging            = false;
                pointerEvent.useDragThreshold    = true;
                pointerEvent.pressPosition       = pointerEvent.position;
                pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast;

                DeselectIfSelectionChanged(currentOverGo, pointerEvent);

                // search for the control that will receive the press
                // if we can't find a press handler set the press
                // handler to be what would receive a click.
                var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler);

                // didn't find a press handler... search for a click handler
                if (null == newPressed)
                {
                    newPressed = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);
                }

                // Debug.Log("Pressed: " + newPressed);

                float time = Time.unscaledTime;

                if (newPressed == pointerEvent.lastPress)
                {
                    var diffTime = time - pointerEvent.clickTime;
                    if (diffTime < 0.3f)
                    {
                        ++pointerEvent.clickCount;
                    }
                    else
                    {
                        pointerEvent.clickCount = 1;
                    }

                    pointerEvent.clickTime = time;
                }
                else
                {
                    pointerEvent.clickCount = 1;
                }

                pointerEvent.pointerPress    = newPressed;
                pointerEvent.rawPointerPress = currentOverGo;

                pointerEvent.clickTime = time;

                // Save the drag handler as well
                pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler <IDragHandler>(currentOverGo);

                if (pointerEvent.pointerDrag != null)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);
                }
            }

            // PointerUp notification
            if (m_GazeEventData.ReleasedThisFrame() || Input.GetMouseButtonUp(0) || HololensInput.ButtonUp(ButtonType.AButton))
            {
                // Debug.Log("Executing press-up on: " + pointer.pointerPress);
                ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);

                // Debug.Log("KeyCode: " + pointer.eventData.keyCode);

                // see if we mouse up on the same element that we clicked on...
                var pointerUpHandler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(currentOverGo);

                // PointerClick and Drop events
                if (pointerEvent.pointerPress == pointerUpHandler && pointerEvent.eligibleForClick)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler);
                }
                else if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
                {
                    ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler);
                }

                pointerEvent.eligibleForClick = false;
                pointerEvent.pointerPress     = null;
                pointerEvent.rawPointerPress  = null;

                if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler);
                }

                pointerEvent.dragging    = false;
                pointerEvent.pointerDrag = null;

                // redo pointer enter / exit to refresh state
                // so that if we moused over something that ignored it before
                // due to having pressed on something else
                // it now gets it.
                if (currentOverGo != pointerEvent.pointerEnter)
                {
                    HandlePointerExitAndEnter(pointerEvent, null);
                    HandlePointerExitAndEnter(pointerEvent, currentOverGo);
                }
            }
        }
    // Update is called once per frame
    void Update()
    {
        if (isResize)
        {
            Vector2 an = HololensInput.GetJoystick();

            if (HololensInput.GetPressed(ButtonType.BButton))
            {
                Debug.Log("Test");
                resizeUI();
            }
            else if (an.y > 0.1 || an.y < -0.1)
            {
                float width = menu.transform.localScale.x + an.y * Time.deltaTime;

                // Clamp to min/max size
                if (width < 0.2F)
                {
                    width = 0.2F;
                }
                else if (width > 1.0f)
                {
                    width = 1.0f;
                }

                menu.transform.localScale = new Vector3(width, width, 1.0f); // New scale of the menu
                moveCorners();
            }
        }

        //Debug.Log(HololensInput.Instance.current.pressed + " " + HololensInput.Instance.previous.pressed);
        if (HololensInput.Instance.current.pressed && !HololensInput.Instance.previous.pressed)
        {
            // Check if the user has selected a corner box
            //Debug.Log("click");
            for (int i = 0; i < corners.Length; i++)
            {
                if (HololensInput.Instance.current.hitInfo.gameObject == corners[i])
                {
                    //Debug.Log("selected cube " + i);
                    isDragging = i;
                    break;
                }
            }
        }
        else if (isDragging >= 0 && HololensInput.Instance.current.pressed)
        {
            // Cast the users selection to the plane
            Ray   ray  = HololensInput.GazeRay();
            float dist = GetRayDistance(ray);
            if (dist > 0)
            {
                //Debug.Log("Distance > 0");
                Vector3 hit = ray.origin + dist * ray.direction; // Position the ray hit

                Vector3 lnDir = new Vector3(0, 0, 0);            // Direction of the cross line
                if (isDragging == 0 || isDragging == 1)
                {
                    lnDir = Vector3.Normalize(menu.transform.rotation * new Vector3(1, 9 / 16.0f, 0));
                }
                else
                {
                    lnDir = Vector3.Normalize(menu.transform.rotation * new Vector3(1, -9 / 16.0f, 0));
                }
                //Debug.Log(lnDir);

                // Find the point on the cross line closest to hit
                Vector3 corner  = corners[isDragging].transform.position;
                Vector3 closest = lnDir * Vector3.Dot(hit - corner, lnDir) + corner;
                corners[isDragging].transform.position = closest;
                // Find the new width

                closest = Quaternion.Inverse(menu.transform.rotation) * (closest - menu.transform.position);
                //Debug.Log("Dist = " + closest);
                float width;
                if (isDragging == 0 || isDragging == 3)
                {
                    Vector3 cornerP = Quaternion.Inverse(menu.transform.rotation) * (corners[1].transform.position - menu.transform.position);

                    width = Mathf.Abs(closest.x - cornerP.x);
                }
                else
                {
                    Vector3 cornerP = Quaternion.Inverse(menu.transform.rotation) * (corners[0].transform.position - menu.transform.position);

                    width = Mathf.Abs(closest.x - cornerP.x);
                }

                // Clamp to min/max size
                if (width < 0.2F)
                {
                    width = 0.2F;
                }
                else if (width > 1.0f)
                {
                    width = 1.0f;
                }

                Vector3 scale      = new Vector3(width, width, 1.0f); // New scale of the menu
                Vector3 scaleDelta = scale - menu.transform.localScale;
                scaleDelta.y *= 9.0f / 16.0f;

                // Set the scale
                menu.transform.localScale = scale;

                // Move the menu to compensate for the change in scale
                if (isDragging == 1 || isDragging == 3)
                {
                    scaleDelta.y = -scaleDelta.y;
                }
                if (isDragging == 1 || isDragging == 2)
                {
                    scaleDelta.x = -scaleDelta.x;
                }
                Vector3 p = menu.transform.position + menu.transform.rotation * (scaleDelta / 2.0f);
                menu.transform.position = p;

                // Finally set the corners in the right position
                moveCorners();
            }
            else
            {
                isDragging = -1;
            }
        }
        if (isDragging >= 0 && !HololensInput.Instance.current.pressed)
        {
            isDragging = -1;
        }
    }
Esempio n. 8
0
 public void OnSelect(BaseEventData eventData)
 {
     HololensInput.Pulse(1023, 200);
 }