diff --git a/src/DebugUtils/MetaAttributes/MetaColorAttribute.cs b/src/DebugUtils/MetaAttributes/MetaColorAttribute.cs index 507ae0d..1c9a54e 100644 --- a/src/DebugUtils/MetaAttributes/MetaColorAttribute.cs +++ b/src/DebugUtils/MetaAttributes/MetaColorAttribute.cs @@ -232,16 +232,17 @@ namespace DCFApixels.DragonECS { this.colorCode = withoutAlpha ? colorCode | 255 : colorCode; } - public MetaColor(string stringCode) : this() + public static MetaColor FromHashCode(int hash) + { + return FromHashCode(hash, false); + } + public static MetaColor FromHashCode(int hash, bool withoutAlpha) { unchecked { - const uint MAGIC_CONST = 0xA638_783E; - uint colorCode = (uint)stringCode.GetHashCode(); - colorCode ^= MAGIC_CONST; + uint colorCode = (uint)hash; colorCode = BitsUtility.NextXorShiftState(colorCode); - this.colorCode = (uint)colorCode | 255; - this.colorCode = UpContrast().colorCode; + return new MetaColor(colorCode, withoutAlpha); } } #endregion diff --git a/src/DebugUtils/MetaAttributes/MetaGroupAttribute.cs b/src/DebugUtils/MetaAttributes/MetaGroupAttribute.cs index a82f4c6..3a548b8 100644 --- a/src/DebugUtils/MetaAttributes/MetaGroupAttribute.cs +++ b/src/DebugUtils/MetaAttributes/MetaGroupAttribute.cs @@ -6,8 +6,6 @@ using System.Text.RegularExpressions; namespace DCFApixels.DragonECS { - using static MetaGroupAttribute; - [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] public sealed class MetaGroupAttribute : EcsMetaAttribute { @@ -22,6 +20,7 @@ namespace DCFApixels.DragonECS [DebuggerDisplay("{Name}")] public class MetaGroup { + public const char SEPARATOR = MetaGroupAttribute.SEPARATOR; public const string UNGROUPED = ""; private const string PATTERN = @"Module(?=/)"; public static readonly MetaGroup Empty = new MetaGroup(UNGROUPED); @@ -39,6 +38,10 @@ namespace DCFApixels.DragonECS return _path; } } + public bool IsEmpty + { + get { return this == Empty; } + } public MetaGroup(string name) { if (string.IsNullOrEmpty(name)) diff --git a/src/DebugUtils/TypeMeta.cs b/src/DebugUtils/TypeMeta.cs index be43d27..20aca4b 100644 --- a/src/DebugUtils/TypeMeta.cs +++ b/src/DebugUtils/TypeMeta.cs @@ -153,7 +153,7 @@ namespace DCFApixels.DragonECS { if (_initFlags.HasFlag(InitFlag.Color) == false) { - (_color, _isCustomColor) = MetaGenerator.GetColor(_type); + (_color, _isCustomColor) = MetaGenerator.GetColor(this); _initFlags |= InitFlag.Color; } } @@ -406,15 +406,6 @@ namespace DCFApixels.DragonECS { private const int GENERIC_NAME_DEPTH = 3; - //private static HashSet _; - - //#region GetMemberType - //public static EcsMemberType GetMemberType(Type type) - //{ - // throw new NotImplementedException(); - //} - //#endregion - #region GetMetaName/GetTypeName public static string GetTypeName(Type type) { @@ -448,15 +439,25 @@ namespace DCFApixels.DragonECS #endregion #region GetColor - private static MetaColor AutoColor(Type type) + + private static MetaColor AutoColor(TypeMeta meta) { - return new MetaColor(type.Name).UpContrast();//.Desaturate(0.48f) / 1.18f; + int hash; + if (meta.Group.IsEmpty) + { + hash = meta.Type.Name.GetHashCode(); + } + else + { + hash = meta.Group.Name.GetHashCode(); + } + return MetaColor.FromHashCode(hash).UpContrast(); } - public static (MetaColor, bool) GetColor(Type type) + public static (MetaColor, bool) GetColor(TypeMeta meta) { #if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает - bool isCustom = type.TryGetAttribute(out MetaColorAttribute atr); - return (isCustom ? atr.color : AutoColor(type), isCustom); + bool isCustom = meta.Type.TryGetAttribute(out MetaColorAttribute atr); + return (isCustom ? atr.color : AutoColor(meta), isCustom); #else EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetColor)} method does not work."); return (AutoColor(type), false);