void OnPostRender () {
// 遍历字典中每一对 Key - Value
foreach (KeyValuePair <string, Grid [,]> keyValue in gridDic) {
// 遍历二维数组中每一个格子
foreach (Grid g in keyValue.Value) {
// 绘制格子
DrawGrid (g);
}
}
if (shouldDrawRect) {
Vector3 endPos = Input.mousePosition;
GL.PushMatrix ();
greenMat.SetPass (0);
GL.LoadPixelMatrix ();
GL.Begin (GL.QUADS);
GL.Vertex3 (startPos.x, startPos.y, 0f);
GL.Vertex3 (startPos.x, endPos.y, 0f);
GL.Vertex3 (endPos.x, endPos.y, 0f);
GL.Vertex3 (endPos.x, startPos.y, 0f);
GL.End ();
GL.PopMatrix ();
foreach (Move m in gc.selectedSoldiers) {
m.selected = false;
}
gc.selectedSoldiers.Clear ();
foreach (Move m in gc.soldiers) {
Vector3 pos = m.transform.position;
Vector3 tempPos = Camera.main.WorldToScreenPoint (pos);
Vector3 p1 = startPos;
Vector3 p2 = endPos;
if (startPos.x < endPos.x) {
p1.x = endPos.x;
p2.x = startPos.x;
}
if (startPos.y < endPos.y) {
p1.y = endPos.y;
p2.y = startPos.y;
}
if (tempPos.x > p2.x && tempPos.x < p1.x && tempPos.y > p2.y && tempPos.y < p1.y) {
gc.selectedSoldiers.Add (m);
m.selected = true;
}
}
}
}