diff --git a/src/Debug/EcsDebugUtility.cs b/src/Debug/EcsDebugUtility.cs index ed89bd9..8a6d87c 100644 --- a/src/Debug/EcsDebugUtility.cs +++ b/src/Debug/EcsDebugUtility.cs @@ -31,7 +31,6 @@ namespace DCFApixels.DragonECS } private static string GetGenericTypeNameInternal(Type type, int maxDepth, bool isFull) { -#if (DEBUG && !DISABLE_DEBUG) string typeName = isFull ? type.FullName : type.Name; if (!type.IsGenericType || maxDepth == 0) { @@ -52,9 +51,6 @@ namespace DCFApixels.DragonECS genericParams += (i == 0 ? paramTypeName : $", {paramTypeName}"); } return $"{typeName}<{genericParams}>"; -#else //optimization for release build - return isFull ? type.FullName : type.Name; -#endif } #endregion @@ -354,7 +350,7 @@ namespace DCFApixels.DragonECS { if (_initFlags.HasFlag(InitFlag.Name) == false) { - (_name, _isCustomName) = MetaCacheGenerator.GetName(_type); + (_name, _isCustomName) = MetaGenerator.GetMetaName(_type); _initFlags |= InitFlag.Name; } } @@ -381,7 +377,7 @@ namespace DCFApixels.DragonECS { if (_initFlags.HasFlag(InitFlag.Color) == false) { - (_color, _isCustomColor) = MetaCacheGenerator.GetColor(_type); + (_color, _isCustomColor) = MetaGenerator.GetColor(_type); _initFlags |= InitFlag.Color; } } @@ -410,7 +406,7 @@ namespace DCFApixels.DragonECS { if (_initFlags.HasFlag(InitFlag.Description) == false) { - _description = MetaCacheGenerator.GetDescription(_type); + _description = MetaGenerator.GetDescription(_type); _initFlags |= InitFlag.Description; } return _description; @@ -425,7 +421,7 @@ namespace DCFApixels.DragonECS { if (_initFlags.HasFlag(InitFlag.Group) == false) { - _group = MetaCacheGenerator.GetGroup(_type); + _group = MetaGenerator.GetGroup(_type); _initFlags |= InitFlag.Group; } return _group; @@ -438,7 +434,7 @@ namespace DCFApixels.DragonECS { if (_initFlags.HasFlag(InitFlag.Tags) == false) { - _tags = MetaCacheGenerator.GetTags(_type); + _tags = MetaGenerator.GetTags(_type); _initFlags |= InitFlag.Tags; _isHidden = _tags.Contains(MetaTags.HIDDEN); } @@ -542,6 +538,71 @@ namespace DCFApixels.DragonECS } } #endregion + + #region MetaGenerator + private static class MetaGenerator + { + private const int GENERIC_NAME_DEPTH = 3; + + #region GetMetaName + public static (string, bool) GetMetaName(Type type) + { + bool isCustom = type.TryGetCustomAttribute(out MetaNameAttribute atr) && string.IsNullOrEmpty(atr.name) == false; + if (isCustom) + { + if ((type.IsGenericType && atr.isHideGeneric == false) == false) + { + return (atr.name, isCustom); + } + string genericParams = ""; + Type[] typeParameters = type.GetGenericArguments(); + for (int i = 0; i < typeParameters.Length; ++i) + { + string paramTypeName = EcsDebugUtility.GetGenericTypeName(typeParameters[i], GENERIC_NAME_DEPTH); + genericParams += (i == 0 ? paramTypeName : $", {paramTypeName}"); + } + return ($"{atr.name}<{genericParams}>", isCustom); + } + return (EcsDebugUtility.GetGenericTypeName(type, GENERIC_NAME_DEPTH), isCustom); + } + #endregion + + #region GetColor + private static MetaColor AutoColor(Type type) + { + return new MetaColor(type.Name).Desaturate(0.48f) / 1.18f; + } + public static (MetaColor, bool) GetColor(Type type) + { + bool isCustom = type.TryGetCustomAttribute(out MetaColorAttribute atr); + return (isCustom ? atr.color : AutoColor(type), isCustom); + } + #endregion + + #region GetGroup + public static MetaGroup GetGroup(Type type) + { + return type.TryGetCustomAttribute(out MetaGroupAttribute atr) ? atr.Data : MetaGroup.Empty; + } + #endregion + + #region GetDescription + public static string GetDescription(Type type) + { + bool isCustom = type.TryGetCustomAttribute(out MetaDescriptionAttribute atr); + return isCustom ? atr.description : string.Empty; + } + #endregion + + #region GetTags + public static IReadOnlyCollection GetTags(Type type) + { + var atr = type.GetCustomAttribute(); + return atr != null ? atr.Tags : Array.Empty(); + } + #endregion + } + #endregion } public static class TypeMetaDataCachedExtensions @@ -555,55 +616,4 @@ namespace DCFApixels.DragonECS return EcsDebugUtility.GetTypeMeta(self); } } -} - -namespace DCFApixels.DragonECS.Internal -{ - internal static class MetaCacheGenerator - { - private const int GENERIC_NAME_DEPTH = 2; - - #region GetName - public static (string, bool) GetName(Type type) - { - bool isCustom = type.TryGetCustomAttribute(out MetaNameAttribute atr) && string.IsNullOrEmpty(atr.name) == false; - return (isCustom ? atr.name : EcsDebugUtility.GetGenericTypeName(type, GENERIC_NAME_DEPTH), isCustom); - } - #endregion - - #region GetColor - private static MetaColor AutoColor(Type type) - { - return new MetaColor(type.Name).Desaturate(0.48f) / 1.18f; - } - public static (MetaColor, bool) GetColor(Type type) - { - bool isCustom = type.TryGetCustomAttribute(out MetaColorAttribute atr); - return (isCustom ? atr.color : AutoColor(type), isCustom); - } - #endregion - - #region GetGroup - public static MetaGroup GetGroup(Type type) - { - return type.TryGetCustomAttribute(out MetaGroupAttribute atr) ? atr.Data : MetaGroup.Empty; - } - #endregion - - #region GetDescription - public static string GetDescription(Type type) - { - bool isCustom = type.TryGetCustomAttribute(out MetaDescriptionAttribute atr); - return isCustom ? atr.description : string.Empty; - } - #endregion - - #region GetTags - public static IReadOnlyCollection GetTags(Type type) - { - var atr = type.GetCustomAttribute(); - return atr != null ? atr.Tags : Array.Empty(); - } - #endregion - } } \ No newline at end of file diff --git a/src/Debug/MetaAttributes/MetaDescriptionAttribute.cs b/src/Debug/MetaAttributes/MetaDescriptionAttribute.cs index a5327d6..3260cc8 100644 --- a/src/Debug/MetaAttributes/MetaDescriptionAttribute.cs +++ b/src/Debug/MetaAttributes/MetaDescriptionAttribute.cs @@ -6,6 +6,9 @@ namespace DCFApixels.DragonECS public sealed class MetaDescriptionAttribute : EcsMetaAttribute { public readonly string description; - public MetaDescriptionAttribute(string description) => this.description = description; + public MetaDescriptionAttribute(string description) + { + this.description = description; + } } } diff --git a/src/Debug/MetaAttributes/MetaNameAttribute.cs b/src/Debug/MetaAttributes/MetaNameAttribute.cs index 449ad35..47b4a65 100644 --- a/src/Debug/MetaAttributes/MetaNameAttribute.cs +++ b/src/Debug/MetaAttributes/MetaNameAttribute.cs @@ -6,6 +6,11 @@ namespace DCFApixels.DragonECS public sealed class MetaNameAttribute : EcsMetaAttribute { public readonly string name; - public MetaNameAttribute(string name) => this.name = name; + public readonly bool isHideGeneric; + public MetaNameAttribute(string name, bool isHideGeneric = false) + { + this.name = name; + this.isHideGeneric = isHideGeneric; + } } }