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

@@ -7,7 +7,9 @@
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:e527b3ce3106f974585be5134b6200e9",
"GUID:e18d548755c9bc8458ca189e16813742"
"GUID:e18d548755c9bc8458ca189e16813742",
"GUID:d8b63aba1907145bea998dd612889d6b",
"GUID:1193c2664d97cc049a6e4c486c6bce71"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -3,7 +3,6 @@ using System.Collections;
using System.Collections.Generic;
using BITKit;
using BITKit.WorldNode;
using UnityEngine;
namespace Net.Project.B.WorldNode
{

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

View File

@@ -3,7 +3,9 @@ using System.Collections;
using System.Collections.Generic;
using BITKit;
using BITKit.WorldNode;
#if UNITY_5_3_OR_NEWER
using UnityEngine;
#endif
namespace Net.Project.B.WorldNode
{

View File

@@ -2,7 +2,6 @@ using System;
using System.Collections;
using System.Collections.Generic;
using BITKit.WorldNode;
using UnityEngine;
namespace Net.Project.B.WorldNode
{

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using BITKit.WorldNode;
#if UNITY_5_3_OR_NEWER
using UnityEngine;
using UnityEngine.Experimental.GlobalIllumination;
#endif
namespace Net.Project.B.WorldNode
@@ -12,6 +13,7 @@ namespace Net.Project.B.WorldNode
public class UnitySeatNode :IWorldNode
{
public int Id { get; set; }
public bool hidePlayer;
#if UNITY_5_3_OR_NEWER
public float cameraDistance= 2;
public Rigidbody Rigidbody;
@@ -20,6 +22,7 @@ namespace Net.Project.B.WorldNode
public Transform ExitObject;
public float CameraDistance => cameraDistance;
public bool HidePlayer => hidePlayer;
#endif
}
}

View File

@@ -0,0 +1,85 @@
using System;
using System.Collections;
using System.Collections.Generic;
using BITKit;
using MemoryPack;
using Net.BITKit.Quadtree;
using Unity.Mathematics;
#if UNITY_EDITOR
using UnityEditor;
#endif
#if UNITY_5_3_OR_NEWER
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Net.Project.B.WorldNode
{
public class UnityVegetationNode : MonoBehaviour
{
[SerializeField] private float3[] positions;
[SerializeField] private float2 sizeFactor;
[SerializeField] private GameObject searchPrefab;
private Mesh _mesh;
private Mesh[] _subMeshes;
private Material[] _materials;
private List<Matrix4x4> _matrix4;
private readonly Quadtree _quadtree=new(default,new float2(2048,2048));
private void Start()
{
_mesh = searchPrefab.GetComponentInChildren<MeshFilter>().sharedMesh;
_materials = searchPrefab.GetComponentInChildren<MeshRenderer>().sharedMaterials;
_matrix4 = new List<Matrix4x4>();
for (var i = 0; i < positions.Length; i++)
{
var position = positions[i];
var matrix = Matrix4x4.TRS(position, Quaternion.identity, Vector3.one);
_matrix4.Add(matrix);
_quadtree.Insert(i,position.xz);
}
}
private void Update()
{
for (var i = 0; i < _mesh.subMeshCount; i++)
{
Graphics.DrawMeshInstanced(_mesh,i,_materials[i],_matrix4);
}
}
#if UNITY_EDITOR
private void OnDrawGizmosSelected()
{
foreach (var position in positions)
{
Gizmos.DrawCube(position,Vector3.one);
}
}
[ContextMenu(nameof(Search))]
private void Search()
{
var positionList = new List<float3>();
var allObjects = GameObject.FindObjectsOfType<GameObject>();
foreach (var obj in allObjects)
{
if (PrefabUtility.GetPrefabAssetType(obj) is not (PrefabAssetType.Regular or PrefabAssetType.Variant)) continue;
if (PrefabUtility.IsAnyPrefabInstanceRoot(obj) is false) continue;
var source = PrefabUtility.GetCorrespondingObjectFromOriginalSource(obj);
if(source!=searchPrefab)continue;
positionList.Add(obj.transform.position);
}
Debug.Log($"已获取到{positionList.Count}个预制体");
positions = positionList.ToArray();
}
#endif
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9c438cc0299e15c4cb3706d97b11f726
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,13 +2,16 @@ using System;
using System.Collections;
using System.Collections.Generic;
using BITKit.WorldNode;
#if UNITY_5_3_OR_NEWER
using UnityEngine;
#endif
namespace Net.Project.B.WorldNode
{
[Serializable]
public class UnityVehicleNode : IWorldNode
{
#if UNITY_5_3_OR_NEWER
public Rigidbody rigidbody;
public GameObject seatObject;
@@ -36,6 +39,8 @@ namespace Net.Project.B.WorldNode
public int Id { get; set; }
public object WorldObject { get; set; }
#endif
}
}

View File

@@ -0,0 +1,22 @@
#if UNITY_5_3_OR_NEWER
using System;
using System.Collections;
using System.Collections.Generic;
using BITKit.WorldNode;
using UnityEngine;
namespace Net.Project.B
{
[Serializable]
public sealed class UnityWorldChunkNode : IWorldNode
{
public string sceneName;
public bool includeColliders;
public GameObject lodGameObject;
public GameObject GameObject { get; set; }
public Bounds Bounds { get; set; }
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b0193be905ce2324a9f256a141778218
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: