Unified Foothold Selection and Motion Planning for Legged Systems in Real-Time over Rough Terrain