Instantly share code, notes, and snippets.

Embed
What would you like to do?
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
public class RemoveSystem : JobComponentSystem
{
[Inject] EndFrameBarrier barrier;
protected override JobHandle OnUpdate(JobHandle inputDeps) => new Hitcheck()
{
mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition + Vector3.forward * 10),
commandBuffer = barrier.CreateCommandBuffer().ToConcurrent()
}.Schedule(this, inputDeps);
[Unity.Burst.BurstCompile]
struct Hitcheck : IJobProcessComponentDataWithEntity<Position, ItemTag>
{
public EntityCommandBuffer.Concurrent commandBuffer;
public float3 mousePosition;
public void Execute(Entity entity, int index, ref Position pos, [ReadOnly] ref ItemTag data1)
{
if( math.distance(pos.Value, mousePosition ) < 1)
{
commandBuffer.DestroyEntity(index, entity);
}
}
}
}
public struct ItemTag : IComponentData { }
using Unity.Entities;
using Unity.Mathematics;
using Unity.Rendering;
using Unity.Transforms;
using UnityEngine;
public class Spawner : MonoBehaviour
{
[SerializeField] MeshInstanceRenderer rendererParams;
void Start()
{
int maxCount = 6400;
var random = new Unity.Mathematics.Random();
random.InitState();
float3 min = new float3(-10f, -10f, 0), max = new float3(10f, 10f, 0);
var entityManager = World.Active.GetOrCreateManager<EntityManager>();
var archytype = entityManager.CreateArchetype(
typeof(MeshInstanceRenderer),
typeof(Position),
typeof(ItemTag));
for (int i = 0; i < maxCount; i++)
{
var e = entityManager.CreateEntity(archytype);
var pos = new Position() { Value = random.NextFloat3(min, max) };
entityManager.SetSharedComponentData(e, rendererParams);
entityManager.SetComponentData(e, pos);
}
}
}
@tsubaki

This comment has been minimized.

Owner

tsubaki commented Oct 1, 2018

118

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment