我们创建了 Fontainebleau 演示来说明摄影photogrammetry流程和 LayeredLit 着色器的使用。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

68 行
1.8 KiB

using UnityEngine;
[ExecuteInEditMode]
public class LightmappedLOD : MonoBehaviour {
private MeshRenderer currentRenderer;
private void Awake()
{
currentRenderer = gameObject.GetComponent<MeshRenderer>();
RendererInfoTransfer();
}
#if UNITY_EDITOR
void OnBecameVisible()
{
if(!Application.isPlaying)
RendererInfoTransfer();
}
#endif
void RendererInfoTransfer()
{
if (GetComponentInParent<LODGroup>() == null)
return;
var lods = GetComponentInParent<LODGroup>().GetLODs();
int currentRendererLodIndex = -1;
if(currentRenderer == null)
{
return;
}
for (int i = 0; i < lods.Length; i++)
{
for (int j = 0; j < lods[i].renderers.Length; j++)
{
if (currentRenderer == lods[i].renderers[j])
currentRendererLodIndex = i;
}
}
if (currentRendererLodIndex == -1)
{
Debug.Log("Lightmapped LOD : lod index not found on " + gameObject.name);
return;
}
var renderers = lods[currentRendererLodIndex].renderers;
for (int i = 0; i < renderers.Length; i++)
{
if (renderers[i] != null)
{
try
{
renderers[i].lightProbeUsage = lods[0].renderers[i].lightProbeUsage;
renderers[i].lightmapIndex = lods[0].renderers[i].lightmapIndex;
renderers[i].lightmapScaleOffset = lods[0].renderers[i].lightmapScaleOffset;
}
catch
{
if(Debug.isDebugBuild)
Debug.Log("Lightmapped LOD : Error setting lightmap settings on " + gameObject.name);
}
}
}
}
}