2025-02-24 23:02:49 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using BITKit;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace Net.Project.B.WorldNode
|
|
|
|
{
|
|
|
|
public class UnityEnvironmentController : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField] private GameObject[] staticGameObjects;
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
{
|
|
|
|
if(Application.isEditor)return;
|
2025-03-03 18:43:55 +08:00
|
|
|
Execute();
|
2025-02-24 23:02:49 +08:00
|
|
|
Destroy(this);
|
|
|
|
}
|
|
|
|
private void Start()
|
|
|
|
{
|
2025-03-03 18:43:55 +08:00
|
|
|
Execute();
|
|
|
|
Destroy(this);
|
2025-02-24 23:02:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[ContextMenu("Build Index")]
|
|
|
|
public void Rebuild()
|
|
|
|
{
|
|
|
|
staticGameObjects = GetComponentsInChildren<Transform>().Where(x=>x.gameObject.isStatic).Select(x=>x.gameObject).ToArray();
|
|
|
|
Debug.Log($"已获取到{staticGameObjects.Length}个物体");
|
|
|
|
}
|
2025-03-03 18:43:55 +08:00
|
|
|
|
|
|
|
private void Execute()
|
|
|
|
{
|
|
|
|
var lost = 0;
|
|
|
|
foreach (var staticGameObject in staticGameObjects)
|
|
|
|
{
|
|
|
|
if (staticGameObject)
|
|
|
|
{
|
|
|
|
staticGameObject.isStatic = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
lost++;
|
|
|
|
}
|
|
|
|
Debug.Log($"已设置{staticGameObjects.Length}个物体为isStatic,丢失了:{lost}个");
|
|
|
|
}
|
2025-02-24 23:02:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|