Andre McGrail
4 年前
当前提交
928fffba
共有 25 个文件被更改,包括 404 次插入 和 403 次删除
-
34Assets/Objects/environment/Cliffs/Prefabs/Cliff_Full_01.prefab
-
34Assets/Objects/environment/Cliffs/Prefabs/Cliff_Full_02.prefab
-
34Assets/Objects/environment/Cliffs/Prefabs/Cliff_Full_03.prefab
-
34Assets/Objects/environment/Cliffs/Prefabs/Cliff_Wall_01.prefab
-
25Assets/Objects/environment/Cliffs/Prefabs/Cliff_Wall_02.prefab
-
25Assets/Objects/environment/Cliffs/Prefabs/Cliff_Wall_03.prefab
-
33Assets/Objects/environment/Cliffs/Prefabs/Hero_Cave.prefab
-
34Assets/Objects/environment/Cliffs/Prefabs/Hero_CaveEntrance.prefab
-
33Assets/Objects/environment/Cliffs/Prefabs/Hero_CaveExit.prefab
-
34Assets/Objects/environment/Cliffs/Prefabs/Hero_Mountain.prefab
-
34Assets/Objects/environment/Cliffs/Prefabs/Hero_Tower.prefab
-
34Assets/Objects/environment/Cliffs/Prefabs/Rock_Large_01.prefab
-
34Assets/Objects/environment/Cliffs/Prefabs/Rock_Large_02.prefab
-
34Assets/Objects/environment/Cliffs/Prefabs/Rock_Medium_01.prefab
-
34Assets/Objects/environment/Cliffs/Prefabs/Rock_Medium_02.prefab
-
34Assets/Objects/environment/Cliffs/Prefabs/Rock_Medium_03.prefab
-
34Assets/Objects/environment/Cliffs/Prefabs/Rock_Medium_04.prefab
-
34Assets/Objects/environment/Cliffs/Prefabs/Rock_Small_01.prefab
-
34Assets/Objects/environment/Cliffs/Prefabs/Rock_Small_02.prefab
-
34Assets/Objects/environment/Cliffs/Prefabs/Rock_Small_03.prefab
-
25Assets/Objects/environment/Cliffs/Prefabs/Rock_Small_04.prefab
-
2Assets/Scripts/Editor/LodLightmapCopy.cs.meta
-
49Assets/Scripts/Editor/LodLightmapCopy.cs
-
71Assets/Scripts/Effects/LodLightmaps.cs
-
0/Assets/Scripts/Editor/LodLightmapCopy.cs.meta
|
|||
using UnityEditor; |
|||
using UnityEditor.Build; |
|||
using UnityEditor.Build.Reporting; |
|||
using UnityEngine; |
|||
using UnityEngine.SceneManagement; |
|||
|
|||
[InitializeOnLoad] |
|||
class LodLightmapCopy : IProcessSceneWithReport |
|||
{ |
|||
public int callbackOrder => -1; |
|||
|
|||
public void OnProcessScene(Scene scene, BuildReport report) |
|||
{ |
|||
Execute(); |
|||
} |
|||
|
|||
static LodLightmapCopy() |
|||
{ |
|||
Lightmapping.bakeCompleted += Execute; |
|||
EditorApplication.playModeStateChanged += LodLightmapEdit; |
|||
} |
|||
|
|||
static void LodLightmapEdit(PlayModeStateChange state) |
|||
{ |
|||
if(state == PlayModeStateChange.EnteredEditMode) Execute(); |
|||
} |
|||
|
|||
private static void Execute() |
|||
{ |
|||
Debug.Log("Baking LOD Lightmap values"); |
|||
var lodGroups= Object.FindObjectsOfType<LODGroup>(); |
|||
foreach (var lodGroup in lodGroups) |
|||
{ |
|||
//is lod0 lightmapped
|
|||
var lods = lodGroup.GetLODs(); |
|||
var lod0 = lods[0].renderers; |
|||
//if(lod0[0].lightmapIndex == -1) return;
|
|||
//copy settings to other lods
|
|||
for (var i = 1; i < lods.Length; i++) |
|||
{ |
|||
for (var j = 0; j < lod0.Length; j++) |
|||
{ |
|||
lods[i].renderers[j].lightmapIndex = lod0[j].lightmapIndex; |
|||
lods[i].renderers[j].lightmapScaleOffset = lod0[j].lightmapScaleOffset; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
using UnityEngine; |
|||
|
|||
namespace BoatAttack |
|||
{ |
|||
/// <summary>
|
|||
/// This make lower LOD levels use the same Lightmaps/offsets as LOD0
|
|||
/// </summary>
|
|||
[RequireComponent(typeof(LODGroup)), ExecuteInEditMode] |
|||
public class LodLightmaps : MonoBehaviour |
|||
{ |
|||
private LODGroup _lodGrp; // the LOD group
|
|||
private Renderer[] _main; // LOD0 Meshes
|
|||
private Renderer[] _lod1; // LOD2 Meshes
|
|||
private Renderer[] _lod2; // LOD3 Meshes
|
|||
private Renderer[] _lod3; // LOD3 Meshes
|
|||
|
|||
private void OnEnable() |
|||
{ |
|||
CopyLightmapSettings(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loops through and copies light map index and offset from LOD0 to LOD1+2
|
|||
/// </summary>
|
|||
void CopyLightmapSettings() |
|||
{ |
|||
_lodGrp = GetComponent<LODGroup>(); |
|||
var lods = _lodGrp.GetLODs(); |
|||
_main = lods[0].renderers; |
|||
|
|||
for (var i = 1; i < lods.Length; i++) |
|||
{ |
|||
switch (i) |
|||
{ |
|||
case 1: |
|||
_lod1 = lods[i].renderers; |
|||
break; |
|||
case 2: |
|||
_lod2 = lods[i].renderers; |
|||
break; |
|||
case 3: |
|||
_lod3 = lods[i].renderers; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
var lmIndex = new int[_main.Length]; |
|||
var lmScaleOffset = new Vector4[_main.Length]; |
|||
|
|||
for (var i = 0; i < _main.Length; i++) |
|||
{ |
|||
lmIndex[i] = _main[i].lightmapIndex; |
|||
lmScaleOffset[i] = _main[i].lightmapScaleOffset; |
|||
} |
|||
|
|||
for (var i = 0; i < _main.Length; i++) |
|||
{ |
|||
#pragma warning disable
|
|||
_lod1[i].lightmapIndex = lmIndex[i]; |
|||
_lod1[i].lightmapScaleOffset = lmScaleOffset[i]; |
|||
if (!_lod2[i]) continue; |
|||
_lod2[i].lightmapIndex = lmIndex[i]; |
|||
_lod2[i].lightmapScaleOffset = lmScaleOffset[i]; |
|||
if (!_lod3[i]) continue; |
|||
_lod3[i].lightmapIndex = lmIndex[i]; |
|||
_lod3[i].lightmapScaleOffset = lmScaleOffset[i]; |
|||
#pragma warning restore
|
|||
} |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue