/// <summary> /// Removes the current cell /// </summary> public void RemoveCurrentCell() { if (cell) { cell.ResetAnimator(); CellPooling.StoreObject(cellGameObject); cell = null; } }
/// <summary> /// Creates a new cell in this holder of type celltype. /// If type is blocked then it's gonna disable cell by default and the returned cell will be null /// </summary> /// <param name="cellType"></param> /// <param name="animate">Whether to animate the cell or not</param> /// <returns>Return null if the cell could not be created</returns> public Cell NewCell(Cell.CellOcc cellType, bool animate = true) { if (!cell) { // We have a blocking cell, for example a hole filler if (cellType == Cell.CellOcc.BLOCKED) { Disable(); currentTemplate = new CellTemplate(); currentTemplate.cellOcc = cellType; return(null); } cellGameObject = CellPooling.GetCell(); SpriteRenderer sprR = cellGameObject.GetComponent <SpriteRenderer>(); sprR.sortingLayerName = "Signs" + cellType.ToString(); // Set sorting layer for dynamic batching sprR.color = SignResourceStorage.Instance.GetColorRelatedTo(cellType); if (Grid.cellParent != null) { cellGameObject.transform.parent = Grid.cellParent.transform; } // current cell template currentTemplate = new CellTemplate(); currentTemplate.cellOcc = cellType; // Set cell type both for animation and data storage purposes cell = cellGameObject.GetComponent <Cell>(); cell.cellType = cellType; // Animation if (animate) { cell.TriggerDraw(); } else { cell.TriggerIdle(); } // Subtract .five because the center is the pivot (because we want to rotate it to give it better look) cellGameObject.transform.position = GetRandomPosBasedOnWorldPos(); cellGameObject.transform.eulerAngles = GetRandomAngles(); } else { return(null); } return(cell); }
/// <summary> /// Removes cell at previous pos /// </summary> public void RemoveCurrentCellWithoutStoring() { CellPooling.StoreObject(cellGameObject); cell = null; }