Skip to content

Instantly share code, notes, and snippets.

@sarkahn
Created March 1, 2020 14:02
Show Gist options
  • Select an option

  • Save sarkahn/f61e1d495d3873f1812b1222f78c5622 to your computer and use it in GitHub Desktop.

Select an option

Save sarkahn/f61e1d495d3873f1812b1222f78c5622 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
public class GlobalArray
{
public static NativeArray<int> Array;
}
[AlwaysUpdateSystem]
public class SystemA : SystemBase
{
protected override void OnCreate()
{
base.OnCreate();
GlobalArray.Array = new NativeArray<int>(3, Allocator.Persistent);
}
protected override void OnDestroy()
{
base.OnDestroy();
GlobalArray.Array.Dispose();
}
protected override void OnUpdate()
{
var arr = GlobalArray.Array;
Job.WithCode(() =>
{
for (int i = 0; i < arr.Length; ++i)
arr[i] = i;
}).Schedule();
}
}
public class SystemB : SystemBase
{
protected override void OnUpdate()
{
var arr = GlobalArray.Array;
Job
.WithoutBurst()
.WithCode(() =>
{
for (int i = 0; i < arr.Length; ++i)
Debug.Log($"{arr[i]}");
}).Schedule();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment