Skip to content

Instantly share code, notes, and snippets.

@andywatts
Last active December 9, 2019 16:10
Show Gist options
  • Save andywatts/570131fdd560e332848e5d44f208a684 to your computer and use it in GitHub Desktop.
Save andywatts/570131fdd560e332848e5d44f208a684 to your computer and use it in GitHub Desktop.
using Unity.Entities;
using Unity.Collections;
using UnityEngine;
using Unity.Jobs;
using Unity.Burst;
// ICOMPONENTDATA
public struct MyICD : IComponentData {
public int id;
}
// MONO
class LookupMapTest : MonoBehaviour
{
NativeHashMap<int,int> myHashMap;
void Start()
{
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = em.CreateEntity();
myHashMap = new NativeHashMap<int, int>(256, Allocator.Persistent);
myHashMap.TryAdd(123,456);
}
void OnDestroy(){ myHashMap.Dispose(); }
}
// COMPONENTSYSTEM
public class MySystem : ComponentSystem
{
protected override void OnUpdate()
{
Entities.ForEach((ref MyICD myICD) => {
// Need readonly access to hashmap
});
}
}
// JOB SYSTEM
public class MyJobSystem : JobComponentSystem
{
[BurstCompile]
struct MyJob : IJobForEachWithEntity<MyICD>
{
public int myJobParam;
public void Execute(Entity entity, int index, [ReadOnly] ref MyICD myICD)
{
// Need readonly access to hashmap
}
}
protected override JobHandle OnUpdate(JobHandle inputDependencies)
{
var job = new MyJob()
{
myJobParam = 666
};
return job.Schedule(this, inputDependencies);
}
~ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment