Class UITKColorPicker
UI Toolkit color picker supporting an HSV picking texture plus H/S/V and R/G/B/A sliders, inputs and a hex field. Spectrum textures are generated via TinyColor and bound to element background images.
public class UITKColorPicker : UITKControl
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourUITKColorPicker
- Inherited Members
-
MonoBehaviour.IsInvoking()MonoBehaviour.CancelInvoke()MonoBehaviour.StopCoroutine(Coroutine)MonoBehaviour.StopAllCoroutines()MonoBehaviour.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.GetComponent<T>()Component.TryGetComponent<T>(out T)Component.GetComponentInChildren<T>()Component.GetComponentsInChildren<T>()Component.GetComponentInParent<T>()Component.GetComponentsInParent<T>()Component.GetComponents<T>()Component.GetComponentIndex()Component.CompareTag(TagHandle)Component.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.GetEntityId()Object.GetInstanceID()Object.GetHashCode()Object.InstantiateAsync<T>(T)Object.InstantiateAsync<T>(T, Transform)Object.InstantiateAsync<T>(T, Vector3, Quaternion)Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion, Transform)Object.Instantiate(Object)Object.Instantiate(Object, Scene)Object.Instantiate<T>(T, InstantiateParameters)Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)Object.Instantiate(Object, Transform)Object.Instantiate<T>(T)Object.Instantiate<T>(T, Vector3, Quaternion)Object.Instantiate<T>(T, Vector3, Quaternion, Transform)Object.Instantiate<T>(T, Transform)Object.Destroy(Object)Object.DestroyImmediate(Object)Object.DontDestroyOnLoad(Object)Object.DestroyObject(Object)Object.FindObjectsOfType<T>()Object.FindObjectsByType<T>(FindObjectsSortMode)Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)Object.FindObjectOfType<T>()Object.FindFirstObjectByType<T>()Object.FindAnyObjectByType<T>()Object.FindFirstObjectByType<T>(FindObjectsInactive)Object.FindAnyObjectByType<T>(FindObjectsInactive)Object.FindObjectsByType<T>()Object.FindObjectsByType<T>(FindObjectsInactive)Object.ToString()Object.nameObject.hideFlags
Fields
HSV_TEXTURE_HEIGHT
Height of HSV texture in pixels.
public const int HSV_TEXTURE_HEIGHT = 192
Field Value
HSV_TEXTURE_WIDTH
Width of HSV texture in pixels.
public const int HSV_TEXTURE_WIDTH = 192
Field Value
HUE_MAX
Maximum hue value (359).
public const int HUE_MAX = 359
Field Value
InitialColor
Initial color for the picker.
public Color InitialColor
Field Value
- Color
NUM_HUES
Number of hue values supported (degrees).
public const int NUM_HUES = 360
Field Value
OnColorChanged
Callback invoked whenever the selected color changes. Consumers should assign this before calling Show() to receive updates.
public Action<Color> OnColorChanged
Field Value
- Action<Color>
RGBA_MAX
Maximum RGBA value (255).
public const int RGBA_MAX = 255
Field Value
SLIDER_BACKGROUND_HEIGHT
Height of slider backgrounds in pixels.
public const int SLIDER_BACKGROUND_HEIGHT = 1
Field Value
SLIDER_BACKGROUND_WIDTH
Width of slider backgrounds in pixels.
public const int SLIDER_BACKGROUND_WIDTH = 134
Field Value
SV_MAX
Maximum saturation/value (100).
public const int SV_MAX = 100
Field Value
Properties
Layer
Draw order tier for this panel. See UITKPanelLayer.
protected override UITKPanelLayer Layer { get; }
Property Value
Methods
Hide(bool)
Hides the picker and stops reporting changes to whoever opened it.
public override void Hide(bool overrideIsAlwaysOpen)
Parameters
overrideIsAlwaysOpenboolWhen true, the call is a no-op.
Remarks
The override is on Hide(bool), not on Hide(). Hide() forwards
here, but quit-to-login calls Hide(false) directly — so an override on the
parameterless form alone left the Options panel still subscribed to colour changes
after the player had returned to the login screen.
OnAfterShow()
Re-applies the picker's colour to the tree the player will actually see.
protected override void OnAfterShow()
OnAfterStarting()
Re-binds the textures and re-applies the colour after a visual tree rebuild.
protected override void OnAfterStarting()
Remarks
The strips survive the rebuild but the elements they were bound to do not, so a re-shown picker came back with no spectrum behind any of its sliders.
OnDestroying()
Releases every texture and any outstanding pointer capture.
public override void OnDestroying()
OnStarting()
Resolves elements, configures sliders, wires callbacks and applies the initial color.
public override void OnStarting()
Open(Color, Action<Color>)
Shows the picker seeded with a colour, reporting each change to one caller.
public void Open(Color initial, Action<Color> onChanged)
Parameters
initialColorColour to start from.
onChangedAction<Color>Invoked with the selected colour as it changes.
Remarks
The picker is a single shared panel, so OnColorChanged is a field that every caller writes to in turn. Assigning it directly means whoever opened the picker last silently keeps receiving colours after they are done with it — this replaces the subscriber outright on each open, so exactly one caller is ever listening.
SetColor(Color)
Sets the picker color and refreshes all sliders, inputs, backgrounds and the cursor.
public void SetColor(Color color)
Parameters
colorColorThe color to set.
SetCursor()
Positions the HSV cursor from the current color's saturation/value.
public void SetCursor()
UpdateAlphaInputValue(int)
Updates the alpha channel from the input field and refreshes the color.
public void UpdateAlphaInputValue(int value)
Parameters
valueint
UpdateAlphaSliderValue(float)
Updates the alpha channel from the slider and refreshes the color.
public void UpdateAlphaSliderValue(float value)
Parameters
valuefloat
UpdateBlueInputValue(int)
Updates the blue channel from the input field and refreshes the color.
public void UpdateBlueInputValue(int value)
Parameters
valueint
UpdateBlueSliderValue(float)
Updates the blue channel from the slider and refreshes the color.
public void UpdateBlueSliderValue(float value)
Parameters
valuefloat
UpdateGreenInputValue(int)
Updates the green channel from the input field and refreshes the color.
public void UpdateGreenInputValue(int value)
Parameters
valueint
UpdateGreenSliderValue(float)
Updates the green channel from the slider and refreshes the color.
public void UpdateGreenSliderValue(float value)
Parameters
valuefloat
UpdateHexValue(string)
Updates the picker color from a hexadecimal string.
public void UpdateHexValue(string value)
Parameters
valuestringThe hexadecimal color string.
UpdateHueInputValue(int)
Updates the hue from the input field and refreshes the color.
public void UpdateHueInputValue(int value)
Parameters
valueint
UpdateHueSliderValue(float)
Updates the hue from the slider and refreshes the color.
public void UpdateHueSliderValue(float value)
Parameters
valuefloat
UpdateRedInputValue(int)
Updates the red channel from the input field and refreshes the color.
public void UpdateRedInputValue(int value)
Parameters
valueint
UpdateRedSliderValue(float)
Updates the red channel from the slider and refreshes the color.
public void UpdateRedSliderValue(float value)
Parameters
valuefloat
UpdateSaturationInputValue(int)
Updates the saturation from the input field and refreshes the color.
public void UpdateSaturationInputValue(int value)
Parameters
valueint
UpdateSaturationSliderValue(float)
Updates the saturation from the slider and refreshes the color.
public void UpdateSaturationSliderValue(float value)
Parameters
valuefloat
UpdateValueInputValue(int)
Updates the value (brightness) from the input field and refreshes the color.
public void UpdateValueInputValue(int value)
Parameters
valueint
UpdateValueSliderValue(float)
Updates the value (brightness) from the slider and refreshes the color.
public void UpdateValueSliderValue(float value)
Parameters
valuefloat