mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
add auto-generation MetaColor from MetaGroup
This commit is contained in:
parent
49fd84cea0
commit
bfb16585fb
@ -232,16 +232,17 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
this.colorCode = withoutAlpha ? colorCode | 255 : colorCode;
|
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
|
unchecked
|
||||||
{
|
{
|
||||||
const uint MAGIC_CONST = 0xA638_783E;
|
uint colorCode = (uint)hash;
|
||||||
uint colorCode = (uint)stringCode.GetHashCode();
|
|
||||||
colorCode ^= MAGIC_CONST;
|
|
||||||
colorCode = BitsUtility.NextXorShiftState(colorCode);
|
colorCode = BitsUtility.NextXorShiftState(colorCode);
|
||||||
this.colorCode = (uint)colorCode | 255;
|
return new MetaColor(colorCode, withoutAlpha);
|
||||||
this.colorCode = UpContrast().colorCode;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -6,8 +6,6 @@ using System.Text.RegularExpressions;
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
using static MetaGroupAttribute;
|
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
|
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
|
||||||
public sealed class MetaGroupAttribute : EcsMetaAttribute
|
public sealed class MetaGroupAttribute : EcsMetaAttribute
|
||||||
{
|
{
|
||||||
@ -22,6 +20,7 @@ namespace DCFApixels.DragonECS
|
|||||||
[DebuggerDisplay("{Name}")]
|
[DebuggerDisplay("{Name}")]
|
||||||
public class MetaGroup
|
public class MetaGroup
|
||||||
{
|
{
|
||||||
|
public const char SEPARATOR = MetaGroupAttribute.SEPARATOR;
|
||||||
public const string UNGROUPED = "<UNGROUPED>";
|
public const string UNGROUPED = "<UNGROUPED>";
|
||||||
private const string PATTERN = @"Module(?=/)";
|
private const string PATTERN = @"Module(?=/)";
|
||||||
public static readonly MetaGroup Empty = new MetaGroup(UNGROUPED);
|
public static readonly MetaGroup Empty = new MetaGroup(UNGROUPED);
|
||||||
@ -39,6 +38,10 @@ namespace DCFApixels.DragonECS
|
|||||||
return _path;
|
return _path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public bool IsEmpty
|
||||||
|
{
|
||||||
|
get { return this == Empty; }
|
||||||
|
}
|
||||||
public MetaGroup(string name)
|
public MetaGroup(string name)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(name))
|
if (string.IsNullOrEmpty(name))
|
||||||
|
@ -153,7 +153,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
if (_initFlags.HasFlag(InitFlag.Color) == false)
|
if (_initFlags.HasFlag(InitFlag.Color) == false)
|
||||||
{
|
{
|
||||||
(_color, _isCustomColor) = MetaGenerator.GetColor(_type);
|
(_color, _isCustomColor) = MetaGenerator.GetColor(this);
|
||||||
_initFlags |= InitFlag.Color;
|
_initFlags |= InitFlag.Color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -406,15 +406,6 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
private const int GENERIC_NAME_DEPTH = 3;
|
private const int GENERIC_NAME_DEPTH = 3;
|
||||||
|
|
||||||
//private static HashSet<Type> _;
|
|
||||||
|
|
||||||
//#region GetMemberType
|
|
||||||
//public static EcsMemberType GetMemberType(Type type)
|
|
||||||
//{
|
|
||||||
// throw new NotImplementedException();
|
|
||||||
//}
|
|
||||||
//#endregion
|
|
||||||
|
|
||||||
#region GetMetaName/GetTypeName
|
#region GetMetaName/GetTypeName
|
||||||
public static string GetTypeName(Type type)
|
public static string GetTypeName(Type type)
|
||||||
{
|
{
|
||||||
@ -448,15 +439,25 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetColor
|
#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 только в релизном билде работает
|
#if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает
|
||||||
bool isCustom = type.TryGetAttribute(out MetaColorAttribute atr);
|
bool isCustom = meta.Type.TryGetAttribute(out MetaColorAttribute atr);
|
||||||
return (isCustom ? atr.color : AutoColor(type), isCustom);
|
return (isCustom ? atr.color : AutoColor(meta), isCustom);
|
||||||
#else
|
#else
|
||||||
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetColor)} method does not work.");
|
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetColor)} method does not work.");
|
||||||
return (AutoColor(type), false);
|
return (AutoColor(type), false);
|
||||||
|
Loading…
Reference in New Issue
Block a user