1
This commit is contained in:
@@ -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
|
Reference in New Issue
Block a user