Skip to content

Instantly share code, notes, and snippets.

@naruse naruse/LODFixer.cs
Created Apr 9, 2017

What would you like to do?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
public class LODFixer {
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("["+groupNR+"].renderers").arraySize;i++){
SerializedProperty prop = (SerializedProperty)obj.FindProperty("["+groupNR+"].renderers").GetArrayElementAtIndex(i);
SerializedProperty propRenderer = prop.FindPropertyRelative("renderer");
Renderer ren = propRenderer.objectReferenceValue as System.Object as Renderer;
string targetName =".ODCObj";
Transform target = ren.transform.parent.FindChild(targetName);
Debug.LogWarning("No coversion found for "+targetName+ " has "+ren.sharedMaterial.shader);
newRens.Add (ren);
Debug.LogError("Renderer disabled: ";
newRens.Add (target.GetComponent<Renderer>());
Debug.LogError("Renderer disabled: "+target.GetComponent<Renderer>().name);
Debug.LogError("Renderer ENAbled but not added to LOD! ";
Debug.Log (" ["+groupNR+"] - ";
SerializedProperty screenHei = obj.FindProperty("["+groupNR+"].screenRelativeHeight");
newLods[groupNR] = new LOD(screenHei.floatValue, newRens.ToArray() );
Debug.Log ("Setting: ";
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.