using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OnOffGroup : MonoBehaviour {
	public bool atLeastOneUnabled = true;
	List<OnOffButton> buttons = new List<OnOffButton>();

	public void addButton(OnOffButton button) {
		buttons.Add(button);
	}

	public void updateStates(OnOffButton caller) {
		bool atLeastOne = false;
		foreach(OnOffButton button in buttons) {
			if (button.state && button != caller) {
				button.setState(false);
			}

			if (button.state) {
				atLeastOne = true;
			}

			if (button.tab != null) {
				button.tab.SetActive(button.state);
			}
		}

		if (!atLeastOne && atLeastOneUnabled) {
			caller.setState(true);

			if (caller.tab != null) {
				caller.tab.SetActive(true);
			}
		}
	}
}
