using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; [CustomEditor(typeof(SetLodGroup))] public class SetLodGroupEditor : Editor { SetLodGroup inst; private void OnEnable() { inst = (SetLodGroup)target; } public override void OnInspectorGUI() { base.OnInspectorGUI(); // if(GUILayout.Button("SetLodGroup", GUILayout.Height(50))) { ASDASD(); } } void asdasdasda() { foreach (Transform t in inst.root.GetComponentInChildren()) { if (t.childCount > 0) { foreach (Transform tt in t.GetComponentInChildren()) { tt.gameObject.SetActive(true); tt.GetComponent().enabled = false; } t.GetChild(0).GetComponent().enabled = true; } } } void ASDASD() { foreach (Transform t in inst.root.GetComponentInChildren()) { Debug.Log(t.name +" "+ t.childCount); if (t.childCount > 0) { if (t.gameObject.GetComponent()) { DestroyImmediate(t.gameObject.GetComponent()); } // LODGroup lodGroup = t.gameObject.AddComponent(); LOD[] lods = inst.lODGroup.GetLODs(); for (int i = 0; i < lods.Length; ++i) { lods[i].renderers = new Renderer[] { t.GetChild(i).GetComponent() }; } lodGroup.SetLODs(lods); lodGroup.RecalculateBounds(); } } } }