public static Vector2 VectorFromDirection16(Direction16 dir)
    {
        switch (dir)
        {
        default:
        case Direction16.None:
            return(Vector2.zero);

        case Direction16.Up:
            return(Vector2.up);

        case Direction16.UpUpRight:
            return(new Vector2(1, 2).normalized);

        case Direction16.UpRight:
            return(new Vector2(1, 1).normalized);

        case Direction16.UpRightRight:
            return(new Vector2(2, 1).normalized);

        case Direction16.Right:
            return(Vector2.right);

        case Direction16.DownRightRight:
            return(new Vector2(2, -1).normalized);

        case Direction16.DownRight:
            return(new Vector2(1, -1).normalized);

        case Direction16.DownDownRight:
            return(new Vector2(1, -2).normalized);

        case Direction16.Down:
            return(Vector2.down);

        case Direction16.DownDownLeft:
            return(new Vector2(-1, -2).normalized);

        case Direction16.DownLeft:
            return(new Vector2(-1, -1).normalized);

        case Direction16.DownLeftLeft:
            return(new Vector2(-2, -1).normalized);

        case Direction16.Left:
            return(Vector2.left);

        case Direction16.UpLeftLeft:
            return(new Vector2(-2, 1).normalized);

        case Direction16.UpLeft:
            return(new Vector2(-1, 1).normalized);

        case Direction16.UpUpLeft:
            return(new Vector2(-1, 2).normalized);
        }
    }
示例#2
0
        public void CommandExecuted(CommandUI cmdUI, object sender)
        {
            Array da = Enum.GetValues(Direction16.NORTH.GetType());

            Debug.WriteLine("--test1--");
            foreach (Direction16 d in da)
            {
                Direction dir = Direction.Get(d);
                Debug.Write(string.Format("{0}:c={1},ic={2},mj={3},", dir.Name, dir.IsCardinal, dir.IsInterCardinal, dir.IsMajor));
                Debug.WriteLine(string.Format("opposite={0},left={1},left_q={2},right={3},right_q={4}", dir.Opposite.Name, dir.Left.Name, dir.LeftQuater.Name, dir.Right.Name, dir.RightQuater.Name));
            }
            Debug.WriteLine("--test2--");
            for (int i = 0; i < da.Length; i++)
            {
                for (int j = 0; j < da.Length; j++)
                {
                    Direction d1 = (Direction16)da.GetValue(i);
                    Direction d2 = (Direction16)da.GetValue(j);
                    Debug.Write(string.Format("{0}<->{1}:", d1.Name, d2.Name));
                    Debug.WriteIf(d1 == d2, "==,");
                    Debug.WriteIf(d1.Equals(d2), "Equals,");
                    Debug.WriteIf(d1.IsParallel(d2), "Parallel,");
                    Debug.WriteIf(d1.IsOpposite(d2), "Opposite,");
                    Debug.WriteIf(d1.IsRightAngle(d2), "RightAngle,");
                    Debug.WriteLine(string.Format("Angle={0}", Direction.AngleStepCount(d1, d2)));
                }
            }

            // cast test
            Direction direction;

            direction = Direction4.EAST;
            direction = Direction8.NORTHEAST;
            direction = Direction16.NORTHNORTHWEST;
            //Direction4 d4 = direction; // compile error
            //Direction8 d8 = direction; // compile error
            Direction16 d16 = direction;
        }
示例#3
0
 /// <summary>
 /// create from <code>Direction16</code>
 /// </summary>
 public static Direction Get(Direction16 dir)
 {
     return(directions[(int)dir]);
 }