update metaID

This commit is contained in:
DCFApixels 2025-03-20 10:55:43 +08:00
parent d1a874e62e
commit 78b49e3f7b
2 changed files with 41 additions and 8 deletions

View File

@ -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<CollisionList.Collision>
{
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<TypeMeta>
{
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
{

View File

@ -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<MetaIDAttribute>();
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
{