private void LoadPattern() { pattern.DeleteGrid(); //this is obvious pattern.GenerateGrid(data.size); //..................set Tiles as data 's grid.......................// for (int i = 0; i < data.size; i++) { for (int j = 0; j < data.size * 2; j++) { if (data.grid[i, j] == 0) { data.grid[i, j] = 0; //LOL ^-^ } else { //this part is similar to Draw method in MGrid script >>((set material from data and instantiate one where i,j)) pattern.Set_Mat_ID(data.grid[i, j]); pattern.SetTileMatColor(); Vector3 temp; //// what i did here /// for example i,j = 0 means left corner of plane /// i,j * cell size means we are in first left corner cell /// + cell size /2 means center of cell so in a 2X1 plane vector is equal(0.5 , 0.5) /// now if main plane's center is in world's center we need to substract the vector with planes size / 2 /// if plane size is 1X2 cellsize will be 1X1 (look at MGrid Line 110) /// vector temp now >> ( 0.5 - 1/2 , 0.5 - 2/2 ) --> ( 0 , -0.5 ) ......>>>> so for secont tile temp will be ( 1, -0.5 ) /// now imagine main plane is NOT at center so we move all tiles x,y,z to where it is (pattern.transform.position is its center) /// and set tiles Size to cell size and make them children of the plane we are instantiating on temp = new Vector3(i * pattern.cell_Size.x + pattern.cell_Size.x / 2, j * pattern.cell_Size.y + pattern.cell_Size.y / 2, pattern.transform.position.z); temp = new Vector3(temp.x - pattern.transform.localScale.x / 2, temp.y - pattern.transform.localScale.y / 2); temp += pattern.transform.position; GameObject go = Instantiate(pattern.TilePrefab, temp, Quaternion.identity); go.transform.localScale = pattern.cell_Size; go.transform.SetParent(pattern.transform); } } } if (Level != -1) //if this is a level 1_20 need to disable pattern Not alowed t odraw on it and make it chid of path cylander for animating { pattern.enabled = false; pattern.transform.SetParent(path.transform); } }
private void LoadLevel() { if (Level != 0 && Level != -1) { SetData_level(); //first set the data LoadPattern(); //load pattern by data we just have now pad.DeleteGrid(); pad.GenerateGrid(data.size); pad.GetComponent <MGrid>().enabled = false; //pad is not intractable first record = SaveStatus.Load().record; //set record from save for best Score value } if (Level == 20) { pattHider.SetActive(true); //panel that should hide pattern } }