BITKit/Src/UnityPluginsSupport/AdvancedCullingSystem/OpenWorldCombiner.cs

54 lines
1.3 KiB
C#
Raw Normal View History

2024-03-31 23:31:00 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using MeshCombineStudio;
using NGS.AdvancedCullingSystem.Dynamic;
using UnityEngine;
2024-04-16 04:06:46 +08:00
using UnityEngine.Events;
2024-03-31 23:31:00 +08:00
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace BITKit.OpenWorld
{
public class OpenWorldCombiner : MonoBehaviour
{
[SerializeField] private MeshCombiner meshCombiner;
2024-04-16 04:06:46 +08:00
[SerializeField] private UnityEvent onCombiningReady;
[SerializeField]
private bool allowCullingSource = true;
2024-03-31 23:31:00 +08:00
private void Start()
{
2024-04-16 04:06:46 +08:00
meshCombiner.onCombiningReady +=x=> onCombiningReady.Invoke();
2024-03-31 23:31:00 +08:00
meshCombiner.onCombiningReady += AddCullingSource;
}
private void AddCullingSource(MeshCombiner meshcombiner)
{
2024-04-16 04:06:46 +08:00
if (allowCullingSource)
2024-04-06 16:33:32 +08:00
AddCullingSource();
2024-03-31 23:31:00 +08:00
}
[BIT]
private void AddCullingSource()
{
var reportBuilder = new System.Text.StringBuilder();
var renderers = meshCombiner.GetComponentsInChildren<MeshRenderer>(true);
reportBuilder.AppendLine($"找到{renderers.Length}个Renderer");
foreach (var x in renderers)
{
if (x.GetComponent<DC_SourceSettings>()) continue;
x.gameObject.AddComponent<DC_SourceSettings>();
reportBuilder.AppendLine($"为{x.name}添加了DC_SourceSettings");
}
Debug.Log(reportBuilder.ToString());
}
}
}