You've already forked FateViewer
Add project files.
This commit is contained in:
5
Assets/Scripts/HSVPicker/Editor.meta
Normal file
5
Assets/Scripts/HSVPicker/Editor.meta
Normal file
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a9e9df3c14e9034eb587348635c8f09
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
||||
65
Assets/Scripts/HSVPicker/Editor/BoxSliderEditor.cs
Normal file
65
Assets/Scripts/HSVPicker/Editor/BoxSliderEditor.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UI;
|
||||
|
||||
namespace HSVPicker.Editors
|
||||
{
|
||||
[CustomEditor(typeof(BoxSlider), true)]
|
||||
[CanEditMultipleObjects]
|
||||
public class BoxSliderEditor : SelectableEditor
|
||||
{
|
||||
|
||||
SerializedProperty m_HandleRect;
|
||||
SerializedProperty m_MinValue;
|
||||
SerializedProperty m_MaxValue;
|
||||
SerializedProperty m_WholeNumbers;
|
||||
SerializedProperty m_Value;
|
||||
SerializedProperty m_ValueY;
|
||||
SerializedProperty m_OnValueChanged;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
m_HandleRect = serializedObject.FindProperty("m_HandleRect");
|
||||
|
||||
m_MinValue = serializedObject.FindProperty("m_MinValue");
|
||||
m_MaxValue = serializedObject.FindProperty("m_MaxValue");
|
||||
m_WholeNumbers = serializedObject.FindProperty("m_WholeNumbers");
|
||||
m_Value = serializedObject.FindProperty("m_Value");
|
||||
m_ValueY = serializedObject.FindProperty("m_ValueY");
|
||||
m_OnValueChanged = serializedObject.FindProperty("m_OnValueChanged");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
EditorGUILayout.Space();
|
||||
|
||||
serializedObject.Update();
|
||||
|
||||
EditorGUILayout.PropertyField(m_HandleRect);
|
||||
|
||||
if (m_HandleRect.objectReferenceValue != null)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
|
||||
EditorGUILayout.PropertyField(m_MinValue);
|
||||
EditorGUILayout.PropertyField(m_MaxValue);
|
||||
EditorGUILayout.PropertyField(m_WholeNumbers);
|
||||
EditorGUILayout.Slider(m_Value, m_MinValue.floatValue, m_MaxValue.floatValue);
|
||||
EditorGUILayout.Slider(m_ValueY, m_MinValue.floatValue, m_MaxValue.floatValue);
|
||||
|
||||
// Draw the event notification options
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.PropertyField(m_OnValueChanged);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.HelpBox("Specify a RectTransform for the slider fill or the slider handle or both. Each must have a parent RectTransform that it can slide within.", MessageType.Info);
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Scripts/HSVPicker/Editor/BoxSliderEditor.cs.meta
Normal file
12
Assets/Scripts/HSVPicker/Editor/BoxSliderEditor.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8701e045b26e51f4eb345f2ccb3c13f5
|
||||
timeCreated: 1426804458
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Scripts/HSVPicker/Editor/HSVPicker.Editors.asmdef
Normal file
17
Assets/Scripts/HSVPicker/Editor/HSVPicker.Editors.asmdef
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "HSVPicker.Editors",
|
||||
"references": [
|
||||
"HSVPicker"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 485edc8694d264a8fb6d3a830531425d
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Scripts/HSVPicker/Enums.meta
Normal file
9
Assets/Scripts/HSVPicker/Enums.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d3904d3d18ddd544820bd8518990fee
|
||||
folderAsset: yes
|
||||
timeCreated: 1442586617
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Scripts/HSVPicker/Enums/ColorValues.cs
Normal file
13
Assets/Scripts/HSVPicker/Enums/ColorValues.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
public enum ColorValues
|
||||
{
|
||||
R,
|
||||
G,
|
||||
B,
|
||||
A,
|
||||
|
||||
Hue,
|
||||
Saturation,
|
||||
Value
|
||||
}
|
||||
12
Assets/Scripts/HSVPicker/Enums/ColorValues.cs.meta
Normal file
12
Assets/Scripts/HSVPicker/Enums/ColorValues.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 859a1720e083e504cb68917f781e87c7
|
||||
timeCreated: 1442586608
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Scripts/HSVPicker/Events.meta
Normal file
9
Assets/Scripts/HSVPicker/Events.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6bb0d49c64210014e9a24ed9345928c2
|
||||
folderAsset: yes
|
||||
timeCreated: 1442747310
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Scripts/HSVPicker/Events/ColorChangedEvent.cs
Normal file
9
Assets/Scripts/HSVPicker/Events/ColorChangedEvent.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine.Events;
|
||||
|
||||
[Serializable]
|
||||
public class ColorChangedEvent : UnityEvent<Color>
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff46fbecea7739f4690e4285c88f53c5
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
6
Assets/Scripts/HSVPicker/Events/HSVChangedEvent.cs
Normal file
6
Assets/Scripts/HSVPicker/Events/HSVChangedEvent.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class HSVChangedEvent : UnityEvent<float, float, float>
|
||||
{
|
||||
|
||||
}
|
||||
12
Assets/Scripts/HSVPicker/Events/HSVChangedEvent.cs.meta
Normal file
12
Assets/Scripts/HSVPicker/Events/HSVChangedEvent.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d95ce8fba3dbbf4eb14411412169b88
|
||||
timeCreated: 1442747317
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/Scripts/HSVPicker/HSVPicker.asmdef
Normal file
15
Assets/Scripts/HSVPicker/HSVPicker.asmdef
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "HSVPicker",
|
||||
"references": [
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Assets/Scripts/HSVPicker/HSVPicker.asmdef.meta
Normal file
7
Assets/Scripts/HSVPicker/HSVPicker.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 413a95a52ca644b7dac76988ad8915af
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9189
Assets/Scripts/HSVPicker/Picker 2.0.prefab
Normal file
9189
Assets/Scripts/HSVPicker/Picker 2.0.prefab
Normal file
File diff suppressed because it is too large
Load Diff
8
Assets/Scripts/HSVPicker/Picker 2.0.prefab.meta
Normal file
8
Assets/Scripts/HSVPicker/Picker 2.0.prefab.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 916ee089a0d7b63419075f91e1c657ec
|
||||
timeCreated: 1442747914
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
28
Assets/Scripts/HSVPicker/README.txt
Normal file
28
Assets/Scripts/HSVPicker/README.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
HSV color picker using Unity UI.
|
||||
Github https://github.com/judah4/HSV-Color-Picker-Unity
|
||||
|
||||
Usage:
|
||||
Drag picker prefab onto a UI canvas.
|
||||
|
||||
Setup:
|
||||
On the color picker setup section.
|
||||
|
||||
Show Rgb: Show RGB sliders.
|
||||
|
||||
Show Hsv: Show HSV sliders.
|
||||
|
||||
Show Alpha: Show the alpha slider.
|
||||
|
||||
Show Color Box: Show the larger color selection box and color column.
|
||||
|
||||
Show Color Slider Toggle: Show the button to toggle the HSV and RGB sliders.
|
||||
|
||||
Show Header: Options to show the top header with color preview and hex code.
|
||||
* Hide: Hide the top header.
|
||||
* Show Color: Show only the color preview in the header.
|
||||
* Show Color Code: Show only the color code in the header.
|
||||
* Show All: Show the entire top header.
|
||||
|
||||
Color Presets:
|
||||
The prefabs starts with 4 colors in the color presets. This can be updated in the Setup section of the picker prefab.
|
||||
Set the Preset Colors Id for different shared list between color pickers.
|
||||
7
Assets/Scripts/HSVPicker/README.txt.meta
Normal file
7
Assets/Scripts/HSVPicker/README.txt.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78aa9aa1471451045b0f2f552ad0c361
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Scripts/HSVPicker/UI.meta
Normal file
9
Assets/Scripts/HSVPicker/UI.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b5fe4e314cbd9944bcaa93e814e9bd5
|
||||
folderAsset: yes
|
||||
timeCreated: 1442586536
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/Scripts/HSVPicker/UI/ColorImage.cs
Normal file
30
Assets/Scripts/HSVPicker/UI/ColorImage.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace HSVPicker
|
||||
{
|
||||
[RequireComponent(typeof(Image))]
|
||||
public class ColorImage : MonoBehaviour
|
||||
{
|
||||
public ColorPicker picker;
|
||||
|
||||
private Image image;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
image = GetComponent<Image>();
|
||||
picker.onValueChanged.AddListener(ColorChanged);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
picker.onValueChanged.RemoveListener(ColorChanged);
|
||||
}
|
||||
|
||||
private void ColorChanged(Color newColor)
|
||||
{
|
||||
image.color = newColor;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
12
Assets/Scripts/HSVPicker/UI/ColorImage.cs.meta
Normal file
12
Assets/Scripts/HSVPicker/UI/ColorImage.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6bca58eb07ad66b498a2f158bcb13225
|
||||
timeCreated: 1442675622
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
92
Assets/Scripts/HSVPicker/UI/ColorLabel.cs
Normal file
92
Assets/Scripts/HSVPicker/UI/ColorLabel.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
namespace HSVPicker
|
||||
{
|
||||
|
||||
[RequireComponent(typeof(TMP_Text))]
|
||||
public class ColorLabel : MonoBehaviour
|
||||
{
|
||||
public ColorPicker picker;
|
||||
|
||||
public ColorValues type;
|
||||
|
||||
public string prefix = "R: ";
|
||||
public float minValue = 0;
|
||||
public float maxValue = 255;
|
||||
|
||||
public int precision = 0;
|
||||
|
||||
[SerializeField, HideInInspector]
|
||||
private TMP_Text label;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
label = GetComponent<TMP_Text>();
|
||||
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (Application.isPlaying && picker != null)
|
||||
{
|
||||
picker.onValueChanged.AddListener(ColorChanged);
|
||||
picker.onHSVChanged.AddListener(HSVChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (picker != null)
|
||||
{
|
||||
picker.onValueChanged.RemoveListener(ColorChanged);
|
||||
picker.onHSVChanged.RemoveListener(HSVChanged);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnValidate()
|
||||
{
|
||||
label = GetComponent<TMP_Text>();
|
||||
UpdateValue();
|
||||
}
|
||||
#endif
|
||||
|
||||
private void ColorChanged(Color color)
|
||||
{
|
||||
UpdateValue();
|
||||
}
|
||||
|
||||
private void HSVChanged(float hue, float sateration, float value)
|
||||
{
|
||||
UpdateValue();
|
||||
}
|
||||
|
||||
private void UpdateValue()
|
||||
{
|
||||
if(label == null)
|
||||
return;
|
||||
|
||||
if (picker == null)
|
||||
{
|
||||
label.text = prefix + "-";
|
||||
}
|
||||
else
|
||||
{
|
||||
float value = minValue + (picker.GetValue(type) * (maxValue - minValue));
|
||||
|
||||
label.text = prefix + ConvertToDisplayString(value);
|
||||
}
|
||||
}
|
||||
|
||||
private string ConvertToDisplayString(float value)
|
||||
{
|
||||
if (precision > 0)
|
||||
return value.ToString("f " + precision);
|
||||
else
|
||||
return Mathf.FloorToInt(value).ToString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
12
Assets/Scripts/HSVPicker/UI/ColorLabel.cs.meta
Normal file
12
Assets/Scripts/HSVPicker/UI/ColorLabel.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b10e832a32d2d14facd8a3f489ee8d6
|
||||
timeCreated: 1442587803
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
306
Assets/Scripts/HSVPicker/UI/ColorPicker.cs
Normal file
306
Assets/Scripts/HSVPicker/UI/ColorPicker.cs
Normal file
@@ -0,0 +1,306 @@
|
||||
using UnityEngine;
|
||||
namespace HSVPicker
|
||||
{
|
||||
public class ColorPicker : MonoBehaviour
|
||||
{
|
||||
|
||||
private float _hue = 0;
|
||||
private float _saturation = 0;
|
||||
private float _brightness = 0;
|
||||
|
||||
[SerializeField]
|
||||
private Color _color = Color.red;
|
||||
|
||||
[Header("Setup")]
|
||||
public ColorPickerSetup Setup;
|
||||
|
||||
[Header("Event")]
|
||||
public ColorChangedEvent onValueChanged = new ColorChangedEvent();
|
||||
public HSVChangedEvent onHSVChanged = new HSVChangedEvent();
|
||||
|
||||
public Color CurrentColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _color;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (CurrentColor == value)
|
||||
return;
|
||||
|
||||
_color = value;
|
||||
|
||||
RGBChanged();
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Setup.AlphaSlidiers.Toggle(Setup.ShowAlpha);
|
||||
Setup.ColorToggleElement.Toggle(Setup.ShowColorSliderToggle);
|
||||
Setup.RgbSliders.Toggle(Setup.ShowRgb);
|
||||
Setup.HsvSliders.Toggle(Setup.ShowHsv);
|
||||
Setup.ColorBox.Toggle(Setup.ShowColorBox);
|
||||
|
||||
HandleHeaderSetting(Setup.ShowHeader);
|
||||
UpdateColorToggleText();
|
||||
|
||||
RGBChanged();
|
||||
SendChangedEvent();
|
||||
}
|
||||
|
||||
public float H
|
||||
{
|
||||
get
|
||||
{
|
||||
return _hue;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_hue == value)
|
||||
return;
|
||||
|
||||
_hue = value;
|
||||
|
||||
HSVChanged();
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
public float S
|
||||
{
|
||||
get
|
||||
{
|
||||
return _saturation;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_saturation == value)
|
||||
return;
|
||||
|
||||
_saturation = value;
|
||||
|
||||
HSVChanged();
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
public float V
|
||||
{
|
||||
get
|
||||
{
|
||||
return _brightness;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_brightness == value)
|
||||
return;
|
||||
|
||||
_brightness = value;
|
||||
|
||||
HSVChanged();
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
public float R
|
||||
{
|
||||
get
|
||||
{
|
||||
return _color.r;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_color.r == value)
|
||||
return;
|
||||
|
||||
_color.r = value;
|
||||
|
||||
RGBChanged();
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
public float G
|
||||
{
|
||||
get
|
||||
{
|
||||
return _color.g;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_color.g == value)
|
||||
return;
|
||||
|
||||
_color.g = value;
|
||||
|
||||
RGBChanged();
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
public float B
|
||||
{
|
||||
get
|
||||
{
|
||||
return _color.b;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_color.b == value)
|
||||
return;
|
||||
|
||||
_color.b = value;
|
||||
|
||||
RGBChanged();
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private float A
|
||||
{
|
||||
get
|
||||
{
|
||||
return _color.a;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_color.a == value)
|
||||
return;
|
||||
|
||||
_color.a = value;
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private void RGBChanged()
|
||||
{
|
||||
HsvColor color = HSVUtil.ConvertRgbToHsv(CurrentColor);
|
||||
|
||||
_hue = color.normalizedH;
|
||||
_saturation = color.normalizedS;
|
||||
_brightness = color.normalizedV;
|
||||
}
|
||||
|
||||
private void HSVChanged()
|
||||
{
|
||||
Color color = HSVUtil.ConvertHsvToRgb(_hue * 360, _saturation, _brightness, _color.a);
|
||||
|
||||
_color = color;
|
||||
}
|
||||
|
||||
private void SendChangedEvent()
|
||||
{
|
||||
onValueChanged.Invoke(CurrentColor);
|
||||
onHSVChanged.Invoke(_hue, _saturation, _brightness);
|
||||
}
|
||||
|
||||
public void AssignColor(ColorValues type, float value)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ColorValues.R:
|
||||
R = value;
|
||||
break;
|
||||
case ColorValues.G:
|
||||
G = value;
|
||||
break;
|
||||
case ColorValues.B:
|
||||
B = value;
|
||||
break;
|
||||
case ColorValues.A:
|
||||
A = value;
|
||||
break;
|
||||
case ColorValues.Hue:
|
||||
H = value;
|
||||
break;
|
||||
case ColorValues.Saturation:
|
||||
S = value;
|
||||
break;
|
||||
case ColorValues.Value:
|
||||
V = value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void AssignColor(Color color)
|
||||
{
|
||||
CurrentColor = color;
|
||||
}
|
||||
|
||||
public float GetValue(ColorValues type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ColorValues.R:
|
||||
return R;
|
||||
case ColorValues.G:
|
||||
return G;
|
||||
case ColorValues.B:
|
||||
return B;
|
||||
case ColorValues.A:
|
||||
return A;
|
||||
case ColorValues.Hue:
|
||||
return H;
|
||||
case ColorValues.Saturation:
|
||||
return S;
|
||||
case ColorValues.Value:
|
||||
return V;
|
||||
default:
|
||||
throw new System.NotImplementedException("");
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleColorSliders()
|
||||
{
|
||||
Setup.ShowHsv = !Setup.ShowHsv;
|
||||
Setup.ShowRgb = !Setup.ShowRgb;
|
||||
Setup.HsvSliders.Toggle(Setup.ShowHsv);
|
||||
Setup.RgbSliders.Toggle(Setup.ShowRgb);
|
||||
|
||||
|
||||
UpdateColorToggleText();
|
||||
}
|
||||
|
||||
void UpdateColorToggleText()
|
||||
{
|
||||
if (Setup.ShowRgb)
|
||||
{
|
||||
Setup.SliderToggleButtonText.text = "RGB";
|
||||
}
|
||||
|
||||
if (Setup.ShowHsv)
|
||||
{
|
||||
Setup.SliderToggleButtonText.text = "HSV";
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleHeaderSetting(ColorPickerSetup.ColorHeaderShowing setupShowHeader)
|
||||
{
|
||||
if (setupShowHeader == ColorPickerSetup.ColorHeaderShowing.Hide)
|
||||
{
|
||||
Setup.ColorHeader.Toggle(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Setup.ColorHeader.Toggle(true);
|
||||
|
||||
Setup.ColorPreview.Toggle(setupShowHeader != ColorPickerSetup.ColorHeaderShowing.ShowColorCode);
|
||||
Setup.ColorCode.Toggle(setupShowHeader != ColorPickerSetup.ColorHeaderShowing.ShowColor);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
8
Assets/Scripts/HSVPicker/UI/ColorPicker.cs.meta
Normal file
8
Assets/Scripts/HSVPicker/UI/ColorPicker.cs.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8262e4a8322117f4da079921eaa72834
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
58
Assets/Scripts/HSVPicker/UI/ColorPickerSetup.cs
Normal file
58
Assets/Scripts/HSVPicker/UI/ColorPickerSetup.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
namespace HSVPicker
|
||||
{
|
||||
[System.Serializable]
|
||||
public class ColorPickerSetup
|
||||
{
|
||||
public enum ColorHeaderShowing
|
||||
{
|
||||
Hide,
|
||||
ShowColor,
|
||||
ShowColorCode,
|
||||
ShowAll,
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class UiElements
|
||||
{
|
||||
public RectTransform[] Elements;
|
||||
|
||||
|
||||
public void Toggle(bool active)
|
||||
{
|
||||
for (int cnt = 0; cnt < Elements.Length; cnt++)
|
||||
{
|
||||
Elements[cnt].gameObject.SetActive(active);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public bool ShowRgb = true;
|
||||
public bool ShowHsv;
|
||||
public bool ShowAlpha = true;
|
||||
public bool ShowColorBox = true;
|
||||
public bool ShowColorSliderToggle = true;
|
||||
|
||||
public ColorHeaderShowing ShowHeader = ColorHeaderShowing.ShowAll;
|
||||
|
||||
public UiElements RgbSliders;
|
||||
public UiElements HsvSliders;
|
||||
public UiElements ColorToggleElement;
|
||||
public UiElements AlphaSlidiers;
|
||||
|
||||
|
||||
public UiElements ColorHeader;
|
||||
public UiElements ColorCode;
|
||||
public UiElements ColorPreview;
|
||||
|
||||
public UiElements ColorBox;
|
||||
public TMP_Text SliderToggleButtonText;
|
||||
|
||||
public string PresetColorsId = "default";
|
||||
public Color[] DefaultPresetColors;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/HSVPicker/UI/ColorPickerSetup.cs.meta
Normal file
11
Assets/Scripts/HSVPicker/UI/ColorPickerSetup.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f1e0a31fe4cdb5458d5a88aa1268434
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
67
Assets/Scripts/HSVPicker/UI/ColorPresetManager.cs
Normal file
67
Assets/Scripts/HSVPicker/UI/ColorPresetManager.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace HSVPicker
|
||||
{
|
||||
public static class ColorPresetManager
|
||||
{
|
||||
private static Dictionary<string, ColorPresetList> _presets = new Dictionary<string, ColorPresetList>();
|
||||
|
||||
public static ColorPresetList Get(string listId = "default")
|
||||
{
|
||||
ColorPresetList preset;
|
||||
if (!_presets.TryGetValue(listId, out preset))
|
||||
{
|
||||
preset = new ColorPresetList(listId);
|
||||
_presets.Add(listId, preset);
|
||||
}
|
||||
|
||||
return preset;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class ColorPresetList
|
||||
{
|
||||
public string ListId { get; private set; }
|
||||
public List<Color> Colors { get; private set; }
|
||||
|
||||
public event UnityAction<List<Color>> OnColorsUpdated;
|
||||
|
||||
public ColorPresetList(string listId, List<Color> colors = null)
|
||||
{
|
||||
if (colors == null)
|
||||
{
|
||||
colors = new List<Color>();
|
||||
}
|
||||
|
||||
Colors = colors;
|
||||
ListId = listId;
|
||||
}
|
||||
|
||||
public void AddColor(Color color)
|
||||
{
|
||||
Colors.Add(color);
|
||||
if (OnColorsUpdated != null)
|
||||
{
|
||||
OnColorsUpdated.Invoke(Colors);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateList(IEnumerable<Color> colors)
|
||||
{
|
||||
Colors.Clear();
|
||||
Colors.AddRange(colors);
|
||||
|
||||
if (OnColorsUpdated != null)
|
||||
{
|
||||
OnColorsUpdated.Invoke(Colors);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/HSVPicker/UI/ColorPresetManager.cs.meta
Normal file
11
Assets/Scripts/HSVPicker/UI/ColorPresetManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55b59bed8e892614e9397d8a20e36e0c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
86
Assets/Scripts/HSVPicker/UI/ColorPresets.cs
Normal file
86
Assets/Scripts/HSVPicker/UI/ColorPresets.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace HSVPicker
|
||||
{
|
||||
public class ColorPresets : MonoBehaviour
|
||||
{
|
||||
public ColorPicker picker;
|
||||
public GameObject[] presets;
|
||||
public Image createPresetImage;
|
||||
|
||||
private ColorPresetList _colors;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
// picker.onHSVChanged.AddListener(HSVChanged);
|
||||
picker.onValueChanged.AddListener(ColorChanged);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
_colors = ColorPresetManager.Get(picker.Setup.PresetColorsId);
|
||||
|
||||
if (_colors.Colors.Count < picker.Setup.DefaultPresetColors.Length)
|
||||
{
|
||||
_colors.UpdateList(picker.Setup.DefaultPresetColors);
|
||||
}
|
||||
|
||||
_colors.OnColorsUpdated += OnColorsUpdate;
|
||||
OnColorsUpdate(_colors.Colors);
|
||||
}
|
||||
|
||||
private void OnColorsUpdate(List<Color> colors)
|
||||
{
|
||||
for (int cnt = 0; cnt < presets.Length; cnt++)
|
||||
{
|
||||
if (colors.Count <= cnt)
|
||||
{
|
||||
presets[cnt].SetActive(false);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
presets[cnt].SetActive(true);
|
||||
presets[cnt].GetComponent<Image>().color = colors[cnt];
|
||||
|
||||
}
|
||||
|
||||
createPresetImage.gameObject.SetActive(colors.Count < presets.Length);
|
||||
|
||||
}
|
||||
|
||||
public void CreatePresetButton()
|
||||
{
|
||||
_colors.AddColor(picker.CurrentColor);
|
||||
|
||||
// for (var i = 0; i < presets.Length; i++)
|
||||
//{
|
||||
// if (!presets[i].activeSelf)
|
||||
// {
|
||||
// presets[i].SetActive(true);
|
||||
// presets[i].GetComponent<Image>().color = picker.CurrentColor;
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
public void PresetSelect(Image sender)
|
||||
{
|
||||
picker.CurrentColor = sender.color;
|
||||
}
|
||||
|
||||
// Not working, it seems ConvertHsvToRgb() is broken. It doesn't work when fed
|
||||
// input h, s, v as shown below.
|
||||
// private void HSVChanged(float h, float s, float v)
|
||||
// {
|
||||
// createPresetImage.color = HSVUtil.ConvertHsvToRgb(h, s, v, 1);
|
||||
// }
|
||||
private void ColorChanged(Color color)
|
||||
{
|
||||
createPresetImage.color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Scripts/HSVPicker/UI/ColorPresets.cs.meta
Normal file
12
Assets/Scripts/HSVPicker/UI/ColorPresets.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0923373e76e77402c9c53a2f1250ad3e
|
||||
timeCreated: 1456875791
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
92
Assets/Scripts/HSVPicker/UI/ColorSlider.cs
Normal file
92
Assets/Scripts/HSVPicker/UI/ColorSlider.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
namespace HSVPicker
|
||||
{
|
||||
/// <summary>
|
||||
/// Displays one of the color values of aColorPicker
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Slider))]
|
||||
public class ColorSlider : MonoBehaviour
|
||||
{
|
||||
public ColorPicker hsvpicker;
|
||||
|
||||
/// <summary>
|
||||
/// Which value this slider can edit.
|
||||
/// </summary>
|
||||
public ColorValues type;
|
||||
|
||||
private Slider slider;
|
||||
|
||||
private bool listen = true;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
slider = GetComponent<Slider>();
|
||||
|
||||
hsvpicker.onValueChanged.AddListener(ColorChanged);
|
||||
hsvpicker.onHSVChanged.AddListener(HSVChanged);
|
||||
slider.onValueChanged.AddListener(SliderChanged);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
hsvpicker.onValueChanged.RemoveListener(ColorChanged);
|
||||
hsvpicker.onHSVChanged.RemoveListener(HSVChanged);
|
||||
slider.onValueChanged.RemoveListener(SliderChanged);
|
||||
}
|
||||
|
||||
private void ColorChanged(Color newColor)
|
||||
{
|
||||
listen = false;
|
||||
switch (type)
|
||||
{
|
||||
case ColorValues.R:
|
||||
slider.normalizedValue = newColor.r;
|
||||
break;
|
||||
case ColorValues.G:
|
||||
slider.normalizedValue = newColor.g;
|
||||
break;
|
||||
case ColorValues.B:
|
||||
slider.normalizedValue = newColor.b;
|
||||
break;
|
||||
case ColorValues.A:
|
||||
slider.normalizedValue = newColor.a;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void HSVChanged(float hue, float saturation, float value)
|
||||
{
|
||||
listen = false;
|
||||
switch (type)
|
||||
{
|
||||
case ColorValues.Hue:
|
||||
slider.normalizedValue = hue; //1 - hue;
|
||||
break;
|
||||
case ColorValues.Saturation:
|
||||
slider.normalizedValue = saturation;
|
||||
break;
|
||||
case ColorValues.Value:
|
||||
slider.normalizedValue = value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void SliderChanged(float newValue)
|
||||
{
|
||||
if (listen)
|
||||
{
|
||||
newValue = slider.normalizedValue;
|
||||
//if (type == ColorValues.Hue)
|
||||
// newValue = 1 - newValue;
|
||||
|
||||
hsvpicker.AssignColor(type, newValue);
|
||||
}
|
||||
listen = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Scripts/HSVPicker/UI/ColorSlider.cs.meta
Normal file
12
Assets/Scripts/HSVPicker/UI/ColorSlider.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c600592efa0cf25479655321bf4fb08a
|
||||
timeCreated: 1442586558
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
206
Assets/Scripts/HSVPicker/UI/ColorSliderImage.cs
Normal file
206
Assets/Scripts/HSVPicker/UI/ColorSliderImage.cs
Normal file
@@ -0,0 +1,206 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
namespace HSVPicker
|
||||
{
|
||||
[RequireComponent(typeof(RawImage)), ExecuteInEditMode()]
|
||||
public class ColorSliderImage : MonoBehaviour
|
||||
{
|
||||
public ColorPicker picker;
|
||||
|
||||
/// <summary>
|
||||
/// Which value this slider can edit.
|
||||
/// </summary>
|
||||
public ColorValues type;
|
||||
|
||||
public Slider.Direction direction;
|
||||
|
||||
private RawImage image;
|
||||
|
||||
private RectTransform rectTransform
|
||||
{
|
||||
get
|
||||
{
|
||||
return transform as RectTransform;
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
image = GetComponent<RawImage>();
|
||||
|
||||
if(Application.isPlaying)
|
||||
RegenerateTexture();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (picker != null && Application.isPlaying)
|
||||
{
|
||||
picker.onValueChanged.AddListener(ColorChanged);
|
||||
picker.onHSVChanged.AddListener(HSVChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (picker != null)
|
||||
{
|
||||
picker.onValueChanged.RemoveListener(ColorChanged);
|
||||
picker.onHSVChanged.RemoveListener(HSVChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (image.texture != null)
|
||||
DestroyImmediate(image.texture);
|
||||
}
|
||||
|
||||
private void ColorChanged(Color newColor)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ColorValues.R:
|
||||
case ColorValues.G:
|
||||
case ColorValues.B:
|
||||
case ColorValues.Saturation:
|
||||
case ColorValues.Value:
|
||||
RegenerateTexture();
|
||||
break;
|
||||
case ColorValues.A:
|
||||
case ColorValues.Hue:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void HSVChanged(float hue, float saturation, float value)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ColorValues.R:
|
||||
case ColorValues.G:
|
||||
case ColorValues.B:
|
||||
case ColorValues.Saturation:
|
||||
case ColorValues.Value:
|
||||
RegenerateTexture();
|
||||
break;
|
||||
case ColorValues.A:
|
||||
case ColorValues.Hue:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void RegenerateTexture()
|
||||
{
|
||||
Color32 baseColor = picker != null ? picker.CurrentColor : Color.black;
|
||||
|
||||
float h = picker != null ? picker.H : 0;
|
||||
float s = picker != null ? picker.S : 0;
|
||||
float v = picker != null ? picker.V : 0;
|
||||
|
||||
Texture2D texture;
|
||||
Color32[] colors;
|
||||
|
||||
bool vertical = direction == Slider.Direction.BottomToTop || direction == Slider.Direction.TopToBottom;
|
||||
bool inverted = direction == Slider.Direction.TopToBottom || direction == Slider.Direction.RightToLeft;
|
||||
|
||||
int size;
|
||||
switch (type)
|
||||
{
|
||||
case ColorValues.R:
|
||||
case ColorValues.G:
|
||||
case ColorValues.B:
|
||||
case ColorValues.A:
|
||||
size = 255;
|
||||
break;
|
||||
case ColorValues.Hue:
|
||||
size = 360;
|
||||
break;
|
||||
case ColorValues.Saturation:
|
||||
case ColorValues.Value:
|
||||
size = 100;
|
||||
break;
|
||||
default:
|
||||
throw new System.NotImplementedException("");
|
||||
}
|
||||
if (vertical)
|
||||
texture = new Texture2D(1, size);
|
||||
else
|
||||
texture = new Texture2D(size, 1);
|
||||
|
||||
texture.hideFlags = HideFlags.DontSave;
|
||||
colors = new Color32[size];
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ColorValues.R:
|
||||
for (byte i = 0; i < size; i++)
|
||||
{
|
||||
colors[inverted ? size - 1 - i : i] = new Color32(i, baseColor.g, baseColor.b, 255);
|
||||
}
|
||||
break;
|
||||
case ColorValues.G:
|
||||
for (byte i = 0; i < size; i++)
|
||||
{
|
||||
colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, i, baseColor.b, 255);
|
||||
}
|
||||
break;
|
||||
case ColorValues.B:
|
||||
for (byte i = 0; i < size; i++)
|
||||
{
|
||||
colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, baseColor.g, i, 255);
|
||||
}
|
||||
break;
|
||||
case ColorValues.A:
|
||||
for (byte i = 0; i < size; i++)
|
||||
{
|
||||
colors[inverted ? size - 1 - i : i] = new Color32(i, i, i, 255);
|
||||
}
|
||||
break;
|
||||
case ColorValues.Hue:
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(i, 1, 1, 1);
|
||||
}
|
||||
break;
|
||||
case ColorValues.Saturation:
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(h * 360, (float)i / size, v, 1);
|
||||
}
|
||||
break;
|
||||
case ColorValues.Value:
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(h * 360, s, (float)i / size, 1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new System.NotImplementedException("");
|
||||
}
|
||||
texture.SetPixels32(colors);
|
||||
texture.Apply();
|
||||
|
||||
if (image.texture != null)
|
||||
DestroyImmediate(image.texture);
|
||||
image.texture = texture;
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case Slider.Direction.BottomToTop:
|
||||
case Slider.Direction.TopToBottom:
|
||||
image.uvRect = new Rect(0, 0, 2, 1);
|
||||
break;
|
||||
case Slider.Direction.LeftToRight:
|
||||
case Slider.Direction.RightToLeft:
|
||||
image.uvRect = new Rect(0, 0, 1, 2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
Assets/Scripts/HSVPicker/UI/ColorSliderImage.cs.meta
Normal file
12
Assets/Scripts/HSVPicker/UI/ColorSliderImage.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7ca76dd9ad6eb204c9b0481aece34497
|
||||
timeCreated: 1442682013
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
Assets/Scripts/HSVPicker/UI/HexColorField.cs
Normal file
53
Assets/Scripts/HSVPicker/UI/HexColorField.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
namespace HSVPicker
|
||||
{
|
||||
[RequireComponent(typeof(TMP_InputField))]
|
||||
public class HexColorField : MonoBehaviour
|
||||
{
|
||||
public ColorPicker hsvpicker;
|
||||
|
||||
public bool displayAlpha;
|
||||
|
||||
private TMP_InputField hexInputField;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
hexInputField = GetComponent<TMP_InputField>();
|
||||
|
||||
// Add listeners to keep text (and color) up to date
|
||||
hexInputField.onEndEdit.AddListener(UpdateColor);
|
||||
hsvpicker.onValueChanged.AddListener(UpdateHex);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
hexInputField.onValueChanged.RemoveListener(UpdateColor);
|
||||
hsvpicker.onValueChanged.RemoveListener(UpdateHex);
|
||||
}
|
||||
|
||||
private void UpdateHex(Color newColor)
|
||||
{
|
||||
hexInputField.text = ColorToHex(newColor);
|
||||
}
|
||||
|
||||
private void UpdateColor(string newHex)
|
||||
{
|
||||
Color color;
|
||||
if (!newHex.StartsWith("#"))
|
||||
newHex = "#"+newHex;
|
||||
if (ColorUtility.TryParseHtmlString(newHex, out color))
|
||||
hsvpicker.CurrentColor = color;
|
||||
else
|
||||
Debug.Log("hex value is in the wrong format, valid formats are: #RGB, #RGBA, #RRGGBB and #RRGGBBAA (# is optional)");
|
||||
}
|
||||
|
||||
private string ColorToHex(Color32 color)
|
||||
{
|
||||
return displayAlpha
|
||||
? string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", color.r, color.g, color.b, color.a)
|
||||
: string.Format("#{0:X2}{1:X2}{2:X2}", color.r, color.g, color.b);
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Assets/Scripts/HSVPicker/UI/HexColorField.cs.meta
Normal file
8
Assets/Scripts/HSVPicker/UI/HexColorField.cs.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d85c534b3c1560544b09d0996dfeba84
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
121
Assets/Scripts/HSVPicker/UI/SVBoxSlider.cs
Normal file
121
Assets/Scripts/HSVPicker/UI/SVBoxSlider.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace HSVPicker
|
||||
{
|
||||
[RequireComponent(typeof(BoxSlider), typeof(RawImage)), ExecuteInEditMode()]
|
||||
public class SVBoxSlider : MonoBehaviour
|
||||
{
|
||||
public ColorPicker picker;
|
||||
|
||||
private BoxSlider slider;
|
||||
private RawImage image;
|
||||
|
||||
private int textureWidth = 128;
|
||||
private int textureHeight = 128;
|
||||
|
||||
private float lastH = -1;
|
||||
private bool listen = true;
|
||||
|
||||
public RectTransform rectTransform
|
||||
{
|
||||
get
|
||||
{
|
||||
return transform as RectTransform;
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
slider = GetComponent<BoxSlider>();
|
||||
image = GetComponent<RawImage>();
|
||||
if(Application.isPlaying)
|
||||
{
|
||||
RegenerateSVTexture ();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (Application.isPlaying && picker != null)
|
||||
{
|
||||
slider.onValueChanged.AddListener(SliderChanged);
|
||||
picker.onHSVChanged.AddListener(HSVChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (picker != null)
|
||||
{
|
||||
slider.onValueChanged.RemoveListener(SliderChanged);
|
||||
picker.onHSVChanged.RemoveListener(HSVChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if ( image.texture != null )
|
||||
{
|
||||
DestroyImmediate (image.texture);
|
||||
}
|
||||
}
|
||||
|
||||
private void SliderChanged(float saturation, float value)
|
||||
{
|
||||
if (listen)
|
||||
{
|
||||
picker.AssignColor(ColorValues.Saturation, saturation);
|
||||
picker.AssignColor(ColorValues.Value, value);
|
||||
}
|
||||
listen = true;
|
||||
}
|
||||
|
||||
private void HSVChanged(float h, float s, float v)
|
||||
{
|
||||
if (!lastH.Equals(h))
|
||||
{
|
||||
lastH = h;
|
||||
RegenerateSVTexture();
|
||||
}
|
||||
|
||||
if (!s.Equals(slider.normalizedValue))
|
||||
{
|
||||
listen = false;
|
||||
slider.normalizedValue = s;
|
||||
}
|
||||
|
||||
if (!v.Equals(slider.normalizedValueY))
|
||||
{
|
||||
listen = false;
|
||||
slider.normalizedValueY = v;
|
||||
}
|
||||
}
|
||||
|
||||
private void RegenerateSVTexture()
|
||||
{
|
||||
double h = picker != null ? picker.H * 360 : 0;
|
||||
|
||||
if ( image.texture != null )
|
||||
DestroyImmediate (image.texture);
|
||||
|
||||
var texture = new Texture2D (textureWidth, textureHeight);
|
||||
texture.wrapMode = TextureWrapMode.Clamp;
|
||||
texture.hideFlags = HideFlags.DontSave;
|
||||
|
||||
for ( int s = 0; s < textureWidth; s++ )
|
||||
{
|
||||
Color[] colors = new Color[textureHeight];
|
||||
for ( int v = 0; v < textureHeight; v++ )
|
||||
{
|
||||
colors[v] = HSVUtil.ConvertHsvToRgb (h, (float)s / textureWidth, (float)v / textureHeight, 1);
|
||||
}
|
||||
texture.SetPixels (s, 0, 1, textureHeight, colors);
|
||||
}
|
||||
texture.Apply();
|
||||
|
||||
image.texture = texture;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Scripts/HSVPicker/UI/SVBoxSlider.cs.meta
Normal file
12
Assets/Scripts/HSVPicker/UI/SVBoxSlider.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e4240873631f724496efec97d7151b3
|
||||
timeCreated: 1442650713
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Scripts/HSVPicker/UtilityScripts.meta
Normal file
9
Assets/Scripts/HSVPicker/UtilityScripts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b33138f525222146865861432dbe845
|
||||
folderAsset: yes
|
||||
timeCreated: 1426051345
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
448
Assets/Scripts/HSVPicker/UtilityScripts/BoxSlider.cs
Normal file
448
Assets/Scripts/HSVPicker/UtilityScripts/BoxSlider.cs
Normal file
@@ -0,0 +1,448 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace HSVPicker
|
||||
{
|
||||
[AddComponentMenu("UI/BoxSlider", 35)]
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
public class BoxSlider : Selectable, IDragHandler, IInitializePotentialDragHandler, ICanvasElement
|
||||
{
|
||||
public enum Direction
|
||||
{
|
||||
LeftToRight,
|
||||
RightToLeft,
|
||||
BottomToTop,
|
||||
TopToBottom,
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class BoxSliderEvent : UnityEvent<float, float> { }
|
||||
|
||||
[SerializeField]
|
||||
private RectTransform m_HandleRect;
|
||||
public RectTransform handleRect { get { return m_HandleRect; } set { if (SetClass(ref m_HandleRect, value)) { UpdateCachedReferences(); UpdateVisuals(); } } }
|
||||
|
||||
[Space(6)]
|
||||
|
||||
[SerializeField]
|
||||
private float m_MinValue = 0;
|
||||
public float minValue { get { return m_MinValue; } set { if (SetStruct(ref m_MinValue, value)) { Set(m_Value); SetY (m_ValueY); UpdateVisuals(); } } }
|
||||
|
||||
[SerializeField]
|
||||
private float m_MaxValue = 1;
|
||||
public float maxValue { get { return m_MaxValue; } set { if (SetStruct(ref m_MaxValue, value)) { Set(m_Value); SetY (m_ValueY); UpdateVisuals(); } } }
|
||||
|
||||
[SerializeField]
|
||||
private bool m_WholeNumbers = false;
|
||||
public bool wholeNumbers { get { return m_WholeNumbers; } set { if (SetStruct(ref m_WholeNumbers, value)) { Set(m_Value); SetY (m_ValueY); UpdateVisuals(); } } }
|
||||
|
||||
[SerializeField]
|
||||
private float m_Value = 1f;
|
||||
public float value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (wholeNumbers)
|
||||
return Mathf.Round(m_Value);
|
||||
return m_Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
Set(value);
|
||||
}
|
||||
}
|
||||
|
||||
public float normalizedValue
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Mathf.Approximately(minValue, maxValue))
|
||||
return 0;
|
||||
return Mathf.InverseLerp(minValue, maxValue, value);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.value = Mathf.Lerp(minValue, maxValue, value);
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private float m_ValueY = 1f;
|
||||
public float valueY
|
||||
{
|
||||
get
|
||||
{
|
||||
if (wholeNumbers)
|
||||
return Mathf.Round(m_ValueY);
|
||||
return m_ValueY;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetY(value);
|
||||
}
|
||||
}
|
||||
|
||||
public float normalizedValueY
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Mathf.Approximately(minValue, maxValue))
|
||||
return 0;
|
||||
return Mathf.InverseLerp(minValue, maxValue, valueY);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.valueY = Mathf.Lerp(minValue, maxValue, value);
|
||||
}
|
||||
}
|
||||
|
||||
[Space(6)]
|
||||
|
||||
// Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multiple receivers.
|
||||
[SerializeField]
|
||||
private BoxSliderEvent m_OnValueChanged = new BoxSliderEvent();
|
||||
public BoxSliderEvent onValueChanged { get { return m_OnValueChanged; } set { m_OnValueChanged = value; } }
|
||||
|
||||
// Private fields
|
||||
|
||||
//private Image m_FillImage;
|
||||
//private Transform m_FillTransform;
|
||||
//private RectTransform m_FillContainerRect;
|
||||
private Transform m_HandleTransform;
|
||||
private RectTransform m_HandleContainerRect;
|
||||
|
||||
// The offset from handle position to mouse down position
|
||||
private Vector2 m_Offset = Vector2.zero;
|
||||
|
||||
private DrivenRectTransformTracker m_Tracker;
|
||||
|
||||
// Size of each step.
|
||||
float stepSize { get { return wholeNumbers ? 1 : (maxValue - minValue) * 0.1f; } }
|
||||
|
||||
protected BoxSlider()
|
||||
{ }
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void OnValidate()
|
||||
{
|
||||
base.OnValidate();
|
||||
|
||||
if (wholeNumbers)
|
||||
{
|
||||
m_MinValue = Mathf.Round(m_MinValue);
|
||||
m_MaxValue = Mathf.Round(m_MaxValue);
|
||||
}
|
||||
|
||||
//Onvalidate is called before OnEnabled. We need to make sure not to touch any other objects before OnEnable is run.
|
||||
if (IsActive())
|
||||
{
|
||||
UpdateCachedReferences();
|
||||
Set(m_Value, false);
|
||||
SetY(m_ValueY, false);
|
||||
// Update rects since other things might affect them even if value didn't change.
|
||||
UpdateVisuals();
|
||||
}
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
|
||||
if (!UnityEditor.PrefabUtility.IsPartOfPrefabAsset(this) && !Application.isPlaying)
|
||||
CanvasUpdateRegistry.RegisterCanvasElementForLayoutRebuild(this);
|
||||
|
||||
#else
|
||||
|
||||
var prefabType = UnityEditor.PrefabUtility.GetPrefabType(this);
|
||||
if (prefabType != UnityEditor.PrefabType.Prefab && !Application.isPlaying)
|
||||
CanvasUpdateRegistry.RegisterCanvasElementForLayoutRebuild(this);
|
||||
#endif
|
||||
}
|
||||
#endif // if UNITY_EDITOR
|
||||
|
||||
public virtual void Rebuild(CanvasUpdate executing)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (executing == CanvasUpdate.Prelayout)
|
||||
onValueChanged.Invoke(value, valueY);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void LayoutComplete()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void GraphicUpdateComplete()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static bool SetClass<T>(ref T currentValue, T newValue) where T: class
|
||||
{
|
||||
if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue)))
|
||||
return false;
|
||||
|
||||
currentValue = newValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool SetStruct<T>(ref T currentValue, T newValue) where T: struct
|
||||
{
|
||||
if (currentValue.Equals(newValue))
|
||||
return false;
|
||||
|
||||
currentValue = newValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
UpdateCachedReferences();
|
||||
Set(m_Value, false);
|
||||
SetY(m_ValueY, false);
|
||||
// Update rects since they need to be initialized correctly.
|
||||
UpdateVisuals();
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
m_Tracker.Clear();
|
||||
base.OnDisable();
|
||||
}
|
||||
|
||||
void UpdateCachedReferences()
|
||||
{
|
||||
|
||||
if (m_HandleRect)
|
||||
{
|
||||
m_HandleTransform = m_HandleRect.transform;
|
||||
if (m_HandleTransform.parent != null)
|
||||
m_HandleContainerRect = m_HandleTransform.parent.GetComponent<RectTransform>();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_HandleContainerRect = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the valueUpdate the visible Image.
|
||||
void Set(float input)
|
||||
{
|
||||
Set(input, true);
|
||||
}
|
||||
|
||||
void Set(float input, bool sendCallback)
|
||||
{
|
||||
// Clamp the input
|
||||
float newValue = Mathf.Clamp(input, minValue, maxValue);
|
||||
if (wholeNumbers)
|
||||
newValue = Mathf.Round(newValue);
|
||||
|
||||
// If the stepped value doesn't match the last one, it's time to update
|
||||
if (m_Value.Equals(newValue))
|
||||
return;
|
||||
|
||||
m_Value = newValue;
|
||||
UpdateVisuals();
|
||||
if (sendCallback)
|
||||
m_OnValueChanged.Invoke(newValue, valueY);
|
||||
}
|
||||
|
||||
void SetY(float input)
|
||||
{
|
||||
SetY(input, true);
|
||||
}
|
||||
|
||||
void SetY(float input, bool sendCallback)
|
||||
{
|
||||
// Clamp the input
|
||||
float newValue = Mathf.Clamp(input, minValue, maxValue);
|
||||
if (wholeNumbers)
|
||||
newValue = Mathf.Round(newValue);
|
||||
|
||||
// If the stepped value doesn't match the last one, it's time to update
|
||||
if (m_ValueY.Equals(newValue))
|
||||
return;
|
||||
|
||||
m_ValueY = newValue;
|
||||
UpdateVisuals();
|
||||
if (sendCallback)
|
||||
m_OnValueChanged.Invoke(value, newValue);
|
||||
}
|
||||
|
||||
|
||||
protected override void OnRectTransformDimensionsChange()
|
||||
{
|
||||
base.OnRectTransformDimensionsChange();
|
||||
UpdateVisuals();
|
||||
}
|
||||
|
||||
enum Axis
|
||||
{
|
||||
Horizontal = 0,
|
||||
Vertical = 1
|
||||
}
|
||||
|
||||
|
||||
// Force-update the slider. Useful if you've changed the properties and want it to update visually.
|
||||
private void UpdateVisuals()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
UpdateCachedReferences();
|
||||
#endif
|
||||
|
||||
m_Tracker.Clear();
|
||||
|
||||
|
||||
//to business!
|
||||
if (m_HandleContainerRect != null)
|
||||
{
|
||||
m_Tracker.Add(this, m_HandleRect, DrivenTransformProperties.Anchors);
|
||||
Vector2 anchorMin = Vector2.zero;
|
||||
Vector2 anchorMax = Vector2.one;
|
||||
anchorMin[0] = anchorMax[0] = (normalizedValue);
|
||||
anchorMin[1] = anchorMax[1] = ( normalizedValueY);
|
||||
|
||||
m_HandleRect.anchorMin = anchorMin;
|
||||
m_HandleRect.anchorMax = anchorMax;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the slider's position based on the mouse.
|
||||
void UpdateDrag(PointerEventData eventData, Camera cam)
|
||||
{
|
||||
RectTransform clickRect = m_HandleContainerRect;
|
||||
if (clickRect != null && clickRect.rect.size[0] > 0)
|
||||
{
|
||||
Vector2 localCursor;
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(clickRect, eventData.position, cam, out localCursor))
|
||||
return;
|
||||
localCursor -= clickRect.rect.position;
|
||||
|
||||
float val = Mathf.Clamp01((localCursor - m_Offset)[0] / clickRect.rect.size[0]);
|
||||
normalizedValue = (val);
|
||||
|
||||
float valY = Mathf.Clamp01((localCursor - m_Offset)[1] / clickRect.rect.size[1]);
|
||||
normalizedValueY = ( valY);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private bool MayDrag(PointerEventData eventData)
|
||||
{
|
||||
return IsActive() && IsInteractable() && eventData.button == PointerEventData.InputButton.Left;
|
||||
}
|
||||
|
||||
public override void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
if (!MayDrag(eventData))
|
||||
return;
|
||||
|
||||
base.OnPointerDown(eventData);
|
||||
|
||||
m_Offset = Vector2.zero;
|
||||
if (m_HandleContainerRect != null && RectTransformUtility.RectangleContainsScreenPoint(m_HandleRect, eventData.position, eventData.enterEventCamera))
|
||||
{
|
||||
Vector2 localMousePos;
|
||||
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HandleRect, eventData.position, eventData.pressEventCamera, out localMousePos))
|
||||
m_Offset = localMousePos;
|
||||
m_Offset.y = -m_Offset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Outside the slider handle - jump to this point instead
|
||||
UpdateDrag(eventData, eventData.pressEventCamera);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
if (!MayDrag(eventData))
|
||||
return;
|
||||
|
||||
UpdateDrag(eventData, eventData.pressEventCamera);
|
||||
}
|
||||
|
||||
//public override void OnMove(AxisEventData eventData)
|
||||
//{
|
||||
// if (!IsActive() || !IsInteractable())
|
||||
// {
|
||||
// base.OnMove(eventData);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// switch (eventData.moveDir)
|
||||
// {
|
||||
// case MoveDirection.Left:
|
||||
// if (axis == Axis.Horizontal && FindSelectableOnLeft() == null) {
|
||||
// Set(reverseValue ? value + stepSize : value - stepSize);
|
||||
// SetY (reverseValue ? valueY + stepSize : valueY - stepSize);
|
||||
// }
|
||||
// else
|
||||
// base.OnMove(eventData);
|
||||
// break;
|
||||
// case MoveDirection.Right:
|
||||
// if (axis == Axis.Horizontal && FindSelectableOnRight() == null) {
|
||||
// Set(reverseValue ? value - stepSize : value + stepSize);
|
||||
// SetY(reverseValue ? valueY - stepSize : valueY + stepSize);
|
||||
// }
|
||||
// else
|
||||
// base.OnMove(eventData);
|
||||
// break;
|
||||
// case MoveDirection.Up:
|
||||
// if (axis == Axis.Vertical && FindSelectableOnUp() == null) {
|
||||
// Set(reverseValue ? value - stepSize : value + stepSize);
|
||||
// SetY(reverseValue ? valueY - stepSize : valueY + stepSize);
|
||||
// }
|
||||
// else
|
||||
// base.OnMove(eventData);
|
||||
// break;
|
||||
// case MoveDirection.Down:
|
||||
// if (axis == Axis.Vertical && FindSelectableOnDown() == null) {
|
||||
// Set(reverseValue ? value + stepSize : value - stepSize);
|
||||
// SetY(reverseValue ? valueY + stepSize : valueY - stepSize);
|
||||
// }
|
||||
// else
|
||||
// base.OnMove(eventData);
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
|
||||
//public override Selectable FindSelectableOnLeft()
|
||||
//{
|
||||
// if (navigation.mode == Navigation.Mode.Automatic && axis == Axis.Horizontal)
|
||||
// return null;
|
||||
// return base.FindSelectableOnLeft();
|
||||
//}
|
||||
|
||||
//public override Selectable FindSelectableOnRight()
|
||||
//{
|
||||
// if (navigation.mode == Navigation.Mode.Automatic && axis == Axis.Horizontal)
|
||||
// return null;
|
||||
// return base.FindSelectableOnRight();
|
||||
//}
|
||||
|
||||
//public override Selectable FindSelectableOnUp()
|
||||
//{
|
||||
// if (navigation.mode == Navigation.Mode.Automatic && axis == Axis.Vertical)
|
||||
// return null;
|
||||
// return base.FindSelectableOnUp();
|
||||
//}
|
||||
|
||||
//public override Selectable FindSelectableOnDown()
|
||||
//{
|
||||
// if (navigation.mode == Navigation.Mode.Automatic && axis == Axis.Vertical)
|
||||
// return null;
|
||||
// return base.FindSelectableOnDown();
|
||||
//}
|
||||
|
||||
public virtual void OnInitializePotentialDrag(PointerEventData eventData)
|
||||
{
|
||||
eventData.useDragThreshold = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37c44bc94a9a7f241b5b552f3ff89458
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
210
Assets/Scripts/HSVPicker/UtilityScripts/HSVUtil.cs
Normal file
210
Assets/Scripts/HSVPicker/UtilityScripts/HSVUtil.cs
Normal file
@@ -0,0 +1,210 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace HSVPicker
|
||||
{
|
||||
|
||||
#region ColorUtilities
|
||||
|
||||
public static class HSVUtil
|
||||
{
|
||||
|
||||
public static HsvColor ConvertRgbToHsv(Color color)
|
||||
{
|
||||
return ConvertRgbToHsv((int)(color.r * 255), (int)(color.g * 255), (int)(color.b * 255));
|
||||
}
|
||||
|
||||
//Converts an RGB color to an HSV color.
|
||||
public static HsvColor ConvertRgbToHsv(double r, double b, double g)
|
||||
{
|
||||
double delta, min;
|
||||
double h = 0, s, v;
|
||||
|
||||
min = Math.Min(Math.Min(r, g), b);
|
||||
v = Math.Max(Math.Max(r, g), b);
|
||||
delta = v - min;
|
||||
|
||||
if (v.Equals(0))
|
||||
s = 0;
|
||||
else
|
||||
s = delta / v;
|
||||
|
||||
if (s.Equals(0))
|
||||
h = 360;
|
||||
else
|
||||
{
|
||||
if (r.Equals(v))
|
||||
h = (g - b) / delta;
|
||||
else if (g.Equals(v))
|
||||
h = 2 + (b - r) / delta;
|
||||
else if (b.Equals(v))
|
||||
h = 4 + (r - g) / delta;
|
||||
|
||||
h *= 60;
|
||||
if (h <= 0.0)
|
||||
h += 360;
|
||||
}
|
||||
|
||||
HsvColor hsvColor = new HsvColor();
|
||||
hsvColor.H = 360 - h;
|
||||
hsvColor.S = s;
|
||||
hsvColor.V = v / 255;
|
||||
|
||||
return hsvColor;
|
||||
|
||||
}
|
||||
|
||||
// Converts an HSV color to an RGB color.
|
||||
public static Color ConvertHsvToRgb(double h, double s, double v, float alpha)
|
||||
{
|
||||
|
||||
double r = 0, g = 0, b = 0;
|
||||
|
||||
if (s.Equals(0))
|
||||
{
|
||||
r = v;
|
||||
g = v;
|
||||
b = v;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
int i;
|
||||
double f, p, q, t;
|
||||
|
||||
|
||||
if (h.Equals(360))
|
||||
h = 0;
|
||||
else
|
||||
h = h / 60;
|
||||
|
||||
i = (int)(h);
|
||||
f = h - i;
|
||||
|
||||
p = v * (1.0 - s);
|
||||
q = v * (1.0 - (s * f));
|
||||
t = v * (1.0 - (s * (1.0f - f)));
|
||||
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
r = v;
|
||||
g = t;
|
||||
b = p;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
r = q;
|
||||
g = v;
|
||||
b = p;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
r = p;
|
||||
g = v;
|
||||
b = t;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
r = p;
|
||||
g = q;
|
||||
b = v;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
r = t;
|
||||
g = p;
|
||||
b = v;
|
||||
break;
|
||||
|
||||
default:
|
||||
r = v;
|
||||
g = p;
|
||||
b = q;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new Color((float)r, (float)g, (float)b, alpha);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion ColorUtilities
|
||||
|
||||
|
||||
// Describes a color in terms of
|
||||
// Hue, Saturation, and Value (brightness)
|
||||
#region HsvColor
|
||||
public struct HsvColor
|
||||
{
|
||||
/// <summary>
|
||||
/// The Hue, ranges between 0 and 360
|
||||
/// </summary>
|
||||
public double H;
|
||||
|
||||
/// <summary>
|
||||
/// The saturation, ranges between 0 and 1
|
||||
/// </summary>
|
||||
public double S;
|
||||
|
||||
// The value (brightness), ranges between 0 and 1
|
||||
public double V;
|
||||
|
||||
public float normalizedH
|
||||
{
|
||||
get
|
||||
{
|
||||
return (float)H / 360f;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
H = (double)value * 360;
|
||||
}
|
||||
}
|
||||
|
||||
public float normalizedS
|
||||
{
|
||||
get
|
||||
{
|
||||
return (float)S;
|
||||
}
|
||||
set
|
||||
{
|
||||
S = (double)value;
|
||||
}
|
||||
}
|
||||
|
||||
public float normalizedV
|
||||
{
|
||||
get
|
||||
{
|
||||
return (float)V;
|
||||
}
|
||||
set
|
||||
{
|
||||
V = (double)value;
|
||||
}
|
||||
}
|
||||
|
||||
public HsvColor(double h, double s, double v)
|
||||
{
|
||||
this.H = h;
|
||||
this.S = s;
|
||||
this.V = v;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{" + H.ToString("f2") + "," + S.ToString("f2") + "," + V.ToString("f2") + "}";
|
||||
}
|
||||
}
|
||||
#endregion HsvColor
|
||||
|
||||
|
||||
}
|
||||
|
||||
8
Assets/Scripts/HSVPicker/UtilityScripts/HSVUtil.cs.meta
Normal file
8
Assets/Scripts/HSVPicker/UtilityScripts/HSVUtil.cs.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f3189246d7fc204faba7a1e9c08e0af
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
11
Assets/Scripts/HSVPicker/package.json
Normal file
11
Assets/Scripts/HSVPicker/package.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "judah4.hsvcolorpickerunity",
|
||||
"displayName": "HSVPicker",
|
||||
"version": "3.0.1",
|
||||
"unity": "2019.4",
|
||||
"description": "HSV color picker for Unity UI",
|
||||
"keywords": [
|
||||
],
|
||||
"dependencies": {
|
||||
}
|
||||
}
|
||||
7
Assets/Scripts/HSVPicker/package.json.meta
Normal file
7
Assets/Scripts/HSVPicker/package.json.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d46aec3749789425caab28d9edf026cf
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user