private GameObject spawnAndPopulateTile(CubeCoord pos) { var go = spawnTile(pos); _populator.Populate(pos, go); return(go); }
public List <GameObject> GetNeighborTiles(CubeCoord coord) { return(CubeCoord.Neighbors .Select(c => c + coord) .Where(_knownTiles.ContainsKey) .Select(c => _knownTiles[c]) .ToList()); }
public static IEnumerator <CubeCoord> ShuffledRings(CubeCoord center, int startRing = 0, int maxRings = -1) { for (var i = 0; i < maxRings || maxRings == -1; ++i) { foreach (var coord in Ring(center, startRing + i).ToList().Shuffled()) { yield return(coord); } } }
public void Populate(CubeCoord coord, GameObject tileObject) { var techTree = Global.FindTechTree(); var structure = Util.chooseWeighted(_weights, techTree.Structures); var tileScript = tileObject.GetComponent <TileScript>(); tileScript.Init(coord, techTree); tileScript.AssignStructure(structure); }
public static IEnumerator <CubeCoord> Spiral(CubeCoord center, int startRing = 0, int maxRings = -1) { for (var i = 0; i < maxRings || maxRings == -1; ++i) { var coords = Ring(center, startRing + i); while (coords.MoveNext()) { yield return(coords.Current); } } }
void Start() { _renderer = TilePrefab.GetComponentInChildren <MeshRenderer>(); _populator = GetComponent <TilePopulator>(); spawnOrigin(); var spiralCoords = CubeCoord.ShuffledRings(CubeCoord.ORIGIN, 1, initialRings); enqueue(() => SpawnAll(spiralCoords, 0.5f, 0.1f)); //StartCoroutine(SpawnAll(CubeCoord.Spiral(CubeCoord.ORIGIN, 1).Take(40), 0.5f, 0.1f)); //StartCoroutine(SpawnAll(CubeCoord.Ring(CubeCoord.ORIGIN, 2), 0.1f, 2f)); //StartCoroutine(SpawnEdgeTiles()); }
private GameObject spawnTile(CubeCoord pos) { var objectScale = TilePrefab.transform.localScale; var tileSize = _renderer.bounds.size; tileSize.Scale(objectScale); var instance = Instantiate(TilePrefab, transform, true); instance.name = $"{pos}"; var worldPos = pos.ToWorld(0, tileSize); instance.transform.position = worldPos; _knownTiles[pos] = instance; return(instance); }
public static IEnumerator <CubeCoord> Ring(CubeCoord center, int radius) { if (radius == 0) { yield return(center); } else { var cube = (center + (WEST * radius)); foreach (var direction in Neighbors) { for (var i = 0; i < radius; ++i) { yield return(cube); cube += direction; } } } }
public void SpawnNewAroundAsync(CubeCoord coord) { var enumerator = CubeCoord.ShuffledRings(coord, 1, 3).WhereNot(_knownTiles.ContainsKey); enqueue(() => SpawnAll(enumerator, 0f, 0.2f)); }
public double Distance(CubeCoord b) => (this - b).Length;