|
|
|
|
|
using GameCore.TinyECS;
|
|
|
|
|
|
using Unity.Burst;
|
|
|
|
|
|
using Unity.Collections;
|
|
|
|
|
|
using Unity.Jobs;
|
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using Random = Unity.Mathematics.Random;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ECSTest.Server
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
[BurstCompile]
|
|
|
|
|
|
public struct TestWorldJob : IJob
|
|
|
|
|
|
{
|
|
|
|
|
|
public World world;
|
|
|
|
|
|
|
|
|
|
|
|
public void Execute()
|
|
|
|
|
|
{
|
|
|
|
|
|
// var componentId = ComponentId<BulletData>.Get();
|
|
|
|
|
|
// Debug.LogError($"XXXX bulletData id: {componentId}");
|
|
|
|
|
|
// var componentId2 = ComponentId<CannonData>.Get();
|
|
|
|
|
|
// Debug.LogError($"xxxx2222 CannonData id: {componentId2}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[BurstCompile]
|
|
|
|
|
|
public struct GetDeferred : IJob
|
|
|
|
|
|
{
|
|
|
|
|
|
public World world;
|
|
|
|
|
|
|
|
|
|
|
|
public void Execute()
|
|
|
|
|
|
{
|
|
|
|
|
|
// var componentId = ComponentId<BulletData>.Get();
|
|
|
|
|
|
// Debug.LogError($"XXXX bulletData id: {componentId}");
|
|
|
|
|
|
// var componentId2 = ComponentId<CannonData>.Get();
|
|
|
|
|
|
// Debug.LogError($"xxxx2222 CannonData id: {componentId2}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[BurstCompile]
|
|
|
|
|
|
public struct SpawnCannonJob : IJob
|
|
|
|
|
|
{
|
|
|
|
|
|
public World world;
|
|
|
|
|
|
public NativeList<bool> deferList;
|
|
|
|
|
|
|
|
|
|
|
|
public uint seed;
|
|
|
|
|
|
public int maxCount;
|
|
|
|
|
|
public int spawnCountPerFrame;
|
|
|
|
|
|
public Rect rect;
|
|
|
|
|
|
public int initHealth;
|
|
|
|
|
|
|
|
|
|
|
|
public void Execute()
|
|
|
|
|
|
{
|
|
|
|
|
|
ref var database = ref world.cannonDatabase;
|
|
|
|
|
|
if (database.Count >= maxCount)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
var random = new Random(seed);
|
|
|
|
|
|
for (int i = 0; i < spawnCountPerFrame; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var pos = random.NextFloat2(rect.min, rect.max);
|
|
|
|
|
|
var dir = random.NextFloat(math.PI2);
|
|
|
|
|
|
math.sincos(dir, out var s, out var c);
|
|
|
|
|
|
var velocity = new float2(c, s);
|
|
|
|
|
|
|
|
|
|
|
|
var entity = database.AddEntity();
|
|
|
|
|
|
ref var cannonData = ref database.GetDataRef<CannonData>(entity);
|
|
|
|
|
|
cannonData.position = pos;
|
|
|
|
|
|
cannonData.velocity = velocity;
|
|
|
|
|
|
cannonData.direction = dir;
|
|
|
|
|
|
cannonData.health = initHealth;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[BurstCompile]
|
|
|
|
|
|
public struct SpawnBulletJob : IJob
|
|
|
|
|
|
{
|
|
|
|
|
|
public World World;
|
|
|
|
|
|
|
|
|
|
|
|
public void Execute()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|