示例#1
0
    public static List <Vector3> PathFromGround(Ground ground)
    {
        List <Vector3> path = new List <Vector3>();

        int[][] groundGrid = new int[ground.width][];
        for (int i = 0; i < ground.width; i++)
        {
            groundGrid[i] = new int[ground.height];
            for (int j = 0; j < ground.height; j++)
            {
                groundGrid[i][j] = ground.grid[i + j * ground.width];
            }
        }

        int cursorI = 0;
        int cursorJ = 0;

        path.Add(FenceDetection.SetFirst(groundGrid, ground.width, ground.height, ref cursorI, ref cursorJ));
        while (NextLeft(groundGrid, ground.width, ground.height, ref cursorI, ref cursorJ))
        {
            Debug.Log("Next Left");
            path.Add(new Vector3(cursorI, 0, cursorJ));
        }
        while (NextTop(groundGrid, ground.width, ground.height, ref cursorI, ref cursorJ))
        {
            Debug.Log("Next Top");
            path.Add(new Vector3(cursorI, 0, cursorJ));
        }
        while (NextRight(groundGrid, ground.width, ground.height, ref cursorI, ref cursorJ))
        {
            Debug.Log("Next Right");
            path.Add(new Vector3(cursorI, 0, cursorJ));
        }
        while (NextBottom(groundGrid, ground.width, ground.height, ref cursorI, ref cursorJ))
        {
            Debug.Log("Next Bottom");
            path.Add(new Vector3(cursorI, 0, cursorJ));
        }
        path.RemoveAt(path.Count - 1);

        return(path);
    }
示例#2
0
 public void InitializePath()
 {
     this.path = FenceDetection.PathFromGround(FindObjectOfType <Ground>());
     this.UpdateLength();
 }