Skip to content

Instantly share code, notes, and snippets.

@Agoxandr
Created Jul 19, 2021
Embed
What would you like to do?
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