public virtual void SetUpTile(Grid grid, Axial position, Transform root) { var copy = Instantiate <GameObject>(gameObject); copy.transform.SetParent(root); copy.transform.localPosition = Vector3.zero; }
public Tile this[Axial axial] { get { return((Tile)tiles[axial.q][axial.r]); } set { SetTile(axial, value); } }
public virtual void RemoveTile(Grid grid, Axial position, Transform root) { // By default just remove all children from the root for (int i = 0; i < root.childCount; ++i) { Destroy(root.GetChild(i).gameObject); } }
public override void InfluenceUpdated(Grid grid, Axial position) { var renderers = grid.tileRoots[position.q][position.r].GetComponentsInChildren <MeshRenderer>(); foreach (var renderer in renderers) { renderer.material = grid.TEMPplayerInfluence[position.q][position.r] > 0 ? positive : negative; } }
public Axial[] GetNeighbours() { Axial[] neighbours = new Axial[Neighbours.Length]; Array.Copy(Neighbours, neighbours, neighbours.Length); for (int i = 0; i < neighbours.Length; ++i) { neighbours[i] += this; } return(neighbours); }
void SetTile(Axial pos, Tile tile) { // TODO: Check bounds var currentType = tiles[pos.q][pos.r]; tileTypes[currentType].RemoveTile(this, pos, tileRoots[pos.q][pos.r]); var newID = (int)tile; tiles[pos.q][pos.r] = newID; tileTypes[newID].SetUpTile(this, pos, tileRoots[pos.q][pos.r]); }
public bool Raycast(Ray ray, out Axial position) { Plane horizontalPlane = new Plane(Vector3.up, transform.position); float distance = 0.0f; if (horizontalPlane.Raycast(ray, out distance)) { Vector3 hitWorldPosition = ray.origin + ray.direction * distance; Vector3 hitLocalPosition = transform.InverseTransformPoint(hitWorldPosition); float q = (Mathf.Sqrt(3.0f) / 3.0f * hitLocalPosition.x - 1.0f / 3.0f * hitLocalPosition.z) / HexSize; float r = (2.0f / 3.0f * hitLocalPosition.z) / HexSize; position = Axial.Round(q, r); return(IsWithinBounds(position)); } position = new Axial(); return(false); }
public override void RemoveTile(Grid grid, Axial position, Transform root) { base.RemoveTile(grid, position, root); Queue <Axial> toVisit = new Queue <Axial>(); foreach (Axial neighbour in position.GetNeighbours()) { toVisit.Enqueue(neighbour); } HashSet <Axial> visited = new HashSet <Axial>(); while (toVisit.Count > 0) { Axial neighbour = toVisit.Dequeue(); if (visited.Contains(neighbour)) { continue; } visited.Add(neighbour); if (grid.IsWithinBounds(neighbour)) { grid.TEMPAddInfluence(neighbour, -Mathf.FloorToInt(centerInfluence * (1.0f - Axial.Distance(neighbour, position) / (float)radius))); } foreach (Axial next in neighbour.GetNeighbours()) { if (Axial.Distance(next, position) < radius) { toVisit.Enqueue(next); } } } }
public static Axial operator /(Axial lhs, float scalar) { return(Axial.Round(lhs.q / scalar, lhs.r / scalar)); }
public static Axial operator *(float scalar, Axial rhs) { return(Axial.Round(rhs.q * scalar, rhs.r * scalar)); }
public override bool CanBePlaced(Grid grid, Axial position) { return(grid.TEMPplayerInfluence[position.q][position.r] > 0); }
public bool IsWithinBounds(Axial position) { return(position.q >= 0 && position.q < width && position.r >= 0 && position.r < height); }
public TileComponent GetTileComponentAt(Axial axial) { var tileComponent = tileTypes[tiles[axial.q][axial.r]]; return(tileComponent); }
public virtual bool CanBePlaced(Grid grid, Axial position) { return(true); }
public virtual void InfluenceUpdated(Grid grid, Axial position) { }