//--------------------------------------------------------------------------------------------- protected virtual void OnDrawGizmos() { Follow(); if (!m_pCollider) { m_pCollider = GetComponent <PolygonCollider2D>(); } Vector2[] points = m_pCollider.points; Vector2 p2D = transform.position; if (points == null) { return; } Vector3 pointCurrent, pointNext; Vector3 angles = transform.rotation.eulerAngles; for (var i = 0; i < points.Length - 1; i++) { pointCurrent = KDTools.Adjust(points[i], p2D, angles, transform.localScale); pointNext = KDTools.Adjust(points[i + 1], p2D, angles, transform.localScale); Gizmos.DrawLine(pointCurrent, pointNext); } pointCurrent = KDTools.Adjust ( points[points.Length - 1], p2D, angles, transform.localScale ); pointNext = KDTools.Adjust(points[0], p2D, angles, transform.localScale); Gizmos.DrawLine(pointCurrent, pointNext); }
//------------------------------------------------------------------------------------------ private static bool ItsFree ( IEnumerable <GameObject> a_tiles, PolygonCollider2D[] a_obstacles, Rect a_vTile, Vector2 a_point ) { var corner1 = new Vector2(a_vTile.xMin, a_vTile.yMin); var corner2 = new Vector2(a_vTile.xMax, a_vTile.yMin); var corner3 = new Vector2(a_vTile.xMin, a_vTile.yMax); var corner4 = new Vector2(a_vTile.xMax, a_vTile.yMax); Vector2[] corners = { corner1, corner2, corner3, corner4 }; if ( corners.Any(a_corner => !m_floodArea.OverlapPoint(a_corner) || a_obstacles.Any(a_obstacle => a_obstacle.OverlapPoint(a_corner))) ) { return(false); } if (a_obstacles.Any(a_collider2D => a_collider2D.OverlapPoint(a_point))) { return(false); } if ( a_obstacles.Any ( a_obstacle => a_obstacle.points.Any ( a_oPoint => a_vTile.Contains ( ((Vector2)KDTools.Adjust ( a_oPoint, a_obstacle.transform.position, a_obstacle.transform.eulerAngles, a_obstacle.transform.localScale ) ) ) ) ) ) { return(false); } if (a_tiles.Any(a_tile => Vector2.Distance(a_point, a_tile.transform.position) < m_size)) { return(false); } return(true); }