Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[MenuItem("FixLODRendeer")]
static void LODRendeer()
{
LODGroup[] lodgroups = (LODGroup[])GameObject.FindObjectsOfType(typeof(LODGroup));
//For every LOD group: get the current groups and get the renderer names..
foreach (LODGroup lodgroup in lodgroups)
{
SerializedObject obj = new SerializedObject(lodgroup);
LOD[] newLods = new LOD[lodgroup.lodCount];
//For every LOD level in this lodgroup..
for(int groupNR=0; groupNR < lodgroup.lodCount; groupNR++){
List<Renderer> newRens = new List<Renderer>();
//For every renderer in this lodgroup...
for(int i=0; i< obj.FindProperty("m_LODs.Array.data["+groupNR+"].renderers").arraySize;i++){
SerializedProperty prop = (SerializedProperty)obj.FindProperty("m_LODs.Array.data["+groupNR+"].renderers").GetArrayElementAtIndex(i);
SerializedProperty propRenderer = prop.FindPropertyRelative("renderer");
Renderer ren = propRenderer.objectReferenceValue as System.Object as Renderer;
if(ren!=null){
string targetName = ren.name+".ODCObj";
Transform target = ren.transform.parent.FindChild(targetName);
if(target==null){
Debug.LogWarning("No coversion found for "+targetName+ " has "+ren.sharedMaterial.shader);
newRens.Add (ren);
if(!ren.enabled)
Debug.LogError("Renderer disabled: "+ren.name);
}else{
newRens.Add (target.renderer);
if(!target.renderer.enabled){
Debug.LogError("Renderer disabled: "+target.renderer.name);
}
if(ren.enabled)
Debug.LogError("Renderer ENAbled but not added to LOD! "+ren.name);
}
Debug.Log (lodgroup.name+" ["+groupNR+"] - "+ren.name);
}
}
SerializedProperty screenHei = obj.FindProperty("m_LODs.Array.data["+groupNR+"].screenRelativeHeight");
newLods[groupNR] = new LOD(screenHei.floatValue, newRens.ToArray() );
}
if(newLods.Length>0){
Debug.Log ("Setting: "+lodgroup.name);
lodgroup.SetLODS(newLods);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.