//Public Functions public Cell.CellType GetClosestCell(Vector3 a_Pos, out int a_X, out int a_Y) { float fDist = 0f; a_X = 0; a_Y = 0; float fMinDist = float.MaxValue; Cell.CellType type = Cell.CellType.NULL; for (int i = 0; i < m_SizeX; ++i) { for (int j = 0; j < m_SizeY; ++j) { fDist = Vector3.SqrMagnitude(GetCellCenter(i, j) - a_Pos); if (fDist < fMinDist) { fMinDist = fDist; type = GetCellType(i, j); a_X = i; a_Y = j; } } } return(type); }
/// <summary> /// Parses the date (DateTime) or time (TimeSpan) value of a raw cell. If the value is numeric, but out of range of a OAdate, a numeric value will be returned instead. /// If invalid, the string representation will be returned. /// </summary> /// <param name="raw">Raw value as string</param> /// <param name="address">Address of the cell</param> /// <param name="type">Type of the value to be converted: Valid values are DATE and TIME</param> /// <returns>Cell of the type TimeSpan or the defined fall-back type</returns> private Cell GetDateTimeValue(String raw, Address address, Cell.CellType type) { double dValue; if (double.TryParse(raw, NumberStyles.Any, CultureInfo.InvariantCulture, out dValue)) { if (dValue < Utils.MIN_OADATE_VALUE || dValue > Utils.MAX_OADATE_VALUE) { return(new Cell(dValue, Cell.CellType.NUMBER, address)); // Invalid OAdate == plain number } else { switch (type) { case Cell.CellType.DATE: DateTime date = DateTime.FromOADate(dValue); return(new Cell(date, Cell.CellType.DATE, address)); case Cell.CellType.TIME: TimeSpan time = TimeSpan.FromSeconds(dValue * 86400d); return(new Cell(time, Cell.CellType.TIME, address)); default: throw new ArgumentException("The defined type is not supported to be uses as date or time"); } } } else { return(new Cell(raw, Cell.CellType.STRING, address)); } }
public CellConfig(float frequency, float displacement, Cell.CellType cellType, bool enabledDistance, NoiseConfig cfg ) : base(cfg) { Frequency = frequency; Displacement = displacement; CellType = cellType; EnableDistance = enabledDistance; }
public Sprite GetCorrespondingSprite(Cell.CellType cellType, Biome biome) { Sprite currentSprite; List <Sprite> sprites = new List <Sprite>(); switch (cellType) { case Cell.CellType.Bottom: sprites = biome.m_floorSprites; break; case Cell.CellType.Top: sprites = biome.m_ceilingSprites; break; case Cell.CellType.Left: sprites = biome.m_leftWallSprites; break; case Cell.CellType.Right: sprites = biome.m_rightWallSprites; break; case Cell.CellType.TopLeft: sprites = biome.m_topLeftWallSprites; break; case Cell.CellType.TopRight: sprites = biome.m_topRightWallSprites; break; case Cell.CellType.BottomLeft: sprites = biome.m_bottomLeftWallSprites; break; case Cell.CellType.BottomRight: sprites = biome.m_bottomRightWallSprites; break; case Cell.CellType.Middle: sprites = biome.m_filledSprites; break; default: sprites = null; break; } if (sprites == null) { return(null); } currentSprite = sprites[UnityEngine.Random.Range(0, sprites.Count)]; return(currentSprite); }
private List <Cell> GetCellsOfType(Cell.CellType type) { var cells = new List <Cell>(); foreach (var cell in m_Cells) { if (cell.Type == type) { cells.Add(cell); } } return(cells); }
// *************************************************************************** // * Private Methods * // *************************************************************************** /// <summary> /// Sets the origin cell to the next available game piece cell of the given type /// </summary> /// <remarks> /// The origin can not be changed if the piece is placed on a board. /// </remarks> /// <param name="type">Cell type</param> /// <returns>True if successful; false otherwise.</returns> private bool SetOriginToNextCellOfType(Cell.CellType type) { if (!IsPlaced) { GamePieceCell cell; for (_indexOfCellUnderTest = _indexOfCellUnderTest + 1; _indexOfCellUnderTest < _cells.Count; _indexOfCellUnderTest++) { cell = _cells[_indexOfCellUnderTest]; if (cell.Type == type) { _originCell = cell; return(true); } } } return(false); }
Cell CreateCell(int rowIndex, int columnIndex, float cellSize, Cell.CellType cellType) { Cell cell = null; if (cellPool.Count > 0) { cell = cellPool.Dequeue(); ClearCell(cell); } else { GameObject cellGameObject = GameObject.Instantiate(cellPrefab) as GameObject; cellGameObject.transform.parent = cellsContainer.transform; cellGameObject.transform.localScale = Vector3.one; cell = cellGameObject.GetComponent <Cell>(); } cell.gameObject.name = string.Format("Cell_{0}_{1}", columnIndex, rowIndex); cell.gameObject.SetActive(true); Vector3 position = Vector3.zero; position.x += columnIndex * cellSize - ((cellSize * this.column) * 0.5f) + cellSize * 0.5f; position.y += ((cellSize * this.row) * 0.5f) - rowIndex * cellSize - cellSize * 0.5f; position.z += 1; cell.transform.localPosition = position; Vector3 colliderSize = Vector3.one; BoxCollider boxCollider = cell.GetComponent <BoxCollider>(); colliderSize.x = cellSize; colliderSize.y = cellSize; boxCollider.size = colliderSize; UIButtonMessage cellMessage = cell.GetComponent <UIButtonMessage>(); cellMessage.target = this.gameObject; cellMessage.functionName = "CellOnPress"; cell.Init((int)(cellSize * 0.95f), cellType, rowIndex, columnIndex); return(cell); }
public Cell ChangeCell(int x, int y, Cell.CellType newType) { Cell cellToChange = GetCell(x, y); if (newType == Cell.CellType.NONE) // We don't store references to this type. So delete whatever was there { GameObject.Destroy(cellToChange.viz); board.Remove(cellToChange); return(new Cell(x, y, Cell.CellType.NONE)); // We are done the dirty work } cellToChange.type = newType; // Update the visuals GameObject viz = Instantiate(Resources.Load(Cell.GetResourcePath(newType), typeof(GameObject))) as GameObject; viz.transform.localScale = new Vector3(cellScale, cellScale, cellScale); viz.transform.position = CellToWorld(x, y); GameObject.Destroy(cellToChange.viz); // Destroy the old viz cellToChange.viz = viz; // Return the cell return(cellToChange); }
public void SelectCellType(Cell.CellType cellType) => ExecuteAction(() => { _model.CellOptions.CellType = cellType; View.SelectedCellType = cellType; });
private Cell GetRandomCellOType(Cell.CellType type) { var cells = GetCellsOfType(type); return(cells[Random.Range(0, cells.Count)]); }
private void SetCell(int a_X, int a_Y, Cell.CellType a_Type) { m_Cells[a_X, a_Y].ChangeType(a_Type); }
public Player(string n, Cell.CellType markType) { name = n; this.markType = markType; }