Exemplo n.º 1
0
    void FixedUpdate()
    {
        VCAnalogJoystickBase moveJoystick = VCAnalogJoystickBase.GetInstance("MoveJoyStick");
        VCButtonBase         actionButton = VCButtonBase.GetInstance("Action");
        Vector2 directionVector           = new Vector2(moveJoystick.AxisX, moveJoystick.AxisY);

        if (directionVector != Vector2.zero)
        {
            // Get the length of the directon vector and then normalize it
            // Dividing by the length is cheaper than normalizing when we already have the length anyway
            var directionLength = directionVector.magnitude;
            directionVector = directionVector / directionLength;

            // Make sure the length is no bigger than 1
            directionLength = Mathf.Min(1.0f, directionLength);

            // Make the input vector more sensitive towards the extremes and less sensitive in the middle
            // This makes it easier to control slow speeds when using analog sticks
            directionLength = directionLength * directionLength;

            // Multiply the normalized direction vector by the modified length
            directionVector = directionVector * directionLength;
        }

        GetComponent <NetworkView>().RPC("SendInput", RPCMode.Server, directionVector.x, directionVector.y,
                                         actionButton.Pressed, Input.touchCount > 0);
    }
Exemplo n.º 2
0
 void Update()
 {
     if (isPlayer)
     {
         abtn         = VCButtonBase.GetInstance("A");
         abtn.OnPress = ButtonPress;
         bbtn         = VCButtonBase.GetInstance("B");
         bbtn.OnPress = ButtonPress;
         cbtn         = VCButtonBase.GetInstance("C");
         cbtn.OnPress = ButtonPress;
     }
 }
Exemplo n.º 3
0
    void OnGUI()
    {
        // if there's an analog joystick, output some info
        if (VCAnalogJoystickBase.GetInstance("stick") != null)
        {
            GUI.Label(new Rect(10, 10, 300, 20), "Joystick Axes: " + VCAnalogJoystickBase.GetInstance("stick").AxisX + " " + VCAnalogJoystickBase.GetInstance("stick").AxisY);
        }

        // if there's an a button, output some info
        if (VCButtonBase.GetInstance("A") != null)
        {
            GUI.Label(new Rect(10, 30, 300, 20), "Button Hold (s): " + VCButtonBase.GetInstance("A").HoldTime.ToString());
        }

        // if there's a dpad, output some info
        VCDPadBase dpad = VCDPadBase.GetInstance("dpad");

        if (dpad != null)
        {
            string str = "DPad: ";
            if (dpad.Left)
            {
                str += "Left ";
            }
            if (dpad.Right)
            {
                str += "Right ";
            }
            if (dpad.Up)
            {
                str += "Up ";
            }
            if (dpad.Down)
            {
                str += "Down ";
            }
            if (dpad.Pressed(VCDPadBase.EDirection.None))
            {
                str += "(No Direction)";
            }

            GUI.Label(new Rect(10, 50, 300, 20), str);
        }

        GUI.Label(new Rect(10, 70, 300, 20), "Move cube using controls");
        GUI.Label(new Rect(10, 90, 300, 20), "Double tap joystick / Press A for particles");
    }
Exemplo n.º 4
0
    void OnGUI()
    {
        // if there's an analog joystick, output some info
        if (VCAnalogJoystickBase.GetInstance("stick") != null)
        {
            GUI.Label(new Rect(10, 10, 300, 20), VCAnalogJoystickBase.GetInstance("stick").AxisX + " " + VCAnalogJoystickBase.GetInstance("stick").AxisY);
        }

        // if there's an a button, output some info
        if (VCButtonBase.GetInstance("BtnA") != null)
        {
            GUI.Label(new Rect(10, 30, 300, 20), "aaaaaaaaaa");
        }
        else
        {
            GUI.Label(new Rect(10, 30, 300, 20), "nullllll");
        }

        // if there's a dpad, output some info
        VCDPadBase dpad = VCDPadBase.GetInstance("dpad");

        if (dpad != null)
        {
            string str = "";
            if (dpad.Left)
            {
                str += "Left ";
            }
            if (dpad.Right)
            {
                str += "Right ";
            }
            if (dpad.Up)
            {
                str += "Up ";
            }
            if (dpad.Down)
            {
                str += "Down ";
            }

            GUI.Label(new Rect(10, 50, 300, 20), str);
        }

        GUI.Label(new Rect(10, 70, 300, 20), "Move cube using controls");
        GUI.Label(new Rect(10, 90, 300, 20), "Double tap joystick / Press A for particles");
    }
Exemplo n.º 5
0
    void Update()
    {
        // Use the DPad to move the cube container
        if (cubeContainer)
        {
            // try and get the dpad
            VCDPadBase dpad = VCDPadBase.GetInstance("dpad");

            // if we got one, perform movement
            if (dpad)
            {
                if (dpad.Left)
                {
                    cubeContainer.transform.Translate(-moveSpeed * Time.deltaTime, 0.0f, 0.0f);
                }
                if (dpad.Right)
                {
                    cubeContainer.transform.Translate(moveSpeed * Time.deltaTime, 0.0f, 0.0f);
                }
                if (dpad.Up)
                {
                    cubeContainer.transform.Translate(0.0f, moveSpeed * Time.deltaTime, 0.0f);
                }
                if (dpad.Down)
                {
                    cubeContainer.transform.Translate(0.0f, -moveSpeed * Time.deltaTime, 0.0f);
                }
            }

            // do the same for the analog joystick
            VCAnalogJoystickBase joy = VCAnalogJoystickBase.GetInstance("stick");
            if (joy != null)
            {
                cubeContainer.transform.Translate(moveSpeed * Time.deltaTime * joy.AxisX, moveSpeed * Time.deltaTime * joy.AxisY, 0.0f);
            }
        }

        // rotate the cube for coolness effect
        if (cube)
        {
            cube.transform.RotateAroundLocal(new Vector3(1.0f, 1.0f, 0.0f), Time.deltaTime);
        }

        // and emit particles based on the time we've held down our A button (if we have one)
        VCButtonBase abtn = VCButtonBase.GetInstance("A");

        if (abtn != null && cubeContainer)
        {
            ParticleSystem particles = cubeContainer.GetComponentInChildren <ParticleSystem>();
            if (particles != null)
            {
                particles.emissionRate = abtn.HoldTime * 50.0f;
            }

            // emit some particles whenever joystick is double clicked
            VCAnalogJoystickBase joy = VCAnalogJoystickBase.GetInstance("stick");
            if (joy != null && particles != null && joy.TapCount > 1)
            {
                particles.emissionRate = 150.0f;
            }
        }

        // example of how to detect if press began or ended exactly on this frame
        if (abtn != null)
        {
            if (abtn.PressBeganThisFrame)
            {
                Debug.Log("Press began on frame " + Time.frameCount);
            }

            if (abtn.PressEndedThisFrame)
            {
                Debug.Log("Press ended on frame " + Time.frameCount);
            }
        }
    }