Created
June 17, 2020 03:01
-
-
Save igrir/2730e3a700ea3aae96ce204d197ac078 to your computer and use it in GitHub Desktop.
Disable object with <INACTIVE> string in its name
This file contains 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 System; | |
using System.Collections; | |
using UnityEditor; | |
using UnityEngine; | |
public class ObjectsEnDisabler { | |
[MenuItem("Window/ObjectEnDisabler #&d")] | |
private static void ObjectEnDisabler() { | |
GameObject[] gameObjects = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects(); | |
Transform lastChangedObject = null; | |
for (int itGameObjects = 0; itGameObjects < gameObjects.Length; itGameObjects++) { | |
GameObject currentGameObject = gameObjects[itGameObjects]; | |
Transform[] transforms = currentGameObject.GetComponentsInChildren<Transform>(true); | |
for (int itTransform = 0; itTransform < transforms.Length; itTransform++) { | |
var currentTransform = transforms[itTransform]; | |
if (currentTransform.name.Contains("<INACTIVE>")) { | |
currentTransform.gameObject.SetActive(false); | |
lastChangedObject = currentTransform; | |
} else if (currentTransform.name.Contains("<ACTIVE>")) { | |
currentTransform.gameObject.SetActive(true); | |
lastChangedObject = currentTransform; | |
} | |
} | |
if (currentGameObject.name.Contains("<INACTIVE>")) { | |
currentGameObject.SetActive(false); | |
} else if (currentGameObject.name.Contains("<ACTIVE>")) { | |
currentGameObject.SetActive(true); | |
} | |
} | |
EditorUtility.SetDirty(lastChangedObject); | |
Debug.Log("Objects activation traversal finished"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment