예제 #1
0
        public void Process(ref InputInteractionContext context)
        {
            var actuation = context.ComputeMagnitude();

            switch (behavior)
            {
            case PressBehavior.PressOnly:
                if (m_WaitingForRelease)
                {
                    if (actuation <= releasePointOrDefault)
                    {
                        m_WaitingForRelease = false;
                        context.Canceled();
                    }
                }
                else if (actuation >= pressPointOrDefault)
                {
                    m_WaitingForRelease = true;
                    // Stay performed until release.
                    context.PerformedAndStayPerformed();
                }
                else if (actuation > 0 && !context.isStarted)
                {
                    context.Started();
                }
                break;

            case PressBehavior.ReleaseOnly:
                if (m_WaitingForRelease)
                {
                    if (actuation <= releasePointOrDefault)
                    {
                        m_WaitingForRelease = false;
                        context.Performed();
                        context.Canceled();
                    }
                }
                else if (actuation >= pressPointOrDefault)
                {
                    m_WaitingForRelease = true;
                    if (!context.isStarted)
                    {
                        context.Started();
                    }
                }
                else
                {
                    var started = context.isStarted;
                    if (actuation > 0 && !started)
                    {
                        context.Started();
                    }
                    else if (Mathf.Approximately(0, actuation) && started)
                    {
                        context.Canceled();
                    }
                }
                break;

            case PressBehavior.PressAndRelease:
                if (m_WaitingForRelease)
                {
                    if (actuation <= releasePointOrDefault)
                    {
                        m_WaitingForRelease = false;
                        context.Performed();
                        if (Mathf.Approximately(0, actuation))
                        {
                            context.Canceled();
                        }
                    }
                }
                else if (actuation >= pressPointOrDefault)
                {
                    m_WaitingForRelease = true;
                    context.PerformedAndStayPerformed();
                }
                else
                {
                    var started = context.isStarted;
                    if (actuation > 0 && !started)
                    {
                        context.Started();
                    }
                    else if (Mathf.Approximately(0, actuation) && started)
                    {
                        context.Canceled();
                    }
                }
                break;
            }
        }