1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
[FONT=Monospace]usingUnityEngine;
usingSystem.Collections;
publicclasssetLevel : MonoBehaviour {
publicGameObjecttiles;
constintmaxTilesX = 15;
constintmaxTilesY = 6;
boolhasDisplayed;
int[,] tableau = newint[6,15] { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
,{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
,{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
,{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
,{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
//Usethisforinitialization
voidStart () {
hasDisplayed = false;
}
//Updateiscalledonceperframe
voidUpdate () {
if (hasDisplayed == false) {
GameObjectsceneCamObj = GameObject.Find( "SceneCamera" );
if ( sceneCamObj != null )
{
drawLevel(sceneCamObj.GetComponent<Camera>());
}
hasDisplayed = true;
}
}
voiddrawLevel(CamerasceneCamera) {
intscreenWidth = sceneCamera.pixelWidth;
intscreenHeight = sceneCamera.pixelHeight;
Debug.Log ("Screen Width = " + screenWidth + "\nScreen Height = " + screenHeight);
intobjectWidth = (screenWidth - 20) / maxTilesX;
intobjectHeight = (screenHeight - 20) / maxTilesY;
Debug.Log ("Object Width = " + objectWidth + "\nObject Height = " + objectHeight);
for (inti=0; i < maxTilesY; ++i) {
for (intj=0; j < maxTilesX; ++j) {
if (0 < tableau[i,j]) {
Instantiate(tiles, newVector2(j*objectWidth,i*objectHeight),Quaternion.identity);
Debug.Log("Line:" + j + ", Column:" + i + ", position(" + j*objectWidth + "," + i*objectHeight + ")");
}
}
}
}
}[/FONT] |
Partager