Skip to content

Instantly share code, notes, and snippets.

@miguel12345
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save miguel12345/4445ef7caf807c38cad3 to your computer and use it in GitHub Desktop.

Select an option

Save miguel12345/4445ef7caf807c38cad3 to your computer and use it in GitHub Desktop.
A Proper ExclusiveChildren script for Unity Editor
using UnityEngine;
using System.Collections;
#if UNITY_EDITOR
using UnityEditor;
#endif
//See http://g.recordit.co/sYme8QQg2L.gif for an example of usage
public class ExclusiveChildren : MonoBehaviour {
#if UNITY_EDITOR
void OnDrawGizmos() {
if (EditorApplication.isPlaying)
return;
if (Selection.activeGameObject == null)
return;
if (Selection.activeGameObject == gameObject)
return;
if (! Selection.activeGameObject.transform.IsChildOf (transform))
return;
DeactivateAllChildrenNotParentOf (Selection.activeGameObject.transform);
}
void DeactivateAllChildrenNotParentOf(Transform transform) {
int childCount = this.transform.childCount;
for(int i = 0; i < childCount; i ++) {
Transform childTransform = this.transform.GetChild (i);
childTransform.gameObject.SetActive (transform.IsChildOf(childTransform));
}
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment