ColorPicker

ColorPicker

Paintcraft does NOT have color picker inside, so first what you need to do is to write color picker by yourself or find it on asset store or github.

In this Receipt we will take free picker by @zloedi from github cui_color_picker, So you can download this package and import in to your project.

Custom Script which will listen color picker change

You need to implement simple script which will listen color picker changes.

Create File SetColorFromColorPicker.cs

using NUnit.Framework;
using PaintCraft.Tools;
using UnityEngine;
[RequireComponent(typeof(CUIColorPicker))]
public class SetColorFromColorPicker : MonoBehaviour
{
public LineConfig LineConfig;
private CUIColorPicker _colorPicker;
void Start()
{
Assert.IsNotNull(LineConfig, "LineConfig must be set");
_colorPicker = GetComponent<CUIColorPicker>();
Assert.IsNotNull(_colorPicker);
_colorPicker.SetOnValueChangeCallback(color => LineConfig.Color.Color = color);
}
}

and add it to the same game object as CUI Color picker. After that set up line config reference

that's it., When you change color on picker it will be assigned to the LineConfig.

Additional Info

CUI Color Picker is not properly tested, so please make sure that you checked and you don't have memory leacks. If you do please change _onValueChangevariable to public and subscribe/unsubscribe to this even in OnEnable/OnDisable methods at your SetColorFromColorPicker file like

using NUnit.Framework;
using PaintCraft.Tools;
using UnityEngine;
[RequireComponent(typeof(CUIColorPicker))]
public class SetColorFromColorPicker : MonoBehaviour
{
public LineConfig LineConfig;
private CUIColorPicker _colorPicker;
void Start()
{
Assert.IsNotNull(LineConfig, "LineConfig must be set");
_colorPicker = GetComponent<CUIColorPicker>();
Assert.IsNotNull(_colorPicker);
}
void OnEnable()
{
_colorPicker._onValueChange += OnColorChanged;
}
void OnDisable()
{
_colorPicker._onValueChange -= OnColorChanged;
}
private void OnColorChanged(Color color)
{
LineConfig.Color.Color = color;
}
}