using UnityEngine; /// /// 特殊处理--针对自己组合生成的网格,对rander的lightmap信息重新设定 /// 这里有个潜规则:关联的网格名字中包含有lightmap的索引ID /// public class CombineMeshLightmap : MonoBehaviour { private void Awake() { var mf = GetComponent(); var render = GetComponent(); if (render != null) { int litIdx = 0; if (mf != null && mf.sharedMesh != null) { int idx = mf.sharedMesh.name.LastIndexOf("_"); if (idx >= 0) { int.TryParse(mf.sharedMesh.name.Substring(idx), out litIdx); } } render.lightmapIndex = litIdx < 0 ? 0 : litIdx; render.lightmapScaleOffset = new Vector4(1, 1, 0, 0); } } }