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

71 行
2.0 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class LightmappedLOD : MonoBehaviour {
//public int LODIndex = 1;
private MeshRenderer currentRenderer;
// Use this for initialization
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 = UnityEngine.Rendering.LightProbeUsage.Off;
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);
}
}
}
}
}