you get a uai from 2 parts of equal weighting, your individual ranking in your school and the performance of you and the school as a whole.
your uai is calculated from your hsc mark and school assessment mark.
the hsc mark depends on your performance in the hsc exams.
the school assessment mark depends on your rank and the performance of your school. for eg- say that you are ranked 1st in maths. then your hsc mark will be what you get and your school assessment mark will be the top mark from your school. you see how you benefit by coming 1st in school...
say if you come 10th, then once again your hsc mark will depend on the exam mark you get and your school assessment mark will approx. be the 10th best mark from your school[this distribution of school assessment marks uses relative differences between internal marks, rather than actual ranks, but i used the latter for simplicity].
once the hsc mark and school assessment has been determined for each of your subjects, then they are averaged, and used in calculation of you uai.