public NotesMovingGrid GenerateNotes(List <uint> _grid, bool autolaunch = true) { // load prefab "Note" GameObject prefabNote = Resources.Load("prefabs/Note") as GameObject; GameObject prefabBonus = Resources.Load("prefabs/BonusNote") as GameObject; // NotesMovingGrid grid = GetFreeGrid(); for (int index = 0; index < _grid.Count; index++) { uint type = _grid [index]; //nothing to place if (type == 0) { continue; } int i = index / NB_COLUMNS; int j = index % NB_COLUMNS; float x = (j * CELL_WIDTH + CELL_WIDTH * 0.5f) * 0.01f; float y = (i * CELL_HEIGHT + CELL_HEIGHT * 0.5f) * 0.01f; Note note = null; if (type == 1) { note = grid.GetUnactiveNote(); if (note == null) { note = Instantiate(prefabNote).GetComponent <Note> (); grid.AddNote(note); } } else { note = grid.GetUnactiveBonus(); if (note == null) { note = Instantiate(prefabBonus).GetComponent <BonusNote> (); grid.AddNote(note); } } Utils.SetLocalPositionXY(note.transform, x, y); note.SetActive(true); } if (autolaunch) { LaunchGrid(grid); } return(grid); }
public NotesMovingGrid GetBottomGrid() { float bestY = float.MaxValue; NotesMovingGrid bestGrid = null; foreach (var grid in m_grids) { if (grid.IsAlive && bestY > grid.transform.localPosition.y) { bestGrid = grid; bestY = grid.transform.localPosition.y; } } return(bestGrid); }
public void LaunchGrid(NotesMovingGrid _grid) { float startY = 0; var topGrid = GetTopGrid(); if (topGrid != null && topGrid != _grid) { startY = topGrid.transform.localPosition.y + 4.8f; //startY = topGrid.TopNote.transform.position.y - transform.localPosition.y + (CELL_HEIGHT * NB_LINES * 0.01f);// + (CELL_HEIGHT * 2 * 0.01f); //startY = topGrid.transform.localPosition.y + topGrid.Height * 0.5f + _grid.Height * 0.5f + (CELL_HEIGHT * 2 * 0.01f); //Debug.Log("added " + _grid.name + " at " + startY + " | top is : " + topGrid.name + " at " + topGrid.transform.localPosition.y); //Debug.Log(_grid.name +" half height " + (_grid.Height *0.5f) + " | " + topGrid.name + " half height : " + (topGrid.Height/2.0f)); } _grid.Launch(m_gridSpeed, startY); //Debug.Log(_grid.name + " "+ _grid.transform.localPosition.y); //_grid.transform.localPosition.y = startY; m_lastLaunchedGrid = _grid; }