Created
January 16, 2023 08:22
-
-
Save dimmduh/c5fddd1db46d015929e85fd99b135390 to your computer and use it in GitHub Desktop.
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
[MenuItem(z_EditorPrefs.ContextMenuInHierarchyCommonPath + "/Fix Before export FBX", false)] | |
public static void FixBeforeExportFbx() | |
{ | |
if (!Selection.activeGameObject) | |
{ | |
return; | |
} | |
foreach (var gameObject in Selection.gameObjects) | |
{ | |
gameObject | |
.GetComponentsInChildren<SkinnedMeshRenderer>() | |
.ForEach(renderer => | |
{ | |
if (renderer != null) | |
Object.DestroyImmediate(renderer); | |
}); | |
} | |
foreach (var gameObject in Selection.gameObjects) | |
{ | |
gameObject | |
.GetComponentsInChildren<LODGroup>(true) | |
.ForEach(group => | |
{ | |
Debug.Log($"Go to {group.gameObject.name}", group.gameObject); | |
var lods = group.GetLODs().ToList(); | |
var newLods = new List<LOD>(lods.Count); | |
lods.ForEach(lod => | |
{ | |
var was = lod.renderers.Length; | |
lod.renderers = lod.renderers.WhereNotNull().ToArray(); | |
newLods.Add(lod); | |
var now = lod.renderers.Length; | |
if (was != now) | |
Debug.Log("Null lod renderer", group.gameObject); | |
}); | |
group.SetLODs(newLods.ToArray()); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment