• Manual
  • Scripting API
Show / Hide Table of Contents
  • BinaryCharm.SemanticColorPalette
    • SCP_ColorId
    • SCP_IPaletteCore
    • SCP_Palette
    • SCP_Palette.eType
    • SCP_PaletteProvider
  • BinaryCharm.SemanticColorPalette.Colorers
    • SCP_AColorer
    • SCP_AColorer<T>
    • SCP_AColorerBase
    • SCP_AGradientColorer
    • SCP_AGraphicColorer
    • SCP_AMaterialColorer
    • SCP_AMaterialColorer<T>
    • SCP_AMaterialColorerBase
    • SCP_IColorer
    • SCP_IColorer<T>
    • SCP_IGradientAccessor
    • SCP_MaterialColorDef
  • BinaryCharm.SemanticColorPalette.Importers
    • SCP_AcoPaletteData
    • SCP_AndroidXmlPaletteData
    • SCP_APaletteData
    • SCP_AsePaletteData
    • SCP_GimpPaletteData
    • SCP_IPaletteDataProvider
    • SCP_KritaPaletteData
    • SCP_SvgPaletteData
  • BinaryCharm.SemanticColorPalette.Utils
    • SCP_ColorUtils
    • SCP_ImportUtils
    • SCP_Utils

Class SCP_Palette

Class representing a color palette suitable for usage in the system. A SCP_Palette is a named set of color definitions that can be created at runtime through code and exist only in memory, but in most cases it will be created through the Unity inspector and stored as a asset file by the Unity serialization system.

Inheritance
Object
SCP_Palette
Implements
SCP_IPaletteCore
Namespace: BinaryCharm.SemanticColorPalette
Assembly: cs.temp.dll.dll
Syntax
public class SCP_Palette : ScriptableObject, SCP_IPaletteCore

Methods

CreateByJsonData(String)

Factory method building a Palette from a JSON string using the default Unity deserialization of ScriptableObject data.

Declaration
public static SCP_Palette CreateByJsonData(string sJsonData)
Parameters
Type Name Description
String sJsonData

A JSON string representing a palette instance.

Returns
Type Description
SCP_Palette

A palette instance built deserializing the sJsonData input.

Remarks

Warning: there is no integrity check on the input string, it is user responsibility to pass valid data. In most common scenarios where a palette needs to be stored/retrieved through an external JSON file, consider using the utility methods SCP_Utils.SavePalette and SCP_Utils.LoadPalette .

CreateMain(String, Dictionary<String, Color>)

Factory method for building a SCP_Palette providing a string to use as palette name and, most importantly, a Dictionary<string, Color> holding the (colorName, colorValue) pairs that will characterize the created palette. The use of a Dictionary guarantees that the color names are unique, which makes them suitable to be used as readable identifiers. Additionally, each color name will be associated to a SCP_ColorId that will need to be retrieved by calling GetColorIdByName on the instantiated palette, and should be the preferred way to access a color definition.

Declaration
public static SCP_Palette CreateMain(string sName, Dictionary<string, Color> rColorDefs)
Parameters
Type Name Description
String sName

The name of the palette to be created.

Dictionary<String, Color> rColorDefs

The (colorName, colorValue) pairs that will define the palette entries

Returns
Type Description
SCP_Palette

A palette instance built according to the parameters.

Remarks

Calling this method is the proper way to create new "main" palettes through code. The number of color entries and the color names cannot be altered after creation, while it is possible to change the color values (by calling SetColor ).

CreateVariant(String, SCP_Palette)

Factory method to create a palette variant of rMainPalette named sName. The instantiated palette will be a copy of the main palette, to be subsequently modified by calling SetColor (for a single entry accessed by color id) or the utility method SCP_Utils.UpdateColorDefs (for multiple entries accessed by color name).

Declaration
public static SCP_Palette CreateVariant(string sName, SCP_Palette rMainPalette)
Parameters
Type Name Description
String sName

The name of the palette variant to be created.

SCP_Palette rMainPalette

The "main" palette of which the newly created palette will be variant.

Returns
Type Description
SCP_Palette

A palette variant instance initialized as a copy of rMainPalette

GetColor(SCP_ColorId)

Retrieves the color value associated to a color id, caring about performances. It's the method used by almost all colorers to retrieve colors.

Declaration
public Color GetColor(SCP_ColorId colorId)
Parameters
Type Name Description
SCP_ColorId colorId

Identifier of the color to retrieve.

Returns
Type Description
Color

The color associated to colorId

GetColorByIndex(Int32)

Fetches the color value of the i-th palette element.

Declaration
public Color GetColorByIndex(int iIndex)
Parameters
Type Name Description
Int32 iIndex

index of the element color to retrieve.

Returns
Type Description
Color

The color value of the i-th palette element.

Remarks

iIndex is expected to a be a valid value, between 0 and GetNumElems() - 1.

GetColorIdByIndex(Int32)

Fetches the color id of the i-th palette element.

Declaration
public SCP_ColorId GetColorIdByIndex(int iIndex)
Parameters
Type Name Description
Int32 iIndex

index of the element id to retrieve.

Returns
Type Description
SCP_ColorId

The color id of the i-th palette element.

Remarks

iIndex is expected to a be a valid value, between 0 and GetNumElems() - 1.

GetColorIdByName(String)

Retrieves the color id associated to a color name, useful especially when using the system through scripting (to retrieve color ids after creating a new palette instance).

Declaration
public SCP_ColorId GetColorIdByName(string sName)
Parameters
Type Name Description
String sName

Color name of which we want the associated color id.

Returns
Type Description
SCP_ColorId

The color id associated to sName

GetColorNameByIndex(Int32)

Fetches the color name of the i-th palette element.

Declaration
public string GetColorNameByIndex(int iIndex)
Parameters
Type Name Description
Int32 iIndex

index of the element name to retrieve

Returns
Type Description
String

The color name of the i-th palette element.

Remarks

iIndex is expected to a be a valid value, between 0 and GetNumElems() - 1.

GetMainPalette()

Retrieves a reference to the "main" palette of the instance. If the palette is not a palette variant, returns the palette itself.

Declaration
public SCP_Palette GetMainPalette()
Returns
Type Description
SCP_Palette

The "main" palette (if called on a palette variant) or the palette itself (if called on a main palette)

GetName()

Fetches the name of the palette. For palettes defined through the Unity Editor, it will match the asset filename.

Declaration
public string GetName()
Returns
Type Description
String

The mnemonic name of the palette instance.

GetNumElems()

Fetches the number of color entries in the palette.

Declaration
public int GetNumElems()
Returns
Type Description
Int32

The number of color entries in the palette.

GetStateTracker()

Returns a reference to the state tracking struct.

Declaration
public ref MutableStateTracker GetStateTracker()
Returns
Type Description
MutableStateTracker

A reference to the state tracking struct.

Remarks

Should never be used in normal application code. Only public to allow monitoring by custom extensions of SCP_PaletteProvider with no performance penalties.

SetColor(SCP_ColorId, Color)

Sets the color value associated to a color id, caring about performances.

Declaration
public void SetColor(SCP_ColorId colorId, Color color)
Parameters
Type Name Description
SCP_ColorId colorId

The identifier of the color value we want to change.

Color color

The color value we want to set.

Implements

SCP_IPaletteCore
In This Article
Back to top Binary Charm