4. Reactive Extensions for Unity
https://github.com/neuecc/UniRx/
async/await(UniTask)
async UniTask<string> DemoAsync()
{
// You can await Unity's AsyncObject
var asset = await Resources.LoadAsync<TextAsset>("foo");
// .ConfigureAwait accepts progress callback
await SceneManager.LoadSceneAsync("scene2").ConfigureAwai
// await frame-based operation(you can also await frame c
await UniTask.Delay(TimeSpan.FromSeconds(3));
// like 'yield return WaitForEndOfFrame', or Rx's Observe
await UniTask.Yield(PlayerLoopTiming.PostLateUpdate);
// You can await standard task
await Task.Run(() => 100);
// get async webrequest
async UniTask<string> GetTextAsync(UnityWebRequest req)
{
var op = await req.SendWebRequest();
return op.downloadHandler.text;
}
var task1 = GetTextAsync(UnityWebRequest.Get("http://goog
var task2 = GetTextAsync(UnityWebRequest.Get("http://bing
var task3 = GetTextAsync(UnityWebRequest.Get("http://yaho
// concurrent async-wait and get result easily by tuple s
var (google, bing, yahoo) = await UniTask.WhenAll(task1,
// You can handle timeout easily
await GetTextAsync(UnityWebRequest.Get("http://unity.com"
30. public unsafe struct SimpleNativeArray<T> : IDisposable where T : struct
{
void* nativeMemory;
int length;
Allocator allocator;
public SimpleNativeArray(int length, Allocator allocator)
{
var size = UnsafeUtility.SizeOf<T>() * (long)length;
this.nativeMemory = UnsafeUtility.Malloc(size, UnsafeUtility.AlignOf<T>(), allocator);
this.length = length;
this.allocator = allocator;
}
public int Length => length;
public T this[int index]
{
get => UnsafeUtility.ReadArrayElement<T>(nativeMemory, index);
set => UnsafeUtility.WriteArrayElement(nativeMemory, index, value);
}
public void Dispose()
{
UnsafeUtility.Free(nativeMemory, allocator);
}
}
32. public unsafe struct Data
{
public byte* header;
[NativeSetThreadIndex]
public int threadIndex;
public fixed int slot[JobsUtility.MaxJobThreadCount];
}
33. public struct Entity : IEquatable<Entity>
{
public int Index;
public int Version;
}