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

[ExecuteAlways]
public class HideTransforms : MonoBehaviour {

	//[ReadOnly]
	public bool hideChildObjects = true;

	void OnValidate () {
		if (hideChildObjects) {
			HideChildren (transform);
		} else {
			UnhideChildren (transform);
		}
	}

	void HideChildren (Transform sourceObj) {
		foreach (Transform child in sourceObj) {
			if ((sourceObj.tag == "StartFinish" || sourceObj.tag == "TrackManager") && child.hideFlags == HideFlags.None) {
				child.hideFlags = HideFlags.HideInHierarchy;
			} else if ((child.name == "Pivot" || child.name == "Icon") && child.hideFlags == HideFlags.None) {
				child.hideFlags = HideFlags.HideInHierarchy;
			} else if((child.name != "Pivot" || child.name != "Icon") && child.childCount > 0) {
				HideChildren (child);
			}
		}
	}

	void UnhideChildren (Transform sourceObj) {
		foreach (Transform child in sourceObj) {
			if ((sourceObj.tag == "StartFinish" || sourceObj.tag == "TrackManager") && child.hideFlags == HideFlags.HideInHierarchy) {
				child.hideFlags = HideFlags.None;
			} else if ((child.name == "Pivot" || child.name == "Icon") && child.hideFlags == HideFlags.HideInHierarchy) {
				child.hideFlags = HideFlags.None;
			} else if((child.name != "Pivot" || child.name != "Icon") && child.childCount > 0) {
				UnhideChildren (child);
			}
		}
	}
}
