Netcode Bootstrap

This commit is contained in:
Luis Gonzalez
2026-05-31 14:27:52 -07:00
parent 99d8d2d2a9
commit 7fa77ce821
1813 changed files with 2921554 additions and 84 deletions
@@ -0,0 +1,25 @@
using Unity.Assertions;
using UnityEngine;
using UnityEngine.UI;
/////////////////////////////////////////////////////////////////////////////////
namespace Rukhanka.Samples
{
class AnimCullingSampleConf: MonoBehaviour
{
public Toggle enableAnimationCullingToggle;
public Toggle enableRendererBBoxRecalculation;
public Camera cullingCamera;
public static AnimCullingSampleConf Instance { get; private set; }
/////////////////////////////////////////////////////////////////////////////////
void Awake()
{
Assert.IsNull(Instance);
Instance = this;
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: d10831bbc4d14464c8e05ed9ffd16897
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 298480
packageName: Rukhanka Animation System 2
packageVersion: 2.9.0
assetPath: Packages/com.rukhanka.animation/Samples~/Samples/Scenes/20. Animation Culling/Scripts/AnimCullingSampleConf.cs
uploadId: 897522
@@ -0,0 +1,53 @@
using Unity.Entities;
using UnityEngine;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace Rukhanka.Samples
{
[WorldSystemFilter(WorldSystemFilterFlags.LocalSimulation | WorldSystemFilterFlags.ClientSimulation)]
[UpdateBefore(typeof(RukhankaAnimationSystemGroup))]
public partial class AnimCullingSampleSystem: SystemBase
{
protected override void OnUpdate()
{
var sampleConf = AnimCullingSampleConf.Instance;
if (sampleConf == null)
return;
if (UILabelSetter_AnimationCulling.Instance != null)
{
sampleConf.cullingCamera.fieldOfView = UILabelSetter_AnimationCulling.Instance.floatParam1Slider.value;
}
var entitiesWithCulling = SystemAPI.QueryBuilder()
.WithAll<CullAnimationsTag>()
.WithOptions(EntityQueryOptions.IgnoreComponentEnabledState)
.Build();
var animatedEntities = SystemAPI.QueryBuilder()
.WithAll<RigDefinitionComponent>()
.WithOptions(EntityQueryOptions.IgnoreComponentEnabledState)
.Build();
if (entitiesWithCulling.IsEmpty)
{
if (sampleConf.enableAnimationCullingToggle.isOn)
EntityManager.AddComponent<CullAnimationsTag>(animatedEntities);
}
else
{
if (!sampleConf.enableAnimationCullingToggle.isOn)
EntityManager.RemoveComponent<CullAnimationsTag>(animatedEntities);
}
var dynamicBoundingBoxEntities = SystemAPI.QueryBuilder()
.WithAll<ShouldUpdateBoundingBoxTag>()
.WithOptions(EntityQueryOptions.IgnoreComponentEnabledState)
.Build();
EntityManager.SetComponentEnabled<ShouldUpdateBoundingBoxTag>(dynamicBoundingBoxEntities, sampleConf.enableRendererBBoxRecalculation.isOn);
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 95ba04a876f8eff4bb4dc20a19ac8164
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 298480
packageName: Rukhanka Animation System 2
packageVersion: 2.9.0
assetPath: Packages/com.rukhanka.animation/Samples~/Samples/Scenes/20. Animation Culling/Scripts/AnimCullingSampleSystems.cs
uploadId: 897522
@@ -0,0 +1,98 @@
#if !RUKHANKA_NO_DEBUG_DRAWER
using Rukhanka.DebugDrawer;
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Rendering;
/////////////////////////////////////////////////////////////////////////////////
namespace Rukhanka.Samples
{
[BurstCompile]
partial struct BoundsRenderJob: IJobEntity
{
public Drawer dd;
public uint colorVisible;
public uint colorInvisible;
public uint colorGeneric;
[ReadOnly]
public ComponentLookup<CullAnimationsTag> cullAnimationsTagLookup;
void Execute(in WorldRenderBounds bb, in SkinnedMeshRendererComponent asmc)
{
var xform = new RigidTransform(quaternion.identity, bb.Value.Center);
var color = colorGeneric;
if (cullAnimationsTagLookup.HasComponent(asmc.animatedRigEntity))
{
color = cullAnimationsTagLookup.IsComponentEnabled(asmc.animatedRigEntity) ? colorInvisible : colorVisible;
}
dd.DrawWireCuboid(bb.Value.Size, color, xform);
}
}
/////////////////////////////////////////////////////////////////////////////////
[BurstCompile]
struct FrustumRenderJob: IJob
{
public NativeArray<float4x4> cullingMatrices;
public Drawer dd;
public void Execute()
{
foreach (var cm in cullingMatrices)
{
dd.DrawWireFrustum(cm, 0xffff);
}
}
}
/////////////////////////////////////////////////////////////////////////////////
partial class AnimCullingSampleVisualizationSystem: SystemBase
{
protected override void OnUpdate()
{
if (AnimCullingSampleConf.Instance == null || AnimationCullingConfig.Instance == null)
return;
if (!SystemAPI.TryGetSingletonRW<Drawer>(out var dd))
return;
var acc = AnimationCullingConfig.Instance;
if (acc.cullingCameras.Length > 0)
{
var cullingMatrices = CollectionHelper.CreateNativeArray<float4x4>(acc.cullingCameras.Length, CheckedStateRef.WorldUpdateAllocator);
for (var i = 0; i < acc.cullingCameras.Length; ++i)
{
cullingMatrices[i] = acc.cullingCameras[i].cullingMatrix;
}
var frustumRenderJob = new FrustumRenderJob()
{
dd = dd.ValueRW,
cullingMatrices = cullingMatrices
};
frustumRenderJob.Run();
}
var bbRenderJob = new BoundsRenderJob()
{
dd = dd.ValueRW,
colorGeneric = 0xffffffff,
colorInvisible = 0xff0000ff,
colorVisible = 0x00ff00ff,
cullAnimationsTagLookup = SystemAPI.GetComponentLookup<CullAnimationsTag>(true)
};
Dependency = bbRenderJob.ScheduleParallel(Dependency);
}
}
}
#endif
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: f7e96083ada6e5c4f891a2a69fbbdf08
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 298480
packageName: Rukhanka Animation System 2
packageVersion: 2.9.0
assetPath: Packages/com.rukhanka.animation/Samples~/Samples/Scenes/20. Animation Culling/Scripts/AnimCullingSampleVisualizationSystem.cs
uploadId: 897522