Show / Hide Table of Contents

Class ByteColor

Fast 4 byte item variation of a color for efficient storage and operating inside chunk. Allows to store colors more efficiently for each chunk per 1000+ block each Good as we do not care about alpha, and has less memory that hex color storage.

Occupies 4 times less memory that regular color. So for min draw distance in eco it will be small 256kb overhead instead of 1mb of data. (loaded 8x8 chunk grid)

Inheritance
System.Object
ByteColor
Implements
IBsonSerialize
IBsonSerializable
IBsonDeserializable
Namespace: Eco.Shared.Utils
Assembly: Eco.Shared.dll
Syntax
[Serialized]
public sealed class ByteColor : ValueType, IBsonSerialize, IBsonSerializable, IBsonDeserializable

Constructors

ByteColor(Byte, Byte, Byte)

Declaration
public ByteColor(byte r, byte g, byte b)
Parameters
Type Name Description
System.Byte r
System.Byte g
System.Byte b

ByteColor(Byte, Byte, Byte, Byte)

Declaration
public ByteColor(byte r, byte g, byte b, byte a)
Parameters
Type Name Description
System.Byte r
System.Byte g
System.Byte b
System.Byte a

Fields

Clear

Declaration
public static ByteColor Clear
Field Value
Type Description
ByteColor

White

Declaration
public static ByteColor White
Field Value
Type Description
ByteColor

Properties

A

Declaration
[Serialized]
public byte A { get; }
Property Value
Type Description
System.Byte

B

Declaration
[Serialized]
public byte B { get; }
Property Value
Type Description
System.Byte

G

Declaration
[Serialized]
public byte G { get; }
Property Value
Type Description
System.Byte

HexRGB

Declaration
public string HexRGB { get; }
Property Value
Type Description
System.String

HexRGBA

Declaration
public string HexRGBA { get; }
Property Value
Type Description
System.String

R

Declaration
[Serialized]
public byte R { get; }
Property Value
Type Description
System.Byte

Methods

Clamped(Single, Single, Single)

Returns clamped byte color instance in [0-225] range, based on integer input

Declaration
public static ByteColor Clamped(float r, float g, float b)
Parameters
Type Name Description
System.Single r
System.Single g
System.Single b
Returns
Type Description
ByteColor

CompareHexRGB(String)

Compares 2 color hex values as string. Counts only for RGB, without alpha

Declaration
public bool CompareHexRGB(string hexString)
Parameters
Type Name Description
System.String hexString
Returns
Type Description
System.Boolean

Convert()

Converts Byte color to Eco.Shared.Color

Declaration
public Color Convert()
Returns
Type Description
Color

Distance(ByteColor)

Calculate the Euclidean distance between current color and target. Ignores Alpha.

Declaration
public float Distance(ByteColor c)
Parameters
Type Name Description
ByteColor c
Returns
Type Description
System.Single

Equals(Object)

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
System.Object obj
Returns
Type Description
System.Boolean

EqualsNoAlpha(ByteColor)

Declaration
public bool EqualsNoAlpha(ByteColor other)
Parameters
Type Name Description
ByteColor other
Returns
Type Description
System.Boolean

FromBson(BSONArray)

Declaration
public void FromBson(BSONArray bson)
Parameters
Type Name Description
BSONArray bson

FromHex(String)

Declaration
public static ByteColor FromHex(string hex)
Parameters
Type Name Description
System.String hex
Returns
Type Description
ByteColor

Get(Color)

Converts Eco.Shared.Utils.Color to ByteColor. Trims alpha and changes to byte.

Declaration
public static ByteColor Get(Color color)
Parameters
Type Name Description
Color color
Returns
Type Description
ByteColor

Get(Single, Single, Single, Single)

Declaration
public static ByteColor Get(float r, float g, float b, float a)
Parameters
Type Name Description
System.Single r
System.Single g
System.Single b
System.Single a
Returns
Type Description
ByteColor

GetHashCode()

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

GetHue()

Get hue value of byte color

Declaration
public float GetHue()
Returns
Type Description
System.Single

Lerp(ByteColor, Single)

Interpolates color towards another

Declaration
public ByteColor Lerp(ByteColor to, float t)
Parameters
Type Name Description
ByteColor to
System.Single t
Returns
Type Description
ByteColor

ToBson()

Declaration
public BSONArray ToBson()
Returns
Type Description
BSONArray

ValidateHex(String)

Tries to validate provided hex input, puts # if missing, returns white if bad format

Declaration
public static string ValidateHex(string hex)
Parameters
Type Name Description
System.String hex
Returns
Type Description
System.String

WithAlpha(Byte)

Returns new instance of byte color with target Alpha

Declaration
public ByteColor WithAlpha(byte coat)
Parameters
Type Name Description
System.Byte coat
Returns
Type Description
ByteColor

Operators

Addition(ByteColor, ByteColor)

Declaration
public static ByteColor operator +(ByteColor a, ByteColor b)
Parameters
Type Name Description
ByteColor a
ByteColor b
Returns
Type Description
ByteColor

Equality(ByteColor, ByteColor)

Declaration
public static bool operator ==(ByteColor left, ByteColor right)
Parameters
Type Name Description
ByteColor left
ByteColor right
Returns
Type Description
System.Boolean

Inequality(ByteColor, ByteColor)

Declaration
public static bool operator !=(ByteColor left, ByteColor right)
Parameters
Type Name Description
ByteColor left
ByteColor right
Returns
Type Description
System.Boolean

Multiply(ByteColor, Single)

Declaration
public static ByteColor operator *(ByteColor a, float b)
Parameters
Type Name Description
ByteColor a
System.Single b
Returns
Type Description
ByteColor

Implements

IBsonSerialize
IBsonSerializable
IBsonDeserializable

Extension Methods

CommandLine.FeedFromCommandLine(Object)
CommandLine.ToCommandLineArgs(Object, Func<Object, Boolean>)
ListUtil.DepthFirstTraversal<T>(T, Func<T, IEnumerable<T>>)
EnumerableExtensions.SingleItemAsEnumerable<T>(T)
EventUtils.RaiseEvent<TEventArgs>(Object, String, TEventArgs)
PredicateUtils.MatchesAll<TEnumerable, T>(T, TEnumerable)
PredicateUtils.MatchesAll<T>(T, Func<T, Boolean>[])
PredicateUtils.MatchesAny<TEnumerable, T>(T, TEnumerable)
ReflectionUtils.PropertyValue<T>(Object, PropertyInfo)
ReflectionUtils.TryGetPropertyValueByName<T>(Object, String, out T)
ReflectionUtils.GetPropertyValueByName<T>(Object, String)
ReflectionUtils.SetPropertyByName(Object, String, Object)
ReflectionUtils.GetStructPropertyByName<T>(Object, String)
ReflectionUtils.GetStringPropertyByName(Object, String)
ReflectionUtils.ZipByProperty<T>(Object, Object, Object, Func<T, T, T>)
☀
☾
In This Article
Back to top
Copyright (c) Strange Loop Games 2021
☀
☾