Exemple #1
0
    void Touchpad()
    {
        PS4Input.GetPadControllerInformation(playerId, out touchPixelDensity, out touchResolutionX, out touchResolutionY, out analogDeadZoneLeft, out analogDeadZoneRight, out connectionType);
        PS4Input.GetLastTouchData(playerId, out touchNum, out touch0x, out touch0y, out touch0id, out touch1x, out touch1y, out touch1id);

        // Show and move around up to 2 touch inputs
        if (touchNum > 0)
        {
            float xPos = 0;
            float yPos = 0;

            // Touch 1
            if (touch0x > 0 || touch0y > 0)
            {
                if (!touches[0].gameObject.activeSelf)
                {
                    touches[0].gameObject.SetActive(true);
                }

                xPos = (3.57f / touchResolutionX) * touch0x;
                yPos = (1.35f / touchResolutionY) * touch0y;

                touches[0].localPosition = new Vector3(xPos, -yPos, 1);
            }
            else if (touches[0].gameObject.activeSelf)
            {
                touches[0].gameObject.SetActive(false);
            }

            //Touch 2
            if (touchNum > 1 && (touch1x > 0 || touch1y > 0))
            {
                if (!touches[1].gameObject.activeSelf)
                {
                    touches[1].gameObject.SetActive(true);
                }

                xPos = (3.57f / touchResolutionX) * touch1x;
                yPos = (1.35f / touchResolutionY) * touch1y;

                touches[1].localPosition = new Vector3(xPos, -yPos, 1);
            }
            else if (touches[1].gameObject.activeSelf)
            {
                touches[1].gameObject.SetActive(false);
            }
        }
        else if (touches[0].gameObject.activeSelf || touches[1].gameObject.activeSelf)
        {
            touches[0].gameObject.SetActive(false);
            touches[1].gameObject.SetActive(false);
        }

        // Make the touchpad light up and play audio if it's pushed down
        if (Input.GetKey((KeyCode)Enum.Parse(typeof(KeyCode), "Joystick" + stickID + "Button6", true)))
        {
            gamePad.touchpad.color = inputOn;
            TouchpadAudio(touchResolutionX, touchResolutionY, touch0x, touch0y);
        }
        else
        {
            gamePad.touchpad.color = inputOff;
            GetComponent <AudioSource>().Stop();
        }
    }
Exemple #2
0
    void MouseInputSelection()
    {
#if UNITY_PS4 && !UNITY_EDITOR
        PS4Input.GetPadControllerInformation(playerId, out touchPixelDensity, out touchResolutionX, out touchResolutionY, out analogDeadZoneLeft, out analogDeadZoneRight, out connectionType);
        PS4Input.GetLastTouchData(playerId, out touchNum, out touch0x, out touch0y, out touch0id, out touch1x, out touch1y, out touch1id);
#endif


        if (
#if UNITY_PS4 && !UNITY_EDITOR
            touchNum > 0
#elif UNITY_PSP2 && !UNITY_EDITOR
            Input.touchCount == 1
#else
            Vector2.Distance(storeMouse, Input.mousePosition) > 0.5f
            //Input.GetMouseButton(0)
#endif
            )
        {
#if UNITY_PS4 && !UNITY_EDITOR
            if (touch0x > 0 || touch0y > 0)
            {
#endif
            if (!m_touchSpawned.gameObject.activeSelf)
            {
                m_touchSpawned.gameObject.SetActive(true);
            }

            float xDraw = 0;
            float yDraw = 0;
#if UNITY_PS4 && !UNITY_EDITOR
            // m_touchSpawned.position = Camera.main.ScreenToWorldPoint(new Vector3(touch0x, touchResolutionY - touch0y, 9));
            xDraw  = (1.0f / touchResolutionX) * touch0x;
            xDraw -= 0.5f;
            xDraw *= ScaleFactorX;
            xDraw += 0.5f;
            xDraw *= Screen.width;

            yDraw  = (1.0f / touchResolutionY) * touch0y;
            yDraw  = 1 - yDraw;
            yDraw -= 0.5f;
            yDraw *= ScaleFactorY;
            yDraw += 0.5f;
            yDraw *= Screen.height;

            // m_touchSpawned.position = (new Vector3(xDraw, -yDraw, 9));
#elif UNITY_PSP2 && !UNITY_EDITOR
            xDraw = Input.touches[0].position.x;
            yDraw = Input.touches[0].position.y;
#else
            xDraw = Input.mousePosition.x;
            yDraw = Input.mousePosition.y;
#endif
            Ray ray = Camera.main.ScreenPointToRay(new Vector3(xDraw, yDraw, 0));
            m_touchSpawned.position = ray.origin;
            if (Physics.Raycast(m_touchSpawned.position, Vector3.forward, out hit, 100, PlatformMask))
            {
                hit.collider.GetComponent <Input3DSelection>().SelectByInput();
            }
#if UNITY_PS4 && !UNITY_EDITOR
        }
        else if (m_touchSpawned.gameObject.activeSelf)
        {
            m_touchSpawned.gameObject.SetActive(false);
        }
#endif
        }