Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        IsDown = false;
        if (Input.touches.Length > 0)
        {
            foreach (Touch touch in Input.touches)
            {
                if (Vector2.Distance(touch.position, transform.position) < radius)
                {
                    IsDown = true;
                    break;
                }
            }
        }

        if (HybridInput.IsDebugMode())
        {
            if (Input.GetKey(KeyCode.Mouse0) && Vector2.Distance(Input.mousePosition, transform.position) < radius)
            {
                IsDown = true;
            }
        }

        if (IsDown)
        {
            Image.color = new Color(Image.color.r, Image.color.g, Image.color.b, 0.6f);
        }
        else
        {
            Image.color = new Color(Image.color.r, Image.color.g, Image.color.b, 0.5f);
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (FingerId == ID_NONE)
        {
            if (HybridInput.IsDebugMode() &&
                (Input.GetKeyDown(KeyCode.Mouse0) &&
                 Vector2.Distance(Input.mousePosition, transform.position) < Radius))
            {
                FingerId = ID_MOUSE;
            }
            foreach (Touch touch in Input.touches)
            {
                if (Vector2.Distance(touch.position, transform.position) < Radius)
                {
                    FingerId = touch.fingerId;
                }
            }
        }

        Vector3 touchPosition    = Vector3.zero;
        bool    foundActiveTouch = false;

        if (FingerId == ID_MOUSE)
        {
            if (Input.GetKey(KeyCode.Mouse0))
            {
                touchPosition = Input.mousePosition;
            }
            else
            {
                FingerId = ID_NONE;
            }
        }
        else if (FingerId != ID_NONE)
        {
            foreach (Touch touch in Input.touches)
            {
                if (touch.fingerId == FingerId)
                {
                    touchPosition    = touch.position;
                    foundActiveTouch = true;
                    break;
                }
            }
            if (!foundActiveTouch)
            {
                FingerId = ID_NONE;
            }
        }

        Vector3 diff;

        if (FingerId != ID_NONE)
        {
            diff   = (touchPosition - transform.position) / Radius;
            diff.z = 0;
            if (diff.magnitude > 1.0f)
            {
                diff = diff.normalized;
            }
        }
        else
        {
            diff = Vector3.zero;
        }
        HorizontalAxis.Axis = diff.x;
        VerticalAxis.Axis   = diff.y;

        Vector2 knobPos = transform.position + diff * Radius;

        Knob.transform.position = new Vector3(knobPos.x, knobPos.y, Knob.transform.position.z);
    }