/// <summary>
        /// Determines whether the control is pointing towards the configured North, South, East, or West direction(s).
        /// </summary>
        /// <param name="context">The input control information context.</param>
        /// <returns>Returns <see langword="true"/> if pointing in "this" direction. Otherwise, returns <see langword="false"/>.</returns>
        bool IsValidDirection(ref InputInteractionContext context)
        {
            var value            = context.ReadValue <Vector2>();
            var cardinal         = CardinalUtility.GetNearestCardinal(value);
            var nearestDirection = GetNearestDirection(cardinal);

            return((nearestDirection & directions) != 0);
        }
Example #2
0
        public void Process(ref InputInteractionContext context)
        {
            var value = context.ReadValue <Vector2>();

            if (value.sqrMagnitude > 0)
            {
                if (!context.isStarted)
                {
                    context.Started();
                }
                else
                {
                    context.PerformedAndStayStarted();
                }
            }
            else if (context.isStarted)
            {
                // Went back to below deadzone.
                context.Cancelled();
            }
        }
    public void Process(ref InputInteractionContext context)
    {
        Vector2 stickPos = context.ReadValue <Vector2>();

        if (context.timerHasExpired)
        {
            context.Canceled();
        }

        if (stickPos.magnitude < deadZone)
        {
            hasStarted = false;
            context.Canceled();
        }
        switch (context.phase)
        {
        case InputActionPhase.Waiting:
            if (stickPos.magnitude > deadZone && !hasStarted)
            {
                context.Started();
                timeStartedMoving = context.time;
                hasStarted        = true;
            }
            break;

        case InputActionPhase.Started:
            if ((context.time - timeStartedMoving) > duration || stickPos.magnitude <= deadZone)
            {
                context.Canceled();
            }
            if (stickPos.magnitude >= smashZone)
            {
                context.Performed();
                context.SetTimeout(0.1f);
            }
            break;
        }
    }