mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
update auto name color
This commit is contained in:
parent
5ca6802ae9
commit
4b29ac61b9
@ -172,12 +172,11 @@ namespace DCFApixels.DragonECS
|
|||||||
public static MetaColor GetColor(Type type)
|
public static MetaColor GetColor(Type type)
|
||||||
{
|
{
|
||||||
var atr = type.GetCustomAttribute<MetaColorAttribute>();
|
var atr = type.GetCustomAttribute<MetaColorAttribute>();
|
||||||
return atr != null ? atr.color
|
return atr != null ? atr.color : AutoColor(type);
|
||||||
#if DEBUG //optimization for release build
|
}
|
||||||
: new MetaColor(type.Name);
|
private static MetaColor AutoColor(Type type)
|
||||||
#else
|
{
|
||||||
: MetaColor.BlackColor;
|
return new MetaColor(type.Name).Desaturate(0.45f) / 1.15f;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
public static bool TryGetColor(object obj, out MetaColor color)
|
public static bool TryGetColor(object obj, out MetaColor color)
|
||||||
{
|
{
|
||||||
|
@ -192,7 +192,7 @@ namespace DCFApixels.DragonECS
|
|||||||
colorCode ^= MAGIC_CONST;
|
colorCode ^= MAGIC_CONST;
|
||||||
colorCode = BitsUtility.NextXorShiftState(colorCode);
|
colorCode = BitsUtility.NextXorShiftState(colorCode);
|
||||||
this.colorCode = (int)colorCode | 255;
|
this.colorCode = (int)colorCode | 255;
|
||||||
this.colorCode = UpContrastColor().colorCode;
|
this.colorCode = UpContrast().colorCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -214,7 +214,18 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
public MetaColor UpContrastColor()
|
public MetaColor Desaturate(float t)
|
||||||
|
{
|
||||||
|
byte r = this.r;
|
||||||
|
byte g = this.g;
|
||||||
|
byte b = this.b;
|
||||||
|
byte gray = (byte)(r * 0.299 + g * 0.587 + b * 0.114);
|
||||||
|
r = (byte)(r + (gray - r) * (1 - t));
|
||||||
|
g = (byte)(g + (gray - g) * (1 - t));
|
||||||
|
b = (byte)(b + (gray - b) * (1 - t));
|
||||||
|
return new MetaColor(r, g, b);
|
||||||
|
}
|
||||||
|
public MetaColor UpContrast()
|
||||||
{
|
{
|
||||||
byte minChannel = Math.Min(Math.Min(r, g), b);
|
byte minChannel = Math.Min(Math.Min(r, g), b);
|
||||||
byte maxChannel = Math.Max(Math.Max(r, g), b);
|
byte maxChannel = Math.Max(Math.Max(r, g), b);
|
||||||
|
Loading…
Reference in New Issue
Block a user