A unified optimal impact angle guidance law is designed for different types of interceptors and targets. By solving a linear quadratic optimal control problem with the energy consumption weighted by an arbitrary positive function, the generalized guidance command is determined in a closed-loop feedback form. The main feature of the proposed algorithm is that it can be applied to varying-speed interceptors and targets. The weighting function also brings the command shaping capability of the proposed guidance law. To show the applicability of the proposed guidance law, several illustrative examples covering different types of interceptors and targets are provided. Numerical simulations are conducted to demonstrate the effectiveness of the proposed guidance algorithm.