ECS is DOD but UIToolkit is OOP. How do you bridge this divide?
For example, DynamicBuffer is a list and ListView is meant to display those. Problem arise immediately:
- DynamicBuffer does not implement System.Collections.IList
- DynamicBuffer is made invalid by some structural changes (these that result is buffer relocation)
First issue can be patched over by creating an adapter struct. But it will throw exceptions eventually because of this second point for which I found no 100% reliable solution so far.
IList adapter example
using System.Collections;
using UnityEngine;
using Unity.Collections;
/// <summary> note: nativeCollection.AsNativeArray() exists so you can pass most native container types here </summary>
public struct NativeArrayAsIList <T> : IList where T : unmanaged
{
public NativeArray<T> array;
public NativeArrayAsIList ( NativeArray<T> arr ) => this.array = arr;
object IList.this[int index]
{
get => this.array[index];
[System.Obsolete("read-only",true)] set => this.array[index] = (T)value;
}
public int Count => this.array.Length;
public bool IsReadOnly => true;
public bool IsFixedSize { get{ Debug.LogWarning("IsFixedSize not implemented"); return false; } }
public bool IsSynchronized { get{ Debug.LogWarning("IsSynchronized not implemented"); return false; } }
public object SyncRoot { get{ Debug.LogWarning("SyncRoot not implemented"); return null; } }
[System.Obsolete("read-only",true)] public int Add ( object value ) { Debug.LogWarning($"Add( {value} )"); return -1; }
[System.Obsolete("read-only",true)] public void Clear () => Debug.LogWarning($"Clear()");
[System.Obsolete("not implemented")] public bool Contains ( object value ) { Debug.LogWarning("Contains not implemented"); return false; }
[System.Obsolete("read-only",true)] public void CopyTo ( System.Array array , int index ) => Debug.LogWarning("CopyTo not implemented");
[System.Obsolete("not implemented")] IEnumerator IEnumerable.GetEnumerator () { Debug.LogWarning("IEnumerable.GetEnumerator not implemented"); return this.array.GetEnumerator(); }
[System.Obsolete("read-only",true)] public void RemoveAt ( int index ) => Debug.LogWarning("RemoveAt not implemented");
[System.Obsolete("not implemented")] public int IndexOf ( object value ) { Debug.LogWarning("IndexOf not implemented"); return -1; }
[System.Obsolete("read-only",true)] public void Insert ( int index , object value ) => Debug.LogWarning("Insert not implemented");
[System.Obsolete("read-only",true)] public void Remove ( object value ) => Debug.LogWarning("Remove not implemented");
}
Any ideas, thought, examples, alternatives?