// Use this for initialization void Start() { float xSize = GetComponent <Renderer>().bounds.size.x;; Camera.main.orthographicSize = xSize * Screen.height / Screen.width * 0.5f; InitChessBoard(); int[,] mInitValue = ChessBoard.GameBoardOrigin; float unit = xSize / 9f; float xStart = -4f * unit; float yStart = -4.5f * unit; for (int i = 0; i < 9; i++) { for (int j = 0; j < 10; j++) { XY newPoint = new XY { mX = i, mY = j, mXWorld = xStart + unit * i, mYWorld = yStart + unit * j }; XYValues.Add(newPoint); } } for (int i = 0; i < mInitValue.GetLength(0); i++) { for (int j = 0; j < mInitValue.GetLength(1); j++) { int index = i * 10 + j; XY point = (XY)XYValues[index]; if (mInitValue[i, j] != Chess.EMPTY) { Transform newChess = Instantiate(chess, new Vector3(point.mXWorld, point.mYWorld, -1), Quaternion.identity); ChessController controller = newChess.GetComponent <ChessController>(); controller.SetValue(mInitValue[i, j], i, j); controller.SetOnShowPosCanMoveListener(this); if (mInitValue[i, j] == Chess.VUA_1) { KingRed = controller.GetChess(); } if (mInitValue[i, j] == Chess.VUA_2) { KingBlue = controller.GetChess(); } AllChessList.Add(controller); } } } }