/*更新合批网格*/ void UpdataCombineMesh(HLODGenerate hlodGenerate) { if (!hlodGenerate.m_IsExportMesh) { return; } if (hlodGenerate.m_MeshAssetPath == "") { EditorUtility.DisplayDialog("警告", "没有选择mesh路径,请先选择路径", "是"); hlodGenerate.m_IsExportMesh = false; return; } Queue <LODVolume> queue = new Queue <LODVolume>(); queue.Enqueue(hlodGenerate.m_RootLODVolume.GetComponent <LODVolume>()); //AssetDatabase.StartAssetEditing(); while (queue.Count > 0) { LODVolume lodVolume = queue.Dequeue(); if (lodVolume.combined != null && lodVolume.combined._hlodRoot != null) { string path = AssetDatabase.GetAssetPath(lodVolume.combined._hlodRoot.GetComponent <MeshFilter>().sharedMesh); if (lodVolume.lodGroups.Count < 1)//删除多出来的资源 { if (path == "") { path = Path.Combine(hlodGenerate.m_MeshAssetPath, ExportHLODsByMesh.s_DirectoryName, lodVolume.combined._hlodRoot.name); path = Path.ChangeExtension(path, "asset"); } DestroyImmediate(lodVolume.GetComponent <LODGroup>()); DestroyImmediate(lodVolume.combined._hlodRoot); lodVolume.combined._hlodRoot = null; if (path != "") { AssetDatabase.DeleteAsset(path); } } else if (path == "")//更新资源 { //ExportHLODsByMesh.PersistHLODs(lodVolume.hlodRoot.transform, hlodGenerate.m_MeshAssetPath); ExportHLODsByMesh.PersistHLODOfFbx(lodVolume.combined._hlodRoot.transform, hlodGenerate.m_MeshAssetPath); if (!hlodGenerate.StreamUpdate.Contains(lodVolume)) { hlodGenerate.StreamUpdate.Add(lodVolume); } } EditorUtility.SetDirty(lodVolume); } foreach (LODVolume lv in lodVolume.childVolumes) { queue.Enqueue(lv); } } //AssetDatabase.StopAssetEditing(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
IEnumerator GenerateHLOD(GameObject[] gameObjects = null, Action <GameObject, GameObject> endCall = null) { m_CoroutineQueue.Enqueue(UpdateOctreeByLodGroup(gameObjects)); s_endCall = endCall; yield return(MonoBehaviourHelper.StartCoroutine(m_CoroutineQueue.Dequeue())); while (m_RootVolume == null) { yield return(null); } #if UNITY_EDITOR if (m_RootVolume && m_RootVolume.dirty) { GameObject hlods = null; if (m_CurrHLODGenerate != null)//更新 { hlods = m_CurrHLODGenerate.m_HLODS; } if (!hlods)//创建 { hlods = new GameObject("RootHLOD"); } m_CoroutineQueue.Enqueue(m_RootVolume.CheckAfterBVHUpdata(m_CurrHLODGenerate.m_BVHDivide.m_MaximunLayer)); m_CoroutineQueue.Enqueue(m_RootVolume.UpdateHLODs(m_CurrHLODGenerate.m_BVHDivide.m_MaximunLayer, hlods)); m_CoroutineQueue.Enqueue(m_RootVolume.UpdateRootVolume((List <LODVolume> backList) => { HLODCull hlodCull = m_RootVolume.GetComponent <HLODCull>(); if (!m_RootVolume.GetComponent <HLODCull>()) { hlodCull = m_RootVolume.gameObject.AddComponent <HLODCull>(); Selection.activeGameObject = hlodCull.gameObject; } hlodCull.m_BackSort = backList; EditorUtility.ClearProgressBar(); EditorUtility.SetDirty(m_RootVolume); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene()); //AutoLOD.sceneLODEnabled = false; if (s_endCall != null) { s_endCall.Invoke(m_RootVolume.gameObject, hlods.gameObject); } })); } else { EditorUtility.ClearProgressBar(); if (s_endCall != null) { s_endCall.Invoke(null, null); } } #endif while (m_CoroutineQueue.Count > 0) { yield return(MonoBehaviourHelper.StartCoroutine(m_CoroutineQueue.Dequeue())); } }