diff --git a/src/Buildin/EcsDefaultWorldProvider.cs b/src/Buildin/EcsDefaultWorldProvider.cs index 4892e3f..21cf271 100644 --- a/src/Buildin/EcsDefaultWorldProvider.cs +++ b/src/Buildin/EcsDefaultWorldProvider.cs @@ -5,6 +5,6 @@ namespace DCFApixels.DragonECS [CreateAssetMenu(fileName = nameof(EcsDefaultWorldProvider), menuName = EcsConsts.FRAMEWORK_NAME + "/WorldProviders/" + nameof(EcsDefaultWorldProvider), order = 1)] public class EcsDefaultWorldProvider : EcsWorldProvider { - protected override EcsDefaultWorld BuildWorld(ConfigContainer configs) { return new EcsDefaultWorld(configs, WorldID); } + protected override EcsDefaultWorld BuildWorld(ConfigContainer configs) { return new EcsDefaultWorld(configs, null, WorldID); } } } diff --git a/src/Buildin/EcsDefaultWorldSingletonProvider.cs b/src/Buildin/EcsDefaultWorldSingletonProvider.cs index fbd0b25..2f2abc2 100644 --- a/src/Buildin/EcsDefaultWorldSingletonProvider.cs +++ b/src/Buildin/EcsDefaultWorldSingletonProvider.cs @@ -14,6 +14,6 @@ return _instance; } } - protected override EcsDefaultWorld BuildWorld(ConfigContainer configs) { return new EcsDefaultWorld(configs, WorldID); } + protected override EcsDefaultWorld BuildWorld(ConfigContainer configs) { return new EcsDefaultWorld(configs, null, WorldID); } } } diff --git a/src/Buildin/EcsRootUnity.cs b/src/Buildin/EcsRootUnity.cs index fbf4531..d859dab 100644 --- a/src/Buildin/EcsRootUnity.cs +++ b/src/Buildin/EcsRootUnity.cs @@ -77,6 +77,7 @@ namespace DCFApixels.DragonECS private void OnDrawGizmos() { + Gizmos.DrawIcon(transform.position, "", false); _pipeline?.DrawGizmos(); } diff --git a/src/Buildin/EcsWorldProvider.cs b/src/Buildin/EcsWorldProvider.cs index 45e2735..8f4f35e 100644 --- a/src/Buildin/EcsWorldProvider.cs +++ b/src/Buildin/EcsWorldProvider.cs @@ -5,6 +5,6 @@ namespace DCFApixels.DragonECS [CreateAssetMenu(fileName = nameof(EcsWorldProvider), menuName = EcsConsts.FRAMEWORK_NAME + "/WorldProviders/" + nameof(EcsWorldProvider), order = 1)] public class EcsWorldProvider : EcsWorldProvider { - protected override EcsWorld BuildWorld(ConfigContainer configs) { return new EcsWorld(configs, WorldID); } + protected override EcsWorld BuildWorld(ConfigContainer configs) { return new EcsWorld(configs, null, WorldID); } } } diff --git a/src/Internal/ArrayUtility.cs b/src/Internal/ArrayUtility.cs index f55393e..b17c463 100644 --- a/src/Internal/ArrayUtility.cs +++ b/src/Internal/ArrayUtility.cs @@ -71,4 +71,75 @@ namespace DCFApixels.DragonECS.Unity.Internal void IEnumerator.Reset() { throw new NotSupportedException(); } } } + + internal static class ArrayUtility + { + private static int GetHighBitNumber(uint bits) + { + if (bits == 0) + { + return -1; + } + int bit = 0; + if ((bits & 0xFFFF0000) != 0) + { + bits >>= 16; + bit |= 16; + } + if ((bits & 0xFF00) != 0) + { + bits >>= 8; + bit |= 8; + } + if ((bits & 0xF0) != 0) + { + bits >>= 4; + bit |= 4; + } + if ((bits & 0xC) != 0) + { + bits >>= 2; + bit |= 2; + } + if ((bits & 0x2) != 0) + { + bit |= 1; + } + return bit; + } + public static int NormalizeSizeToPowerOfTwo(int minSize) + { + unchecked + { + return 1 << (GetHighBitNumber((uint)minSize - 1u) + 1); + } + } + public static int NormalizeSizeToPowerOfTwo_ClampOverflow(int minSize) + { + unchecked + { + int hibit = (GetHighBitNumber((uint)minSize - 1u) + 1); + if (hibit >= 32) + { + return int.MaxValue; + } + return 1 << hibit; + } + } + public static void Fill(T[] array, T value, int startIndex = 0, int length = -1) + { + if (length < 0) + { + length = array.Length; + } + else + { + length = startIndex + length; + } + for (int i = startIndex; i < length; i++) + { + array[i] = value; + } + } + } } \ No newline at end of file diff --git a/src/Internal/Editor/EcsGUI.cs b/src/Internal/Editor/EcsGUI.cs index 9649305..8dac123 100644 --- a/src/Internal/Editor/EcsGUI.cs +++ b/src/Internal/Editor/EcsGUI.cs @@ -3,8 +3,10 @@ using DCFApixels.DragonECS.Unity.Internal; using System; using System.Collections.Generic; + //using System.Drawing; using System.Reflection; +using System.Runtime.InteropServices; using Unity.Collections.LowLevel.Unsafe; using UnityEditor; using UnityEditor.IMGUI.Controls; @@ -15,7 +17,7 @@ using UnityObject = UnityEngine.Object; namespace DCFApixels.DragonECS.Unity.Editors { - internal static class EcsGUI + internal static partial class EcsGUI { #region Scores private static int _changedCounter = 0; @@ -1013,7 +1015,6 @@ namespace DCFApixels.DragonECS.Unity.Editors /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - public static partial class Layout { public static void ScriptAssetButton(MonoScript script, params GUILayoutOption[] options) @@ -1302,12 +1303,14 @@ namespace DCFApixels.DragonECS.Unity.Editors GUILayout.EndVertical(); } } + + #region Default DrawRuntimeData [InitializeOnLoadMethod] private static void ResetRuntimeComponentReflectionCache() { _runtimeComponentReflectionCaches.Clear(); } - private class RuntimeComponentReflectionCache + internal class RuntimeComponentReflectionCache { public readonly Type Type; @@ -1481,6 +1484,290 @@ namespace DCFApixels.DragonECS.Unity.Editors expandMatrix.Up(); return changed; } + #endregion + + #region FactMode DrawRuntimeData + private class InspectorTypeInfo + { + #region cahce + private static Dictionary _typeInfosCache = new Dictionary(); + public static InspectorTypeInfo Get(Type type) + { + if (_typeInfosCache.TryGetValue(type, out InspectorTypeInfo info) == false) + { + info = new InspectorTypeInfo(type); + _typeInfosCache.Add(type, info); + } + + return info; + } + #endregion + + public readonly Type Type; + public readonly InspectorFieldInfo[] Fields; + + #region Constructors + private static StructList CnstrBuffer = new StructList(32); + private static readonly char[] VectorFields = new char[] { 'x', 'y', 'z', 'w' }; + private static readonly char[] ColorFields = new char[] { 'r', 'g', 'b', 'a' }; + public InspectorTypeInfo(Type type) + { + CnstrBuffer.FastClear(); + Type = type; + var fieldInfos = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + foreach (var fieldInfo in fieldInfos) + { + InspectorFieldInfo.Union infoUniton = default; + ref InspectorFieldInfo.Constructor infocstr = ref infoUniton.Constructor; + + var fieldType = fieldInfo.FieldType; + + infocstr.FieldInfo = fieldInfo; + infocstr.Offset = UnsafeUtility.GetFieldOffset(fieldInfo); ; + infocstr.Size = UnsafeUtility.SizeOf(fieldType); ; + infocstr.Name = UnityEditorUtility.TransformFieldName(fieldType.Name); + infocstr.TypeID = FieldTypeIDUtitlity.GetFieldTypeIDFor(fieldType); + + #region Def custom types + if (infocstr.TypeID == FieldTypeID.Struct) + { + InspectorTypeInfo preDefinedTypeInfo = Get(fieldType); + infocstr.PreDefinedType = preDefinedTypeInfo; + int length = preDefinedTypeInfo.Fields.Length; + if (length >= 2 && length <= 3) + { + bool isCheck = true; + for (int i = 0; i < length; i++) + { + ref var field = ref preDefinedTypeInfo.Fields[i]; + if (char.ToLower(field.Name[0]) != VectorFields[i]) + { + isCheck = false; + break; + } + } + if (isCheck) + { + infocstr.TypeID = FieldTypeID.StructVector; + } + else + { + isCheck = true; + for (int i = 0; i < length; i++) + { + ref var field = ref preDefinedTypeInfo.Fields[i]; + if (char.ToLower(field.Name[0]) != ColorFields[i]) + { + isCheck = false; + break; + } + } + if (isCheck) + { + infocstr.TypeID = FieldTypeID.StructColor; + } + } + } + } + #endregion + + CnstrBuffer.Add(infoUniton.Result); + } + + Fields = CnstrBuffer.ToArray(); + Array.Sort(Fields); + } + #endregion + } + + private static class FieldTypeIDUtitlity + { + #region GetFieldTypeIDFor + public static FieldTypeID GetFieldTypeIDFor(Type type) + { + var size = UnsafeUtility.SizeOf(type); + if (type.IsClass) + { + if (typeof(UnityObject).IsAssignableFrom(type)) + { + return FieldTypeID.UnityObject; + } + if (type == typeof(string)) + { + return FieldTypeID.String; + } + if (type == typeof(AnimationCurve)) + { + return FieldTypeID.AnimationCurve; + } + if (type == typeof(Gradient)) + { + return FieldTypeID.Gradient; + } + if (type == typeof(Array)) + { + return FieldTypeID.RefArray; + } + if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>)) + { + return FieldTypeID.RefArray; + } + + return FieldTypeID.Ref; + } + else + { + if (type.IsPrimitive) + { + if (UnsafeUtility.IsBlittable(type)) + { + switch (size) + { + case 1: + if (type == typeof(byte)) + { + return FieldTypeID.UInt; + } + if (type == typeof(sbyte)) + { + return FieldTypeID.Int; + } + break; + case 2: + if (type == typeof(ushort)) + { + return FieldTypeID.UInt; + } + if (type == typeof(short)) + { + return FieldTypeID.Int; + } + break; + case 4: + if (type == typeof(uint)) + { + return FieldTypeID.UInt; + } + if (type == typeof(int)) + { + return FieldTypeID.Int; + } + if (type == typeof(float)) + { + return FieldTypeID.Real; + } + break; + case 8: + if (type == typeof(ulong)) + { + return FieldTypeID.UInt; + } + if (type == typeof(long)) + { + return FieldTypeID.Int; + } + if (type == typeof(double)) + { + return FieldTypeID.Real; + } + break; + } + } + else + { + if (type == typeof(bool)) + { + return FieldTypeID.Bool; + } + } + } + else if (type.IsEnum) + { + return FieldTypeID.Enum; + } + + if (type == typeof(LayerMask)) + { + return FieldTypeID.LayerMask; + } + + return FieldTypeID.Struct; + } + } + #endregion + } + private enum FieldTypeID : byte + { + None = 0, + CantDisplayed, + + // leaf types + Bool, + Int, + UInt, + Real, + String, + Enum, + + UnityObject, + LayerMask, + Gradient, + AnimationCurve, + + // struct types + Struct, + Ref, + + // custom struct types + StructVector, + StructColor, + RefArray, + RefList, + } + + [StructLayout(LayoutKind.Sequential)] + private unsafe readonly struct InspectorFieldInfo : IEquatable, IComparable + { + public readonly FieldInfo FieldInfo; + public readonly InspectorTypeInfo PreDefinedType; + public readonly string Name; + public readonly int Offset; + public readonly int Size; + public readonly FieldTypeID ID; + + public int CompareTo(InspectorFieldInfo other) + { + return other.Offset - Offset; + } + public bool Equals(InspectorFieldInfo other) + { + return EqualityComparer.Default.Equals(this, other); + } + [StructLayout(LayoutKind.Sequential)] + public unsafe struct Constructor + { + public FieldInfo FieldInfo; + public InspectorTypeInfo PreDefinedType; + public string Name; + public int Offset; + public int Size; + public byte AxisCount; + public FieldTypeID TypeID; + } + [StructLayout(LayoutKind.Explicit)] + public struct Union + { + [FieldOffset(0)] + public Constructor Constructor; + [FieldOffset(0)] + public InspectorFieldInfo Result; + } + } + private unsafe static bool FastDrawRuntimeData(void* data, InspectorTypeInfo cache) + { + throw new NotImplementedException(); + } + #endregion } } } diff --git a/src/Internal/Editor/ExtendedEditor.cs b/src/Internal/Editor/ExtendedEditor.cs index 5648dc7..f9d4e6c 100644 --- a/src/Internal/Editor/ExtendedEditor.cs +++ b/src/Internal/Editor/ExtendedEditor.cs @@ -92,12 +92,35 @@ namespace DCFApixels.DragonECS.Unity.Editors { base.OnInspectorGUI(); } - - protected SerializedProperty FindProperty(string name) { return serializedObject.FindProperty(name); } + + + //Color proColor = (Color)new Color32(56, 56, 56, 255); + //Color plebColor = (Color)new Color32(194, 194, 194, 255); + //protected override void OnHeaderGUI() + //{ + // //base.OnHeaderGUI(); + // var rect = EditorGUILayout.GetControlRect(false, 0f); + // rect.height = EditorGUIUtility.singleLineHeight; + // rect.y -= rect.height; + // rect.x = 48; + // rect.xMax -= rect.x * 2f; + // + // //GUI.skin.settings + // EditorGUI.DrawRect(rect, EditorGUIUtility.isProSkin ? proColor : plebColor); + // + // //string header = (target as ComponentFolder).folderName; // <--- your variable + // string header = ""; + // if (string.IsNullOrEmpty(header)) + // { + // header = target.ToString() + 1; + // } + // + // EditorGUI.LabelField(rect, header, EditorStyles.boldLabel); + //} } internal abstract class ExtendedEditor : ExtendedEditor { diff --git a/src/Internal/Editor/UnityEditorUtility.cs b/src/Internal/Editor/UnityEditorUtility.cs index 4ec3289..7df6d82 100644 --- a/src/Internal/Editor/UnityEditorUtility.cs +++ b/src/Internal/Editor/UnityEditorUtility.cs @@ -103,12 +103,15 @@ namespace DCFApixels.DragonECS.Unity.Editors namespace DCFApixels.DragonECS.Unity.Editors { using UnityEditor; + using Assembly = System.Reflection.Assembly; [InitializeOnLoad] internal static partial class UnityEditorUtility { static UnityEditorUtility() { + _integrationAssembly = typeof(UnityEditorUtility).Assembly; + colorBoxeStyles = new SparseArray(); List serializableTypes = new List(); @@ -144,6 +147,7 @@ namespace DCFApixels.DragonECS.Unity.Editors //}).ToArray(); } + internal static readonly Assembly _integrationAssembly; internal static readonly Type[] _serializableTypes; internal static readonly TypeMeta[] _serializableTypeWithMetaIDMetas; private static readonly Dictionary _metaIDTypePairs = new Dictionary(); diff --git a/src/Internal/Icons/Color_Icon.png b/src/Internal/Icons/Color_Icon.png new file mode 100644 index 0000000..69278be Binary files /dev/null and b/src/Internal/Icons/Color_Icon.png differ diff --git a/src/Internal/Icons/Color_Icon.png.meta b/src/Internal/Icons/Color_Icon.png.meta new file mode 100644 index 0000000..cb32197 --- /dev/null +++ b/src/Internal/Icons/Color_Icon.png.meta @@ -0,0 +1,122 @@ +fileFormatVersion: 2 +guid: f6905846bdee2584393b2583d00d10f3 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 11 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 2 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Internal/Icons/Gray_Icon.png b/src/Internal/Icons/Gray_Icon.png new file mode 100644 index 0000000..6d875a8 Binary files /dev/null and b/src/Internal/Icons/Gray_Icon.png differ diff --git a/src/Internal/Icons/Gray_Icon.png.meta b/src/Internal/Icons/Gray_Icon.png.meta new file mode 100644 index 0000000..7e74db9 --- /dev/null +++ b/src/Internal/Icons/Gray_Icon.png.meta @@ -0,0 +1,122 @@ +fileFormatVersion: 2 +guid: f1fe20f167697834b815161036625d65 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 11 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 2 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Internal/Utils/StructList.cs b/src/Internal/Utils/StructList.cs new file mode 100644 index 0000000..83efadf --- /dev/null +++ b/src/Internal/Utils/StructList.cs @@ -0,0 +1,165 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Runtime.CompilerServices; + +namespace DCFApixels.DragonECS.Unity.Internal +{ + [DebuggerDisplay("Count: {Count}")] + internal struct StructList + { + internal T[] _items; + internal int _count; + public int Count + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _count; } + } + public int Capacity + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _items.Length; } + set + { + if (value <= _items.Length) { return; } + value = ArrayUtility.NormalizeSizeToPowerOfTwo(value); + Array.Resize(ref _items, value); + } + } + public T this[int index] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { +#if DEBUG + if (index < 0 || index >= _count) { Throw.ArgumentOutOfRange(); } +#endif + return _items[index]; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + set + { +#if DEBUG + if (index < 0 || index >= _count) { Throw.ArgumentOutOfRange(); } +#endif + _items[index] = value; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public StructList(int capacity) + { + _items = new T[ArrayUtility.NormalizeSizeToPowerOfTwo(capacity)]; + _count = 0; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Add(T item) + { + if (_count >= _items.Length) + { + Array.Resize(ref _items, _items.Length << 1); + } + _items[_count++] = item; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int IndexOf(T item) + { + return Array.IndexOf(_items, item, 0, _count); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void SwapAt(int idnex1, int idnex2) + { + T tmp = _items[idnex1]; + _items[idnex1] = _items[idnex2]; + _items[idnex2] = tmp; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void FastRemoveAt(int index) + { +#if DEBUG + if (index < 0 || index >= _count) { Throw.ArgumentOutOfRange(); } +#endif + _items[index] = _items[--_count]; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void RemoveAt(int index) + { +#if DEBUG + if (index < 0 || index >= _count) { Throw.ArgumentOutOfRange(); } +#endif + _items[index] = _items[--_count]; + _items[_count] = default; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void RemoveAtWithOrder(int index) + { +#if DEBUG + if (index < 0 || index >= _count) { Throw.ArgumentOutOfRange(); } +#endif + for (int i = index; i < _count;) + { + _items[i++] = _items[i]; + } + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Remove(T item) + { + int index = IndexOf(item); + if (index >= 0) + { + RemoveAt(index); + return true; + } + return false; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool RemoveWithOrder(T item) + { + int index = IndexOf(item); + if (index >= 0) + { + RemoveAtWithOrder(index); + return true; + } + return false; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void FastClear() + { + _count = 0; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Clear() + { + for (int i = 0; i < _count; i++) + { + _items[i] = default; + } + _count = 0; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ReadOnlySpan.Enumerator GetEnumerator() + { + return new ReadOnlySpan(_items, 0, _count).GetEnumerator(); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ReadOnlySpan ToReadOnlySpan() + { + return new ReadOnlySpan(_items, 0, _count); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public IEnumerable ToEnumerable() + { + return _items.Take(_count); + } + + public T[] ToArray() + { + T[] result = new T[_count]; + Array.Copy(_items, result, _count); + return _items; + } + } +} \ No newline at end of file diff --git a/src/Internal/Utils/StructList.cs.meta b/src/Internal/Utils/StructList.cs.meta new file mode 100644 index 0000000..1aeea41 --- /dev/null +++ b/src/Internal/Utils/StructList.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 366ced1c4c1442c4db00c5a2b8c5787d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Internal/Utils/Throw.cs b/src/Internal/Utils/Throw.cs new file mode 100644 index 0000000..03aa65d --- /dev/null +++ b/src/Internal/Utils/Throw.cs @@ -0,0 +1,12 @@ +using System; + +namespace DCFApixels.DragonECS.Unity.Internal +{ + internal static class Throw + { + internal static void ArgumentOutOfRange() + { + throw new ArgumentOutOfRangeException(); + } + } +} diff --git a/src/Internal/Utils/Throw.cs.meta b/src/Internal/Utils/Throw.cs.meta new file mode 100644 index 0000000..4b32348 --- /dev/null +++ b/src/Internal/Utils/Throw.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 525c4a5bc83fb3343b3b93a02d3caf59 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Templates/EntityTemplate/Editor/EntityTemplateEditor.cs b/src/Templates/EntityTemplate/Editor/EntityTemplateEditor.cs index 24f4085..96e2f52 100644 --- a/src/Templates/EntityTemplate/Editor/EntityTemplateEditor.cs +++ b/src/Templates/EntityTemplate/Editor/EntityTemplateEditor.cs @@ -1,7 +1,9 @@ #if UNITY_EDITOR using DCFApixels.DragonECS.Unity.Internal; using DCFApixels.DragonECS.Unity.RefRepairer.Editors; +using System; using UnityEditor; +using UnityEditor.Graphs; using UnityEditorInternal; using UnityEngine; diff --git a/src/Templates/EntityTemplate/Templates/MonoEntityTemplate.cs b/src/Templates/EntityTemplate/Templates/MonoEntityTemplate.cs index d5b7811..3f84c8f 100644 --- a/src/Templates/EntityTemplate/Templates/MonoEntityTemplate.cs +++ b/src/Templates/EntityTemplate/Templates/MonoEntityTemplate.cs @@ -2,6 +2,7 @@ using DCFApixels.DragonECS.Unity.Internal; using System; using UnityEngine; +using static UnityEngine.GraphicsBuffer; namespace DCFApixels.DragonECS {