Je souhaite faire une sélecteur de niveau en creant une sorte de grille et je voulais savoir si ce code était propre et ne demander pas trop de ressource. Sa serais pas des applications mobiles.
Code : Tout sélectionner
public int nbLevel;
public int nbLvlAxeX =10; //nb de level sur axe x
public int nbLvlAxeY =10; //nb de level sur axe x
public int paddingX;// le padding entre chaque sur axe x
public int paddingY;// le padding entre chaque sur axe y
private int sizeBtnX; //la larguer des bouton
private int sizeBtnY;// la hauteur d'unj bouton
private int currentPosX = 0;
private int currentPosY = 0;
void OnGUI() {
//selGridInt = GUI.SelectionGrid(new Rect(25, 25, 100, 30), selGridInt, selStrings, 2);
int cptLine = 1;
for(int i=0; i<nbLevel; i++){
if(GUI.Button(new Rect(currentPosX,currentPosY,sizeBtnX,sizeBtnY),"Level"+i)){
Debug.Log("Level"+ i);
}
currentPosX += sizeBtnX +paddingX;
if(cptLine ==nbLvlAxeX){
cptLine = 0;
currentPosX = 0;
currentPosY = sizeBtnY+paddingY;
}
cptLine++;
}
currentPosX = 0;
currentPosY = 0;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void Awake(){
sizeBtnX = (int)(Screen.width/nbLvlAxeX) -paddingX;
sizeBtnY= (int)(Screen.height/nbLvlAxeY) -paddingY;
}