有这个很棒的链接: Drawing Isometric game worlds
然而,它从左侧绘制。我很难调整算法。您将如何按照深度顺序绘制它?哪个深度排序是正确的?
此:
.. .. 01 .. ..
.. 06 02 ..
.. 11 07 03 ..
16 12 08 04
21 17 13 09 05
22 18 14 10
.. 23 19 15 ..
.. 24 20 ..
.. .. 25 .. ..
还是这个? :
...1...
..234..
.56789.
..abc..
...d...
到目前为止,我已经从上面的链接向Unity C#移植了代码,但所有使用它的实验都没有产生结果。
void Start () {
terrainObjects = new GameObject[terrainSizeX, terrainSizeY];
for (int x = 0; x < terrainSizeX; x++) {
for (int y = 0; y < terrainSizeY; y++) {
terrainObjects [x, y] = new GameObject ("Tile @ " + x + "-" + y);
terrainObjects [x, y].AddComponent<SpriteRenderer> ();
terrainObjects [x, y].GetComponent<SpriteRenderer> ().sprite = tile;
terrainObjects [x, y].transform.SetParent (this.gameObject.transform);
terrainObjects [x, y].transform.position = new Vector3 ((y * tileSizeX / 2) + (x * tileSizeX / 2),
(x * tileSizeY / 2) - (y * tileSizeY / 2), 0);
}
}
}