Ejemplo 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);
    }
Ejemplo n.º 2
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");
    }
Ejemplo 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), 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");
    }
Ejemplo n.º 4
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);
            }
        }
    }
Ejemplo n.º 5
0
        public float UpdateMovement()
        {
            Vector3 inputVec = new Vector3();

            joy = VCAnalogJoystickBase.GetInstance("stick");

            float x = cameraController.transform.forward.x;
            float z = cameraController.transform.forward.z;

            float sum       = Mathf.Abs(x) + Mathf.Abs(z);
            float remainder = 1 - sum;

            float cameraX = (x + remainder * (x / sum) + 1) / 2;
            float cameraZ = (z + remainder * (z / sum) + 1) / 2;

            inputVec = new Vector3(Mathf.Lerp(-joy.AxisY, joy.AxisY, cameraX) + Mathf.Lerp(-joy.AxisX, joy.AxisX, cameraZ), 0,
                                   Mathf.Lerp(joy.AxisX, -joy.AxisX, cameraX) + Mathf.Lerp(-joy.AxisY, joy.AxisY, cameraZ));

            inputVec *= Speed;

            if ((inputVec.z != 0 || inputVec.x != 0))
            {
                if (!audioSource.isPlaying)
                {
                    audioSource.clip = moveSound;
                    audioSource.Play();
                }
            }
            else
            {
                GetComponent <AudioSource>().Stop();
            }

            controller.Move((inputVec + Vector3.up * -gravity + new Vector3(0, 0, 0)) * Time.deltaTime);

            if (freeRoam)
            {
                // Rotation
                if (inputVec != Vector3.zero)
                {
                    transform.rotation = Quaternion.Slerp(transform.rotation,
                                                          Quaternion.LookRotation(inputVec),
                                                          Time.deltaTime * rotationDamping);
                }
            }
            else if (currentFocus != null)
            {
                Quaternion lookRotation;
                Vector3    direction;

                direction    = (currentFocus.transform.position - transform.position).normalized;
                lookRotation = Quaternion.LookRotation(direction);

                transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * rotationDamping / 3);
            }
            else
            {
                freeRoam = true;
            }

            return(inputVec.magnitude);
        }
    void FixedUpdate()
    {
        if (Network.peerType == NetworkPeerType.Server)
        {
            if (Input.GetAxis("Horizontal") > 0)
            {
                //transform.Translate (new Vector3 (speed*Time.deltaTime, 0, 0));
                Press(1, 0);
            }
            if (Input.GetAxis("Horizontal") < 0)
            {
                //transform.Translate (new Vector3 (-speed*Time.deltaTime, 0, 0));
                Press(-1, 0);
            }
            if (canClimb == true)
            {
                if (Input.GetAxis("Vertical") > 0)
                {
                    //transform.Translate (new Vector3 (0, speed*Time.deltaTime, 0));
                    Press(0, 1);
                }
                if (Input.GetAxis("Vertical") < 0)
                {
                    //transform.Translate (new Vector3 (0, -speed*Time.deltaTime, 0));
                    Press(0, -1);
                }
            }
        }
        if (Network.peerType == NetworkPeerType.Client)
        {
            VCAnalogJoystickBase moveJoystick = VCAnalogJoystickBase.GetInstance("MoveJoyStick");
            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;

                if (Mathf.Abs(directionVector.x) > Mathf.Abs(directionVector.y) || canClimb == false)
                {
                    if (directionVector.x < 0)
                    {
                        GetComponent <NetworkView>().RPC("Press", RPCMode.Server, -1, 0);
                    }
                    if (directionVector.x > 0)
                    {
                        GetComponent <NetworkView>().RPC("Press", RPCMode.Server, 1, 0);
                    }
                }
                if (Mathf.Abs(directionVector.x) <= Mathf.Abs(directionVector.y) && canClimb == true)
                {
                    if (directionVector.y < 0)
                    {
                        GetComponent <NetworkView>().RPC("Press", RPCMode.Server, 0, -1);
                    }
                    if (directionVector.y > 0)
                    {
                        GetComponent <NetworkView>().RPC("Press", RPCMode.Server, 0, 1);
                    }
                }
            }

//			VCDPadBase dpad = VCDPadBase.GetInstance("dpad");
//			if (dpad){
//
//				if (dpad.Left)
//					networkView.RPC("Press", RPCMode.Server, -1, 0);
//				if (dpad.Right)
//					networkView.RPC("Press", RPCMode.Server, 1, 0);
//				if (canClimb){
//					if (dpad.Up)
//						networkView.RPC("Press", RPCMode.Server, 0, 1);
//					if (dpad.Down)
//						networkView.RPC("Press", RPCMode.Server, 0, -1);
//				}
//			}
        }
    }