Beispiel #1
0
    private void FindNearGridOnDirection(LevelGrid grid, NearGridDirection dir)
    {
        int        layerMask = 1 << 9 | 1 << 10;
        RaycastHit hit;
        Vector3    raycastPos = grid.position + 0.5f * grid.direction;
        Quaternion rotation   = Quaternion.FromToRotation(Vector3.up, grid.direction);
        Vector3    direction  = Vector3.back;

        switch (dir)
        {
        case NearGridDirection.BACK:
        {
            direction = Vector3.back;
            break;
        }

        case NearGridDirection.FORWARD:
        {
            direction = Vector3.forward;
            break;
        }

        case NearGridDirection.LEFT:
        {
            direction = Vector3.left;
            break;
        }

        case NearGridDirection.RIGHT:
        {
            direction = Vector3.right;
            break;
        }
        }

        if (Physics.Raycast(raycastPos, rotation * direction, out hit, 1f, layerMask))
        {
            GridSplitter cube = hit.collider.GetComponent <GridSplitter>();
            grid.SetNearGrid(cube.GetGridAtPosition(hit.point), dir);
            //grid.setDebugInfo(raycastPos, hit.point, dir);
        }
        else if (Physics.Raycast(raycastPos, grid.position + rotation * direction - raycastPos, out hit, 2f, layerMask))
        {
            GridSplitter cube = hit.collider.GetComponent <GridSplitter>();
            grid.SetNearGrid(cube.GetGridAtPosition(hit.point), dir);
            //grid.setDebugInfo(raycastPos, hit.point, dir);
        }
        else if (Physics.Raycast(raycastPos - grid.direction + rotation * direction, rotation * ((-1) * direction), out hit, 1f, layerMask))
        {
            GridSplitter cube = hit.collider.GetComponent <GridSplitter>();
            grid.SetNearGrid(cube.GetGridAtPosition(hit.point), dir);
            //grid.setDebugInfo(raycastPos - grid.direction + rotation * direction, hit.point, dir);
        }
    }
Beispiel #2
0
 //获取对应方向的LevelGrid
 public LevelGrid GetNearGrid(NearGridDirection dir)
 {
     return(nearGrids[(int)dir - 1]);
 }
Beispiel #3
0
 public void setDebugInfo(Vector3 pos, Vector3 hit, NearGridDirection dir)
 {
     raycastPos[(int)dir - 1] = pos;
     hitPos[(int)dir - 1]     = hit;
 }
Beispiel #4
0
 //设置对应方向的LevelGrid
 public void SetNearGrid(LevelGrid near, NearGridDirection dir)
 {
     nearGrids[(int)dir - 1] = near;
 }