Skip to content

Instantly share code, notes, and snippets.

@Agoxandr
Created July 19, 2021 18:29
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 Agoxandr/82836aaa480d9919f4021cafdce87c83 to your computer and use it in GitHub Desktop.
Save Agoxandr/82836aaa480d9919f4021cafdce87c83 to your computer and use it in GitHub Desktop.
Adds a LOD Group to everything you select and sets the children correctly.
using UnityEditor;
using UnityEngine;
public class LODTools
{
[MenuItem("Tools/Add LOD Group/LOD 3")]
private static void AddGroup()
{
var objects = Selection.objects;
foreach (var ob in objects)
{
var go = (GameObject)ob;
var group = go.AddComponent<LODGroup>();
var lods = new LOD[go.transform.childCount];
var transitions = new float[] { .6f, .3f, .1f, .01f };
for (int i = 0; i < lods.Length; i++)
{
lods[i] = new LOD(transitions[i], go.transform.GetChild(i).GetComponents<Renderer>());
}
group.SetLODs(lods);
Undo.AddComponent<LODGroup>(go);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment