public void SetBallMode(BallFactory.BallMode mode) { m_Mode = mode; Vector3 par = Vector3.one; if (m_Mode == BallFactory.BallMode.Scale) { par.x = 0.5f; par.y = 0.5f; m_Renderer.sortingOrder = 0; } else if (m_Mode == BallFactory.BallMode.Normal) { par.x = 1; par.y = 1; m_Renderer.sortingOrder = 1; } SetScale(par); }
public void GenerateRandomBalls(bool firstTime = false) { if (firstTime) { if (m_ShowingBalls.Count == 0) { int temp = 0; Vector3 pos = Vector3.zero; pos.x = 0 - Constant.TILE_UNIT * 2; pos.y = Constant.BOARD_START_Y + Constant.TILE_UNIT + 1; while (temp < 3) { Ball showingBall = m_BallFactory.GenerateRandomBall(BallFactory.BallMode.Normal); pos.x += Constant.TILE_UNIT; showingBall.SetBallPosition(pos); showingBall.SetBallActive(false); m_ShowingBalls.Add(showingBall); temp++; } } } int count = 0; int total = 0; if (m_TotalBalls + m_Quota <= Constant.BOARD_COLUMN * Constant.BOARD_ROW) { total = m_Quota; m_TotalBalls += m_Quota; } else { // total = Constant.BOARD_ROW * Constant.BOARD_COLUMN - m_TotalBalls; // m_TotalBalls = Constant.BOARD_COLUMN * Constant.BOARD_ROW; // BoradcastBoardEvent(GameCommand.BOARD_STOP_RECEIVE_INPUT); m_GameOver = true; BoradcastBoardEvent(GameCommand.BOARD_GAME_OVER); return; } while (count < total) { int i = Random.Range(0, Constant.BOARD_ROW); int j = Random.Range(0, Constant.BOARD_COLUMN); BallFactory.BallMode mode = BallFactory.BallMode.Scale; if (firstTime) { mode = BallFactory.BallMode.Normal; } Ball ball = m_Tiles[i, j].GetBall(); if (ball == null) { ball = m_BallFactory.GenerateRandomBall(mode); ball.SetBallPosition(m_Tiles[i, j].GetPosition()); m_Tiles[i, j].SetBall(ball); m_RandomBalls.Add(ball); // count++; if (!firstTime) { m_ShowingBalls[count].SetBallType(ball.GetBallType()); m_ShowingBalls[count].LoadSprite(m_BallFactory.GetBallSprite(ball.GetBallType())); if (!m_ShowingBalls[count].IsObjectActive()) { m_ShowingBalls[count].SetBallActive(true); } } count++; } } }