update meta attributes / add MetaID attribute

This commit is contained in:
Mikhail 2024-09-16 12:24:52 +08:00
parent 7d8a98b616
commit c970111f77
5 changed files with 101 additions and 19 deletions

View File

@ -0,0 +1,27 @@
using DCFApixels.DragonECS.Internal;
using System;
using System.Collections.Generic;
namespace DCFApixels.DragonECS
{
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class MetaIDAttribute : EcsMetaAttribute
{
private static HashSet<string> _ids;
public readonly string ID;
public MetaIDAttribute(string id)
{
if (string.IsNullOrEmpty(id))
{
Throw.ArgumentNull(nameof(id));
}
if (_ids.Add(id))
{
//TODO перевести ексепшен
Throw.ArgumentException($"Дублирование MetaID: {ID}");
}
ID = id;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 145ce3aab9f970b4a8c936e1adf5de95
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -23,16 +23,17 @@ namespace DCFApixels.DragonECS
_tags[i] = string.Intern(_tags[i]);
}
}
//public MetaTagsAttribute(string tag0, string tag1) : this($"{tag0},{tag1}") { }
//public MetaTagsAttribute(string tag0, string tag1, string tag2) : this($"{tag0},{tag1},{tag2}") { }
//public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3) : this($"{tag0},{tag1},{tag2},{tag3}") { }
//public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3, string tag4) : this($"{tag0},{tag1},{tag2},{tag3},{tag4}") { }
//public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3, string tag4, string tag5) : this($"{tag0},{tag1},{tag2},{tag3},{tag4},{tag5}") { }
public MetaTagsAttribute(string tag0, string tag1) : this($"{tag0},{tag1}") { }
public MetaTagsAttribute(string tag0, string tag1, string tag2) : this($"{tag0},{tag1},{tag2}") { }
public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3) : this($"{tag0},{tag1},{tag2},{tag3}") { }
public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3, string tag4) : this($"{tag0},{tag1},{tag2},{tag3},{tag4}") { }
public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3, string tag4, string tag5) : this($"{tag0},{tag1},{tag2},{tag3},{tag4},{tag5}") { }
public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3, string tag4, string tag5, string tag6) : this($"{tag0},{tag1},{tag2},{tag3},{tag4},{tag5},{tag6}") { }
public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3, string tag4, string tag5, string tag6, string tag7) : this($"{tag0},{tag1},{tag2},{tag3},{tag4},{tag5},{tag6},{tag7}") { }
public MetaTagsAttribute(params string[] tags) : this(string.Join(SEPARATOR, tags)) { }
}
public readonly ref struct MetaTags
{
public const string HIDDEN = EcsConsts.META_HIDDEN_TAG;
//private static string[] _tags = new string[64];
}
}

View File

@ -17,7 +17,7 @@ namespace DCFApixels.DragonECS
MetaDescription Description { get; }
MetaGroup Group { get; }
IReadOnlyList<string> Tags { get; }
//string MetaID { get; }
ITypeMeta BaseMeta { get; }
}
public static class ITypeMetaExstensions
@ -51,6 +51,7 @@ namespace DCFApixels.DragonECS
private MetaDescription _description;
private MetaGroup _group;
private IReadOnlyList<string> _tags;
private string _metaID;
private int _typeCode;
private InitFlag _initFlags = InitFlag.None;
@ -218,6 +219,25 @@ namespace DCFApixels.DragonECS
}
#endregion
#region MetaID
private void InitMetaID()
{
if (_initFlags.HasFlag(InitFlag.MetaID) == false)
{
_metaID = MetaGenerator.GetMetaID(_type);
_initFlags |= InitFlag.MetaID;
}
}
public string MetaID
{
get
{
InitMetaID();
return _metaID;
}
}
#endregion
#region TypeCode
public int TypeCode
{
@ -243,6 +263,7 @@ namespace DCFApixels.DragonECS
_ = Color;
_ = Description;
_ = Tags;
_ = MetaID;
_ = TypeCode;
}
return this;
@ -259,10 +280,11 @@ namespace DCFApixels.DragonECS
Color = 1 << 2,
Description = 1 << 3,
Tags = 1 << 4,
TypeCode = 1 << 5,
MemberType = 1 << 6,
MetaID = 1 << 5,
TypeCode = 1 << 6,
//MemberType = 1 << 7,
All = Name | Group | Color | Description | Tags | TypeCode | MemberType
All = Name | Group | Color | Description | Tags | TypeCode | MetaID //| MemberType
}
#endregion
@ -307,6 +329,10 @@ namespace DCFApixels.DragonECS
{
get { return _meta.Tags; }
}
public string MetaID
{
get { return _meta.MetaID; }
}
public DebuggerProxy(TypeMeta meta)
{
_meta = meta;
@ -411,6 +437,19 @@ namespace DCFApixels.DragonECS
#else
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetTags)} method does not work.");
return Array.Empty<string>();
#endif
}
#endregion
#region GetMetaID
public static string GetMetaID(Type type)
{
#if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает
var atr = type.GetCustomAttribute<MetaIDAttribute>();
return atr != null ? atr.ID : string.Empty;
#else
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetTags)} method does not work.");
return string.Empty;
#endif
}
#endregion
@ -418,12 +457,12 @@ namespace DCFApixels.DragonECS
#endregion
}
public enum EcsMemberType : byte
{
Undefined = 0,
Component = 1,
System = 2,
Other = 3,
}
//public enum EcsMemberType : byte
//{
// Undefined = 0,
//
// Component = 1,
// System = 2,
// Other = 3,
//}
}

View File

@ -154,7 +154,11 @@ namespace DCFApixels.DragonECS.Internal
{
throw new Exception(message);
}
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void ArgumentException(string message)
{
throw new ArgumentException(message);
}
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void Aspect_CanOnlyBeUsedDuringInitialization(string methodName)