Ejemplo n.º 1
0
    //---------------------------------------------------------------------
    void UpdateKnib(Vector2 pos)
    {
        Vector2 localPos;

        if (!RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)transform, pos, Camera.main, out localPos))
        {
            return;
        }

        Vector2 offset = localPos - new Vector2(Origin.transform.localPosition.x, Origin.transform.localPosition.y);
        float   length = offset.magnitude;
        Vector2 dir    = Vector2.zero;

        if (length > .1f)
        {
            dir    = offset / length;
            length = Mathf.Clamp(length, 0.0f, MaxRadius);
            offset = dir * length;
        }

        Knib.transform.localPosition = Origin.localPosition + new Vector3(offset.x, offset.y, 0.0f);

        VirtualNetworkController controller = HopperNetwork.GetMyController();

        if (controller != null)
        {
            Vector2 movement = dir * (length / MaxRadius);
            UpdateMovementKnib(movement);
            controller.SetMovement(movement);
        }
    }
Ejemplo n.º 2
0
    //---------------------------------------------------------------------
    void ProcessTouch(Touch touch)
    {
        if (ActiveFingerID == touch.fingerId)
        {
            if ((touch.phase == TouchPhase.Ended) || (touch.phase == TouchPhase.Canceled))
            {
                ActiveFingerID = -1;
                VirtualNetworkController controller = HopperNetwork.GetMyController();
                if (controller != null)
                {
                    controller.SetMovement(Vector2.zero);
                }
                Knib.transform.localPosition = Origin.transform.localPosition;
            }
            else if (touch.phase == TouchPhase.Moved)
            {
                UpdateKnib(touch.position);
            }
            return;
        }

        if (touch.phase == TouchPhase.Began)
        {
            if ((ActiveFingerID == -1) && InMoveArea(touch.position))
            {
                // Okay, starting a touch;
                ActiveFingerID = touch.fingerId;
                UpdateKnib(touch.position);
            }
            else if (InActionArea(touch.position))
            {
                UpdateAction(touch);
            }
        }
    }
Ejemplo n.º 3
0
    //-------------------------------------------------------------------
    void Update()
    {
        if (GamepadID < 0)
        {
            return;
        }

        X      = Input.GetAxis("Horizontal" + GamepadID);
        Y      = Input.GetAxis("Vertical" + GamepadID);
        Action = Input.GetKeyDown(GetActionKey(GamepadID));

        VirtualController.SetMovement(new Vector2(X, Y).normalized);
        if (Action)
        {
            VirtualController.DoAction();

            if (GameManager.GetInstance().m_currentState == eGameState.WAIT_FOR_READY)
            {
                // toggle ready
                if (Action)
                {
                    VirtualController.SetReady(!VirtualController.ClientIsReady);
                }
            }
        }
    }
Ejemplo n.º 4
0
    //---------------------------------------------------------------------
    // Update is called once per frame
    void Update()
    {
        if ((Application.platform == RuntimePlatform.WindowsEditor) || (Application.platform == RuntimePlatform.WindowsEditor))
        {
            VirtualNetworkController controller = HopperNetwork.GetMyController();

            if (controller != null)
            {
                float x      = Input.GetAxis("Horizontal");
                float y      = Input.GetAxis("Vertical");
                bool  action = Input.GetButtonDown("Fire1");

                Vector2 move = new Vector2(x, y);
                if (move.sqrMagnitude > 1.0f)
                {
                    move.Normalize();
                }


                UpdateMovementKnib(move);
                controller.SetMovement(move);

                if (action)
                {
                    DoAction();
                }
            }
        }

        if (!Input.touchSupported)
        {
            // fake touch
            if (Input.GetMouseButton(0) && (!HackActionDown || (ActiveFingerID >= 0)))
            {
                HackActionDown = true;
                Touch touch = new Touch();
                touch.fingerId = 1;
                if (ActiveFingerID == -1)
                {
                    touch.phase = TouchPhase.Began;
                }
                else
                {
                    touch.phase = TouchPhase.Moved;
                }

                touch.position = Input.mousePosition;
                ProcessTouch(touch);
            }
            else if (HackActionDown && !Input.GetMouseButton(0))
            {
                Touch touch = new Touch();
                touch.phase    = TouchPhase.Ended;
                touch.fingerId = ActiveFingerID;
                touch.position = Input.mousePosition;
                ProcessTouch(touch);
                HackActionDown = false;
            }
        }

        if (Input.touches.Length > 0)
        {
            for (int i = 0; i < Input.touches.Length; ++i)
            {
                ProcessTouch(Input.touches[i]);
            }
        }
    }