This commit is contained in:
2025-11-14 18:44:06 +08:00
parent 10156da245
commit 22e867d077
7013 changed files with 2572882 additions and 1804 deletions

View File

@@ -0,0 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MeshCombineStudio
{
public class DisabledLODGroup : MonoBehaviour
{
[HideInInspector] public MeshCombiner meshCombiner;
public LODGroup lodGroup;
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: ec7640472ee37d84298be8f3769ced5f
timeCreated: 1510250774
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MeshCombineStudio
{
[ExecuteInEditMode]
public class FindLodGroups : MonoBehaviour
{
public bool find;
void Start()
{
FindLods();
}
void Update()
{
if (find)
{
find = false;
FindLods();
}
}
void FindLods()
{
LODGroup[] lodGroups = GetComponentsInChildren<LODGroup>(true);
for (int i = 0; i < lodGroups.Length; i++)
{
Debug.Log(lodGroups[i].name);
}
Debug.Log("---------------------------------------------");
Debug.Log("LODGroups found " + lodGroups.Length);
Debug.Log("---------------------------------------------");
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b31f9c228d56bf043b5219a5ff58508b
timeCreated: 1508838518
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,131 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MeshCombineStudio
{
public class LODGroupSetup : MonoBehaviour {
public MeshCombiner meshCombiner;
public LODGroup lodGroup;
public int lodGroupParentIndex;
public int lodCount;
LODGroup[] lodGroups;
public void Init(MeshCombiner meshCombiner, int lodGroupParentIndex)
{
this.meshCombiner = meshCombiner;
this.lodGroupParentIndex = lodGroupParentIndex;
lodCount = lodGroupParentIndex + 1;
if (lodGroup == null) lodGroup = gameObject.AddComponent<LODGroup>();
GetSetup();
}
void GetSetup()
{
LOD[] lods = new LOD[lodGroupParentIndex + 1];
for (int i = 0; i < lods.Length; i++)
{
lods[i] = new LOD();
lods[i].screenRelativeTransitionHeight = meshCombiner.lodGroupsSettings[lodGroupParentIndex].lodSettings[i].screenRelativeTransitionHeight;
}
lodGroup.SetLODs(lods);
}
public void ApplySetup()
{
// Debug.Log("ApplySetup");
LOD[] lods = lodGroup.GetLODs();
if (lodGroups == null) lodGroups = GetComponentsInChildren<LODGroup>();
if (lods.Length != lodCount) return;
bool lodGroupsAreRemoved = false;
if (lodGroupParentIndex == 0)
{
// Debug.Log("Length " + lodGroups.Length +" " +lods[0].screenRelativeTransitionHeight);
if (lods[0].screenRelativeTransitionHeight != 0)
{
if (lodGroups == null || lodGroups.Length == 1) AddLODGroupsToChildren();
}
else
{
if (lodGroup != null && lodGroups.Length != 1) RemoveLODGroupFromChildren();
lodGroupsAreRemoved = true;
}
}
if (meshCombiner != null)
{
for (int i = 0; i < lods.Length; i++)
{
meshCombiner.lodGroupsSettings[lodGroupParentIndex].lodSettings[i].screenRelativeTransitionHeight = lods[i].screenRelativeTransitionHeight;
}
}
if (lodGroupsAreRemoved) return;
for (int i = 0; i < lodGroups.Length; i++)
{
LOD[] childLods = lodGroups[i].GetLODs();
for (int j = 0; j < childLods.Length; j++)
{
childLods[j].screenRelativeTransitionHeight = lods[j].screenRelativeTransitionHeight;
}
lodGroups[i].SetLODs(childLods);
}
if (meshCombiner != null) lodGroup.size = meshCombiner.cellSize;
}
public void AddLODGroupsToChildren()
{
// Debug.Log("Add Lod Groups");
Transform t = transform;
List<LODGroup> lodGroupList = new List<LODGroup>();
for (int i = 0; i < t.childCount; i++)
{
Transform child = t.GetChild(i);
Debug.Log(child.name);
LODGroup lodGroup = child.GetComponent<LODGroup>();
if (lodGroup == null)
{
lodGroup = child.gameObject.AddComponent<LODGroup>();
LOD[] lods = new LOD[1];
lods[0] = new LOD(0, child.GetComponentsInChildren<MeshRenderer>());
lodGroup.SetLODs(lods);
}
lodGroupList.Add(lodGroup);
}
lodGroups = lodGroupList.ToArray();
}
public void RemoveLODGroupFromChildren()
{
// Debug.Log("Remove Lod Groups");
Transform t = transform;
for (int i = 0; i < t.childCount; i++)
{
Transform child = t.GetChild(i);
LODGroup lodGroup = child.GetComponent<LODGroup>();
if (lodGroup != null) DestroyImmediate(lodGroup);
}
lodGroups = null;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 3e72c6f397f46114ca26e357c0ff7e27
timeCreated: 1510423325
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: