73 lines
1.8 KiB
C#
73 lines
1.8 KiB
C#
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<Transform>())
|
|
{
|
|
if (t.childCount > 0)
|
|
{
|
|
foreach (Transform tt in t.GetComponentInChildren<Transform>())
|
|
{
|
|
tt.gameObject.SetActive(true);
|
|
tt.GetComponent<MeshRenderer>().enabled = false;
|
|
}
|
|
|
|
t.GetChild(0).GetComponent<MeshRenderer>().enabled = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void ASDASD()
|
|
{
|
|
foreach (Transform t in inst.root.GetComponentInChildren<Transform>())
|
|
{
|
|
Debug.Log(t.name +" "+ t.childCount);
|
|
if (t.childCount > 0)
|
|
{
|
|
if (t.gameObject.GetComponent<LODGroup>())
|
|
{
|
|
DestroyImmediate(t.gameObject.GetComponent<LODGroup>());
|
|
}
|
|
|
|
//
|
|
LODGroup lodGroup = t.gameObject.AddComponent<LODGroup>();
|
|
|
|
LOD[] lods = inst.lODGroup.GetLODs();
|
|
for (int i = 0; i < lods.Length; ++i)
|
|
{
|
|
lods[i].renderers = new Renderer[] { t.GetChild(i).GetComponent<Renderer>() };
|
|
}
|
|
|
|
lodGroup.SetLODs(lods);
|
|
lodGroup.RecalculateBounds();
|
|
}
|
|
}
|
|
}
|
|
}
|