Created
March 1, 2020 14:02
-
-
Save sarkahn/f61e1d495d3873f1812b1222f78c5622 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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