From 78b49e3f7bbd54171beb4b1507a87bc55b289b17 Mon Sep 17 00:00:00 2001 From: DCFApixels <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 20 Mar 2025 10:55:43 +0800 Subject: [PATCH] update metaID --- .../MetaAttributes/MetaIDAttribute.cs | 24 +++++++++++++----- src/DebugUtils/TypeMeta.cs | 25 +++++++++++++++++-- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/DebugUtils/MetaAttributes/MetaIDAttribute.cs b/src/DebugUtils/MetaAttributes/MetaIDAttribute.cs index 8e57fff..7ccdaef 100644 --- a/src/DebugUtils/MetaAttributes/MetaIDAttribute.cs +++ b/src/DebugUtils/MetaAttributes/MetaIDAttribute.cs @@ -51,11 +51,11 @@ namespace DCFApixels.DragonECS //} public static bool IsGenericID(string id) { - return Regex.IsMatch(id, @"^[^,<>\s]*$"); + return id[id.Length - 1] == '>' || Regex.IsMatch(id, @"^[^,<>\s]*$"); } - public static bool IsValidID(string input) + public static bool IsValidID(string id) { - return input[input.Length - 1] == '>' || Regex.IsMatch(input, @"^[a-zA-Z0-9_]+$"); + return Regex.IsMatch(id, @"^[a-zA-Z0-9_]+$"); } @@ -153,7 +153,7 @@ namespace DCFApixels.DragonECS #region CollisionList [DebuggerTypeProxy(typeof(DebuggerProxy))] - [DebuggerDisplay("HasAnyCollision: {IsHasAnyCollision} ListsCount: {ListsCount}")] + [DebuggerDisplay("HasAnyCollision: {IsHasAnyCollision} ListsCount: {Count}")] public class CollisionList : IEnumerable { private LinkedList[] _linkedLists; @@ -193,6 +193,7 @@ namespace DCFApixels.DragonECS _listsCount = 0; foreach (var meta in metas) { + if (meta.IsHasMetaID() == false) { continue; } if (listIndexes.TryGetValue(meta.MetaID, out int headIndex)) { hasCollision = true; @@ -281,6 +282,7 @@ namespace DCFApixels.DragonECS #endregion [DebuggerDisplay("Count: {Count}")] + [DebuggerTypeProxy(typeof(DebuggerProxy))] public readonly struct Collision : IEnumerable { private readonly CollisionList _collisions; @@ -298,7 +300,7 @@ namespace DCFApixels.DragonECS internal Collision(CollisionList collisions, int head, int count) { _collisions = collisions; - if(count == 0) + if (count == 0) { _head = 0; _metaID = string.Empty; @@ -346,8 +348,18 @@ namespace DCFApixels.DragonECS } } #endregion - } + #region DebuggerProxy + private class DebuggerProxy + { + public Type[] Types; + public DebuggerProxy(Collision collision) + { + Types = collision.Select(o => o.Type).ToArray(); + } + } + #endregion + } #region DebuggerProxy private class DebuggerProxy { diff --git a/src/DebugUtils/TypeMeta.cs b/src/DebugUtils/TypeMeta.cs index bdbb7d2..bca81fe 100644 --- a/src/DebugUtils/TypeMeta.cs +++ b/src/DebugUtils/TypeMeta.cs @@ -6,6 +6,7 @@ using DCFApixels.DragonECS.Internal; using DCFApixels.DragonECS.PoolsCore; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.Linq; #if DEBUG || !REFLECTION_DISABLED @@ -275,6 +276,7 @@ namespace DCFApixels.DragonECS return _metaID; } } + public bool IsHasMetaID() { return string.IsNullOrEmpty(MetaID) == false; } #endregion #region TypeCode @@ -381,7 +383,17 @@ namespace DCFApixels.DragonECS return false; #endif } - public static bool IsHasMeta(Type type) + public static bool TryGetCustomMeta(Type type, out TypeMeta meta) + { + if (IsHasCustomMeta(type)) + { + meta = type.ToMeta(); + return true; + } + meta = null; + return false; + } + public static bool IsHasCustomMeta(Type type) { #if DEBUG || !REFLECTION_DISABLED return CheckEcsMemener(type) || Attribute.GetCustomAttributes(type, typeof(EcsMetaAttribute), false).Length > 0; @@ -393,7 +405,7 @@ namespace DCFApixels.DragonECS public static bool IsHasMetaID(Type type) { #if DEBUG || !REFLECTION_DISABLED - return type.HasAttribute(); + return TryGetCustomMeta(type, out TypeMeta meta) && meta.IsHasMetaID(); #else EcsDebug.PrintWarning($"Reflection is not available, the {nameof(TypeMeta)}.{nameof(IsHasMetaID)} method does not work."); return false; @@ -449,6 +461,15 @@ namespace DCFApixels.DragonECS } #endregion + #region Obsolete + [Obsolete("Use TryGetCustomMeta(type)")] + [EditorBrowsable(EditorBrowsableState.Never)] + public static bool IsHasMeta(Type type) + { + return IsHasCustomMeta(type); + } + #endregion + #region MetaGenerator private static class MetaGenerator {