This commit is contained in:
CortexCore
2025-03-15 21:13:46 +08:00
parent b714f76560
commit ff7afe4133
22 changed files with 177 additions and 20 deletions

View File

@@ -1,32 +1,44 @@
#if UNITY_5_3_OR_NEWER
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using BITKit;
using UnityEngine;
using UnityEngine.Events;
namespace Net.Project.B.WorldNode
{
public class UnityEnvironmentController : MonoBehaviour
{
[SerializeField] private GameObject[] searchGameObjects;
[SerializeField] private GameObject[] staticGameObjects;
private void OnEnable()
{
if(Application.isEditor)return;
Execute();
Destroy(this);
}
[SerializeField] private UnityEvent onCompleted;
private void Start()
{
Execute();
onCompleted?.Invoke();
Destroy(this);
}
[ContextMenu("Build Index")]
public void Rebuild()
{
staticGameObjects = GetComponentsInChildren<Transform>().Where(x=>x.gameObject.isStatic).Select(x=>x.gameObject).ToArray();
if (searchGameObjects is { Length: > 0 })
{
var hashSet = new HashSet<Transform>();
foreach (var searchGameObject in searchGameObjects)
{
if (!searchGameObject) continue;
hashSet.UnionWith(searchGameObject.GetComponentsInChildren<Transform>());
}
staticGameObjects = hashSet.Select(x => x.gameObject).ToArray();
}
else
{
staticGameObjects = GetComponentsInChildren<Transform>().Where(x=>x.gameObject.isStatic).Select(x=>x.gameObject).ToArray();
}
Debug.Log($"已获取到{staticGameObjects.Length}个物体");
}
@@ -49,3 +61,4 @@ namespace Net.Project.B.WorldNode
}
#endif