A unified variational model for the dynamics of perfect unilateral constraints