Skip to content

Instantly share code, notes, and snippets.

@igrir
Created June 17, 2020 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igrir/2730e3a700ea3aae96ce204d197ac078 to your computer and use it in GitHub Desktop.
Save igrir/2730e3a700ea3aae96ce204d197ac078 to your computer and use it in GitHub Desktop.
Disable object with <INACTIVE> string in its name
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