Files
5.24BuYu/Assets/MyGame/Scripts/Manager/FishSpawnTimerJob.cs
T

42 lines
1.1 KiB
C#
Raw Normal View History

2026-03-27 15:18:35 +08:00
using Assets.MyGame.Scripts.Net.API.UserData_SubClass;
using System.Collections.Generic;
2026-02-03 11:35:19 +08:00
using Unity.Burst;
using Unity.Collections;
2026-03-27 15:18:35 +08:00
using Unity.Jobs;
using UnityEngine;
2026-02-03 11:35:19 +08:00
[BurstCompile]
public struct FishSpawnTimerJob : IJob
{
public float deltaTime;
public NativeArray<float> timers; // 每条鱼的计时器
2026-03-27 15:18:35 +08:00
static List<float> spawnTimes = new List<float>();
2026-02-03 11:35:19 +08:00
public NativeArray<float> frequencies; // 每条鱼的频率
public NativeArray<int> shouldSpawn; // 输出:是否应该生成
2026-03-27 15:18:35 +08:00
//public NativeHashMap<int, bool> keyValues;
2026-02-03 11:35:19 +08:00
public void Execute()
{
2026-03-27 15:18:35 +08:00
2026-02-03 11:35:19 +08:00
for (int i = 0; i < timers.Length; i++)
{
2026-03-27 15:18:35 +08:00
if (shouldSpawn[i] == 0)
{
if (timers[i] <= 10000)
{
timers[i] += deltaTime;
}
2026-02-03 11:35:19 +08:00
2026-03-27 15:18:35 +08:00
if (timers[i] >= frequencies[i])
{
timers[i] = 0;
if (shouldSpawn[i] == 0)
shouldSpawn[i] = 1;
}
2026-02-03 11:35:19 +08:00
}
}
}
}