Ejemplo n.º 1
0
        public static void BuildXYSquareInputBasedOnAxisInput(
            ButtonControl controlLeft,
            ButtonControl controlRight,
            ButtonControl controlDown,
            ButtonControl controlUp,
            AxisControl controlX,
            AxisControl controlY,
            Vector2Control control,
            Range deadZones
            )
        {
            // Calculate new vector.
            Vector2 vector = new Vector2(
                -controlLeft.rawValue + controlRight.rawValue,
                -controlDown.rawValue + controlUp.rawValue);

            // Set raw control values.
            control.rawValue  = vector;
            controlX.rawValue = vector.x;
            controlY.rawValue = vector.y;

            // Apply deadzones.
            vector.x = GetDeadZoneAdjustedValue(vector.x, deadZones);
            vector.y = GetDeadZoneAdjustedValue(vector.y, deadZones);

            // Set control values.
            control.value      = vector;
            controlX.value     = vector.x;
            controlY.value     = vector.y;
            controlLeft.value  = Mathf.Max(0, -vector.x);
            controlRight.value = Mathf.Max(0, vector.x);
            controlDown.value  = Mathf.Max(0, -vector.y);
            controlUp.value    = Mathf.Max(0, vector.y);
        }
Ejemplo n.º 2
0
        public static void BuildXYCircularInputBasedOnAxisInput(
            ButtonControl controlLeft,
            ButtonControl controlRight,
            ButtonControl controlDown,
            ButtonControl controlUp,
            AxisControl controlX,
            AxisControl controlY,
            Vector2Control control,
            Range deadZones
            )
        {
            // Calculate new vector.
            Vector2 vector = new Vector2(
                -controlLeft.rawValue + controlRight.rawValue,
                -controlDown.rawValue + controlUp.rawValue);

            // Set raw control values.
            control.rawValue  = vector;
            controlX.rawValue = vector.x;
            controlY.rawValue = vector.y;

            // Apply deadzones.
            float magnitude    = vector.magnitude;
            float newMagnitude = GetDeadZoneAdjustedValue(magnitude, deadZones);

            if (newMagnitude == 0)
            {
                vector = Vector2.zero;
            }
            else
            {
                vector *= (newMagnitude / magnitude);
            }

            // Set control values.
            control.value      = vector;
            controlX.value     = vector.x;
            controlY.value     = vector.y;
            controlLeft.value  = Mathf.Max(0, -vector.x);
            controlRight.value = Mathf.Max(0, vector.x);
            controlDown.value  = Mathf.Max(0, -vector.y);
            controlUp.value    = Mathf.Max(0, vector.y);
        }