using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor;

[ExecuteInEditMode]
public class HideChildGameObjects : MonoBehaviour {

	//[HideInInspector]
	public bool hidden = true;

	//[HideInInspector]
	public List<Transform> objectsToHide;

	void Start () {
		hidden = true;
		HideYoKids ();
	}

	void OnValidate () {
		//hidden = true;
		HideYoKids ();
	}

	void HideYoKids () {
		/*
		if (objectsToHide.Count > 0) {
			if (hidden && SceneManager.GetActiveScene().name != "Launcher" && SceneManager.GetActiveScene().name != "GameIsland" && SceneManager.GetActiveScene().name != "Esports Launcher")
				for (int i = 0; i < objectsToHide.Count; i++)
					objectsToHide[i].hideFlags = HideFlags.None;
			else
				for (int i = 0; i < objectsToHide.Count; i++)
					objectsToHide[i].hideFlags = HideFlags.None;

			//EditorApplication.RepaintHierarchyWindow ();
			//EditorApplication.DirtyHierarchyWindowSorting ();
		}
		*/

		// Old Code
		//return;
		if (hidden && SceneManager.GetActiveScene ().name != "Launcher" && SceneManager.GetActiveScene ().name != "GameIsland" && SceneManager.GetActiveScene ().name != "Esports Launcher") {
			if (transform.tag != "LootChest")
			{
				transform.hideFlags = HideFlags.HideInHierarchy;
			}
			for (int i = 0; i < transform.childCount; i++) {
				transform.GetChild (i).hideFlags = HideFlags.HideInHierarchy;
			}
		} else {
			transform.hideFlags = HideFlags.None;
			for (int i = 0; i < transform.childCount; i++) {
				transform.GetChild (i).hideFlags = HideFlags.None;
			}
		}
		
	}
}
