Unity 滑动事件6个方向的实现

C#脚本如下,如何获取入参,如何判断4个方向的情况请参考http://blog.csdn.net/jarod_jianghe/article/details/52423431

private float tan10 = 0.176f;
private float tan60 = 1.73f;
private float tan70 = 2.75f;
//x和y分别代表起点及终点的坐标差值,返回数字1-6代表6个方向,如图所示,0代表介于方向之间,不作处理
//     6
//  5     1
//  4     2
//     3
private int checkForward(float x, float y)
    {
        if ((Mathf.Abs(x) * tan60) > Mathf.Abs(y))
        {
            if ((Mathf.Abs(x) * tan10) < Mathf.Abs(y))
            {
                if (x > 0 && y > 0) { return 1; }
                if (x > 0 && y < 0) { return 2; }
                if (x < 0 && y > 0) { return 5; }
                if (x < 0 && y < 0) { return 4; }
            }
            else { return 0; }
        }
        else
        {
            if ((Mathf.Abs(x) * tan70) < Mathf.Abs(y))
            {
                if (y > 0) { return 6; }
                if (y < 0) { return 3; }
            }
            else { return 0; }
        }
        return 0;
    }

你可能感兴趣的:(Unity 滑动事件6个方向的实现)