public GameField BuildGameField(int fieldSizeX, int fieldSizeY, GameObject fieldCellPrefab) { GameField gameField = new GameField(); GameFieldCell[,] gameFieldCells = new GameFieldCell[fieldSizeX, fieldSizeY]; GameObject gameFieldParent = new GameObject(); gameFieldParent.name = "GameFieldParent"; for (int i = 0; i < fieldSizeX; i++) { for (int j = 0; j < fieldSizeY; j++) { GameFieldCell gameFieldCell = new GameFieldCell(i, j); GameObject go = GameObject.Instantiate(fieldCellPrefab); go.transform.SetParent(gameFieldParent.transform); GameFieldCellComponent gameFieldCellComponent = go.GetComponent <GameFieldCellComponent>(); gameFieldCellComponent.InitConnection(gameFieldCell); gameFieldCellComponent.MoveToCurrentPosition(); gameFieldCells[i, j] = gameFieldCell; } } gameField.gameFieldCells = gameFieldCells; return(gameField); }
void Update() { UpdateUsingFigure(); RaycastHit hit; Ray ray = myCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.collider.name.Equals("FieldCellCollider")) { GameFieldCellComponent gameFieldCellComponent = hit.collider.transform.parent.GetComponent <GameFieldCellComponent>(); if (gameFieldCellComponent != null) { SetFigureOnCell(gameFieldCellComponent, usingFigureTransformVirtual); var gameFieldCellsComponentsUnderFigureVirtual = GetGameFieldUnderFigure(usingFigureCellTransformsVirtual); if (gameFieldCellsComponentsUnderFigureVirtual != null && IsFreeSpace(gameFieldCellsComponentsUnderFigureVirtual)) { SetFigureOnCell(gameFieldCellComponent, usingFigureTransform); figureSettedOnDesk = true; } if (figureSettedOnDesk && Input.GetKeyDown(KeyCode.Mouse0)) { var gameFieldCellsComponentTransforms = GetFicureCellTransforms(); var gameFieldCellsComponentsUnderFigure = GetGameFieldUnderFigure(gameFieldCellsComponentTransforms); LockGameFieldUnderFigure(gameFieldCellsComponentsUnderFigure); LoseFigure(); } } } } }
private void SetFigureOnCell(GameFieldCellComponent gameFieldCellComponent, Transform usingFigureTransform) { usingFigureTransform.position = gameFieldCellComponent.transform.position + up * 0.5f - fromFigureTohead; }