Last active
August 29, 2015 14:26
-
-
Save miguel12345/4445ef7caf807c38cad3 to your computer and use it in GitHub Desktop.
A Proper ExclusiveChildren script for Unity Editor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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