- Home /
LodGroup property access
Hi, I am trying to access some properties from lodGroup like the current lod level, however, there's no property exposed for this, anybody knows if there's some way to do this?
Thanks in advance! :)
Comment
Answer by cupsster · Mar 16, 2012 at 04:27 PM
Some pointers: http://forum.unity3d.com/threads/123610-Access-to-LODGroup-data-in-script?highlight=LODGroup
var obj = new SerializedObject(comp);
AssignGroup(0, obj, gobject);
AssignGroup(1, obj, gobject);
AssignGroup(2, obj, gobject);
obj.ApplyModifiedProperties();
}
private function AssignGroup(LODGroupID, obj, gobject)
{
var prop = obj.FindProperty("m_LODs.Array.data[" + LODGroupID + "].renderers");
prop.arraySize = 1;
prop.InsertArrayElementAtIndex(0);
var prop2 = prop.GetArrayElementAtIndex(0);
var mRenderer = null;
if (LODGroupID == 0)
{
mRenderer = gobject.GetComponent("MeshRenderer");
}
else
{
for (var tr in gobject.transform)
{
if (tr.gameObject.name == ("LOD" + LODGroupID))
mRenderer = tr.gameObject.GetComponent("MeshRenderer");
}
}
prop2.FindPropertyRelative("renderer").objectRefer enceValue = mRenderer;
}
SerializedObject requires UnityEditor
This sadly won't work for game scripts