update CCK to 3.10, fixing unity 2021 crash :)
This commit is contained in:
parent
48a978fa2a
commit
d11e0fb3a9
492 changed files with 2165204 additions and 437687 deletions
|
@ -17,61 +17,68 @@ namespace ABI.CCK.Scripts.Editor
|
|||
{
|
||||
public class CCK_Tools
|
||||
{
|
||||
|
||||
public enum SearchType
|
||||
{
|
||||
Scene = 1,
|
||||
Selection = 2
|
||||
}
|
||||
|
||||
public static int CleanMissingScripts (SearchType searchType, bool remove, GameObject givenObject)
|
||||
public static int CleanMissingScripts(SearchType searchType, bool shouldRemove, GameObject givenObject)
|
||||
{
|
||||
List<GameObject> allFoundObjects = new List<GameObject>();
|
||||
GameObject[] rootObjects;
|
||||
Scene activeScene = SceneManager.GetActiveScene();
|
||||
GameObject[] rootObjects = (searchType == SearchType.Scene)
|
||||
? activeScene.GetRootGameObjects()
|
||||
: new GameObject[] { givenObject };
|
||||
|
||||
if (searchType == SearchType.Scene)
|
||||
{
|
||||
rootObjects = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();
|
||||
}
|
||||
else
|
||||
{
|
||||
rootObjects = new GameObject[1];
|
||||
rootObjects[0] = givenObject;
|
||||
}
|
||||
|
||||
foreach (var item in rootObjects)
|
||||
{
|
||||
allFoundObjects.AddRange(item.GetComponentsInChildren<Transform>(true).Select(go => go.gameObject).ToArray());
|
||||
}
|
||||
List<GameObject> allFoundObjects = rootObjects
|
||||
.SelectMany(root => root.GetComponentsInChildren<Transform>(true))
|
||||
.Select(t => t.gameObject)
|
||||
.ToList();
|
||||
|
||||
int scriptCount = 0;
|
||||
int goCount = 0;
|
||||
|
||||
foreach (var go in allFoundObjects)
|
||||
{
|
||||
int count = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(go);
|
||||
if (count > 0)
|
||||
if (count <= 0) continue;
|
||||
|
||||
if (shouldRemove)
|
||||
{
|
||||
if (remove)
|
||||
Undo.RegisterCompleteObjectUndo(go, "Remove missing scripts");
|
||||
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go);
|
||||
if (PrefabUtility.IsPartOfAnyPrefab(go))
|
||||
{
|
||||
Undo.RegisterCompleteObjectUndo(go, "Remove missing scripts");
|
||||
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go);
|
||||
GameObject prefabInstance = PrefabUtility.GetNearestPrefabInstanceRoot(go);
|
||||
if (prefabInstance != null)
|
||||
PrefabUtility.ApplyPrefabInstance(prefabInstance, InteractionMode.AutomatedAction);
|
||||
}
|
||||
scriptCount += count;
|
||||
goCount++;
|
||||
}
|
||||
|
||||
scriptCount += count;
|
||||
goCount++;
|
||||
}
|
||||
|
||||
if (remove)
|
||||
if (shouldRemove)
|
||||
{
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
|
||||
EditorSceneManager.MarkSceneDirty(activeScene);
|
||||
EditorSceneManager.SaveScene(activeScene);
|
||||
Debug.Log($"[CCK:Tools] Found and removed {scriptCount} missing scripts from {goCount} GameObjects");
|
||||
}
|
||||
|
||||
if (remove) Debug.Log($"[CCK:Tools] Found and removed {scriptCount} missing scripts from {goCount} GameObjects");
|
||||
|
||||
return scriptCount;
|
||||
}
|
||||
|
||||
public static void CleanEditorOnlyGameObjects(GameObject gameObject)
|
||||
{
|
||||
var objectsToDestroy = (from child in gameObject.GetComponentsInChildren<Transform>(true)
|
||||
where child.CompareTag("EditorOnly")
|
||||
select child.gameObject).ToList();
|
||||
|
||||
for (int i = objectsToDestroy.Count - 1; i >= 0; i--)
|
||||
UnityEngine.Object.DestroyImmediate(objectsToDestroy[i]);
|
||||
}
|
||||
|
||||
[MenuItem("Assets/Create/CVR Override Controller")]
|
||||
private static void CreateCVROverrideController()
|
||||
{
|
||||
|
@ -88,6 +95,12 @@ namespace ABI.CCK.Scripts.Editor
|
|||
|
||||
AssetDatabase.CreateAsset (overrideController, path);
|
||||
}
|
||||
|
||||
|
||||
public static T FindFirstInstanceInScene<T>() where T : Component
|
||||
{
|
||||
return SceneManager.GetActiveScene().GetRootGameObjects()
|
||||
.Select(root => root.GetComponentsInChildren<T>(true).FirstOrDefault())
|
||||
.FirstOrDefault(component => component != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue