/// <summary> /// Swaps the current Tile Theme to whichever theme you give it. Warning: This will change the Tile's Sprites. /// </summary> /// <param name="theme">The Tile Theme you wish to activate.</param> public virtual IEnumerator HotSwapTileThemeEnumerable(GridAssetTheme.Theme theme) { //keeping these var declarations out of the loop since //there's no need for them to be re-created every loop //that's excessive allocation when they'll get cleaned //post-this function finishing execution GridAssetTheme gat; int posOnGridRaw; Sprite tileSprite; SpriteRenderer r; foreach (Tile t in TileGrid) { gat = Container.AssignedGridAssets.Themes[(int)theme]; posOnGridRaw = t.TilePositionOnGrid.GetUnshiftedNumber() - 1; tileSprite = gat.Sprites[posOnGridRaw]; t.spriteRenderer.sprite = tileSprite; if (t.transform.childCount > 0) { for (int i = 0; i < t.transform.childCount; ++i) { if (t.transform.GetChild(i).name.Contains("Decoration")) { r = t.transform.GetChild(i).GetComponent <SpriteRenderer>(); r.sprite = Container.AssignedGridAssets.Themes[(int)theme].TileDecorations[0].Sprite; } } } yield return(new WaitForSeconds(0.01f)); } }
private void RunMapGeneratorInEditor() { ClearGrid(); //update the last theme to be the current selected one in the inspector window lastGridTheme = generator.MapTheme; //let's assign some logging n all that pAction.ActionFailed += () => { Debug.Log(pAction.ErrorMessage); }; pAction.ActionSucceeded += () => { Debug.Log("<color=blue><b>Grid successfully generated!</b></color>"); }; //and now, lastly, let's call the generation of the map! pAction.Call(() => { generator.Generate(); }); }
/// <summary> /// Swaps the current Tile Theme to whichever theme you give it. Warning: This will change the Tile's Sprites. /// </summary> /// <param name="theme">The Tile Theme you wish to activate.</param> public virtual void HotSwapTileTheme(GridAssetTheme.Theme theme) { foreach (Tile t in TileGrid) { t.spriteRenderer.sprite = Container.AssignedGridAssets.Themes[(int)theme].Sprites[t.TilePositionOnGrid.GetUnshiftedNumber()]; if (t.transform.childCount > 0) { for (int i = 0; i < t.transform.childCount; ++i) { if (t.transform.GetChild(i).name.Contains("Decoration")) { SpriteRenderer r = t.transform.GetChild(i).GetComponent <SpriteRenderer>(); r.sprite = Container.AssignedGridAssets.Themes[(int)theme].TileDecorations[0].Sprite; } } } } }