Files
Ultimate-Fishing-Simulator-…/Assets/Scripts/Assembly-CSharp/FishSpawnerSystem.cs
2026-03-04 09:37:33 +08:00

191 lines
5.5 KiB
C#

using System;
using System.Runtime.CompilerServices;
using Unity.Burst.Intrinsics;
using Unity.Collections;
using Unity.Entities;
using Unity.Entities.Internal;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
using UnityEngine.Scripting;
public partial class FishSpawnerSystem : SystemBase
{
private struct FishSpawnerSystem_5F62D1D0_LambdaJob_0_Job : IJobChunk
{
public FishSpawnerSystem __this;
[ReadOnly]
public ComponentTypeHandle<FishSpawner> __spawnerTypeHandle;
private void OriginalLambdaBody(in FishSpawner spawner)
{
__this.SpawnEntities(spawner.prefab, spawner.spawnCount, 1f, spawner.position);
}
// [CompilerGenerated]
public void Execute(in ArchetypeChunk chunk, int batchIndex, bool useEnabledMask, in v128 chunkEnabledMask)
{
IntPtr nativeArrayPtr = InternalCompilerInterface.UnsafeGetChunkNativeArrayReadOnlyIntPtr(chunk, ref __spawnerTypeHandle);
int count = chunk.Count;
if (!useEnabledMask)
{
for (int i = 0; i < count; i++)
{
OriginalLambdaBody(in InternalCompilerInterface.UnsafeGetRefToNativeArrayPtrElement<FishSpawner>(nativeArrayPtr, i));
}
return;
}
if (math.countbits(chunkEnabledMask.ULong0 ^ (chunkEnabledMask.ULong0 << 1)) + math.countbits(chunkEnabledMask.ULong1 ^ (chunkEnabledMask.ULong1 << 1)) - 1 <= 4)
{
int j = 0;
int nextRangeEnd = 0;
while (InternalCompilerInterface.UnsafeTryGetNextEnabledBitRange(chunkEnabledMask, nextRangeEnd, out j, out nextRangeEnd))
{
for (; j < nextRangeEnd; j++)
{
OriginalLambdaBody(in InternalCompilerInterface.UnsafeGetRefToNativeArrayPtrElement<FishSpawner>(nativeArrayPtr, j));
}
}
return;
}
ulong num = chunkEnabledMask.ULong0;
int num2 = math.min(64, count);
for (int k = 0; k < num2; k++)
{
if ((num & 1) != 0L)
{
OriginalLambdaBody(in InternalCompilerInterface.UnsafeGetRefToNativeArrayPtrElement<FishSpawner>(nativeArrayPtr, k));
}
num >>= 1;
}
num = chunkEnabledMask.ULong1;
for (int l = 64; l < count; l++)
{
if ((num & 1) != 0L)
{
OriginalLambdaBody(in InternalCompilerInterface.UnsafeGetRefToNativeArrayPtrElement<FishSpawner>(nativeArrayPtr, l));
}
num >>= 1;
}
}
public static void RunWithoutJobSystem(ref EntityQuery query, IntPtr jobPtr)
{
InternalCompilerInterface.JobChunkInterface.RunWithoutJobsInternal(ref InternalCompilerInterface.UnsafeAsRef<FishSpawnerSystem_5F62D1D0_LambdaJob_0_Job>(jobPtr), ref query);
}
void IJobChunk.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
{
Execute(in chunk, unfilteredChunkIndex, useEnabledMask, in chunkEnabledMask);
}
}
private struct TypeHandle
{
[ReadOnly]
public ComponentTypeHandle<FishSpawner> __FishSpawner_RO_ComponentTypeHandle;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void __AssignHandles(ref SystemState state)
{
__FishSpawner_RO_ComponentTypeHandle = state.GetComponentTypeHandle<FishSpawner>(isReadOnly: true);
}
}
private bool spawned;
private TypeHandle __TypeHandle;
private EntityQuery __query_1030341786_0;
[Preserve]
protected override void OnStartRunning()
{
base.OnStartRunning();
if (!spawned)
{
FishSpawnerSystem_5F62D1D0_LambdaJob_0_Execute();
spawned = true;
}
}
[Preserve]
protected override void OnUpdate()
{
}
private void SpawnEntities(Entity prefab, int count, float spacing, float3 startPosition)
{
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
using NativeArray<Entity> outputEntities = new NativeArray<Entity>(count, Allocator.Temp);
entityManager.Instantiate(prefab, outputEntities);
int num = Mathf.CeilToInt(Mathf.Pow(count, 1f / 3f));
int num2 = 0;
for (int i = 0; i < num; i++)
{
if (num2 >= count)
{
break;
}
for (int j = 0; j < num; j++)
{
if (num2 >= count)
{
break;
}
for (int k = 0; k < num; k++)
{
if (num2 >= count)
{
break;
}
float3 position = startPosition + new float3((float)i * spacing, (float)j * spacing, (float)k * spacing);
if (entityManager.HasComponent<LocalTransform>(outputEntities[num2]))
{
entityManager.SetComponentData(outputEntities[num2], LocalTransform.FromPositionRotationScale(position, quaternion.identity, 1f));
}
num2++;
}
}
}
}
private void FishSpawnerSystem_5F62D1D0_LambdaJob_0_Execute()
{
__TypeHandle.__FishSpawner_RO_ComponentTypeHandle.Update(ref base.CheckedStateRef);
FishSpawnerSystem_5F62D1D0_LambdaJob_0_Job value = new FishSpawnerSystem_5F62D1D0_LambdaJob_0_Job
{
__this = this,
__spawnerTypeHandle = __TypeHandle.__FishSpawner_RO_ComponentTypeHandle
};
if (!__query_1030341786_0.IsEmptyIgnoreFilter)
{
base.CheckedStateRef.CompleteDependency();
IntPtr jobPtr = InternalCompilerInterface.AddressOf(ref value);
FishSpawnerSystem_5F62D1D0_LambdaJob_0_Job.RunWithoutJobSystem(ref __query_1030341786_0, jobPtr);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void __AssignQueries(ref SystemState state)
{
EntityQueryBuilder entityQueryBuilder = new EntityQueryBuilder(Allocator.Temp);
__query_1030341786_0 = entityQueryBuilder.WithAll<FishSpawner>().Build(ref state);
entityQueryBuilder.Reset();
entityQueryBuilder.Dispose();
}
protected override void OnCreateForCompiler()
{
base.OnCreateForCompiler();
__AssignQueries(ref base.CheckedStateRef);
__TypeHandle.__AssignHandles(ref base.CheckedStateRef);
}
[Preserve]
public FishSpawnerSystem()
{
}
}