Skip to content
Snippets Groups Projects
SetButtonColours_default.cs 1.22 KiB
Newer Older
  • Learn to ignore specific revisions
  • using static UIconfig;
    
    public class SetButtonColours_default : MonoBehaviour
    {
    
    
        void Start()
        {
    
    Stefan Richter's avatar
    Stefan Richter committed
            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>
    
    Stefan Richter's avatar
    Stefan Richter committed
        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++)
            {
    
    Stefan Richter's avatar
    Stefan Richter committed
                RecursivelySetAllButtonsOfMenuToDefaultColors(gameObject.transform.GetChild(i).gameObject);