using UnityEngine; using UnityEngine.UI; using static UIconfig; public class SetButtonColours_default : MonoBehaviour { void Start() { RecursivelySetAllButtonsOfMenuToDefaultColors(gameObject); } /// <summary> /// Recursively go through all button components of GameObjects including and below @gameObject. /// Set their colors to the default values, defined in UIconfig. /// </summary> public static void RecursivelySetAllButtonsOfMenuToDefaultColors(GameObject gameObject) { // first check, wether the object has a button component Button button = gameObject.GetComponent<Button>(); if (button != null) { ColorBlock tempColB = button.colors; tempColB.pressedColor = colPressed; tempColB.selectedColor = colSelect; tempColB.highlightedColor = bttnColHighlightet; tempColB.normalColor = bttnColNormal; button.colors = tempColB; } // now recursively call for all children for (int i = 0; i < gameObject.transform.childCount; i++) { RecursivelySetAllButtonsOfMenuToDefaultColors(gameObject.transform.GetChild(i).gameObject); } } }