├── ColorBand.unitypackage
├── ColorBand
├── ColorBand.cs
├── ColorBand.cs.meta
├── ColorBands.meta
├── ColorBands
│ ├── Alpha Green.asset
│ ├── Alpha Green.asset.meta
│ ├── Alpha Waves.asset
│ ├── Alpha Waves.asset.meta
│ ├── Butterfly 01.asset
│ ├── Butterfly 01.asset.meta
│ ├── Chrome Ice.asset
│ ├── Chrome Ice.asset.meta
│ ├── Discrete 01.asset
│ ├── Discrete 01.asset.meta
│ ├── Discrete 02.asset
│ ├── Discrete 02.asset.meta
│ ├── Discrete BW.asset
│ ├── Discrete BW.asset.meta
│ ├── Fairy Wings.asset
│ ├── Fairy Wings.asset.meta
│ ├── HSVFullBand.asset
│ ├── HSVFullBand.asset.meta
│ ├── Hard Edge Blue Waves.asset
│ ├── Hard Edge Blue Waves.asset.meta
│ ├── HeatMap.asset
│ ├── HeatMap.asset.meta
│ ├── Lava 1.asset
│ ├── Lava 1.asset.meta
│ ├── Lovely Pastel.asset
│ ├── Lovely Pastel.asset.meta
│ ├── RedToBlue.asset
│ ├── RedToBlue.asset.meta
│ ├── StunningHeatmap 2.asset
│ ├── StunningHeatmap.asset
│ ├── _CantDoThisWithGradients 01.asset
│ ├── _CantDoThisWithGradients 01.asset.meta
│ ├── _CantDoThisWithGradients 02.asset
│ └── _CantDoThisWithGradients 02.asset.meta
├── Editor.meta
└── Editor
│ ├── ColorBandEditor.cs
│ └── ColorBandEditor.cs.meta
├── Images
├── ._CannotDoThisWithGradients 01.png
├── ._CannotDoThisWithGradients 02.png
├── ._ColorSpace.png
├── ._Discrete02.png
├── ._HSVExample.png
├── ._Screenshot_03.png
├── ._Screenshot_05.png
├── .__CantDoThisWithGradients 03.png
├── ._screenshot_01.png
├── CannotDoThisWithGradients 01.png
├── CannotDoThisWithGradients 02.png
├── ColorSpace.png
├── Discrete02.png
├── HSVExample.png
├── Screenshot_02.png
├── Screenshot_03.png
├── Screenshot_04.png
├── Screenshot_05.png
├── Screenshot_06.png
├── _CantDoThisWithGradients 03.png
└── screenshot_01.png
├── LICENSE
└── README.md
/ColorBand.unitypackage:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand.unitypackage
--------------------------------------------------------------------------------
/ColorBand/ColorBand.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | public class ColorBand : ScriptableObject {
5 |
6 | public string name = "New Color Band";
7 |
8 | public AnimationCurve RCurve;
9 | public AnimationCurve GCurve;
10 | public AnimationCurve BCurve;
11 | public AnimationCurve ACurve;
12 |
13 | public enum COLORSPACE { RGB, HSV };
14 | public COLORSPACE colorSpace = COLORSPACE.RGB;
15 |
16 | public bool applyRequired { get; set; } // Apply button in inspector
17 |
18 | public Texture2D previewTexture;
19 | public bool biggerPreview = false;
20 |
21 | public bool discrete = false;
22 | public int discreteSteps = 16;
23 | public enum DISCRETE_METHOD { LEFT_VALUE, RIGHT_VALUE, CENTER_VALUE };
24 | public DISCRETE_METHOD discreteMethod = DISCRETE_METHOD.LEFT_VALUE;
25 |
26 | int Wt = 128, Wt_big = 256;
27 | int Ht = 8, Ht_big = 8;
28 |
29 | public ColorBand()
30 | {
31 | #if !UNITY_5_3_OR_NEWER
32 | previewTexture = new Texture2D(Wt, Ht);
33 | #endif
34 | RCurve = AnimationCurve.Linear(timeStart:0f, valueStart:0f, timeEnd:1f, valueEnd:1f);
35 | GCurve = AnimationCurve.Linear(timeStart:0f, valueStart:0f, timeEnd:1f, valueEnd:1f);
36 | BCurve = AnimationCurve.Linear(timeStart:0f, valueStart:0f, timeEnd:1f, valueEnd:1f);
37 | ACurve = AnimationCurve.Linear(timeStart:0f, valueStart:1f, timeEnd:1f, valueEnd:1f); // Initialized as constant to 1f
38 |
39 | #if !UNITY_5_3_OR_NEWER
40 | buildPreviewTexture();
41 | #endif
42 | }
43 |
44 | void OnEnable()
45 | {
46 | #if UNITY_5_3_OR_NEWER
47 | previewTexture = new Texture2D(Wt, Ht);
48 | #endif
49 | buildPreviewTexture();
50 | }
51 |
52 | Color GetColorAt(float t, bool useAlpha = false, COLORSPACE _colorSpace = COLORSPACE.RGB)
53 | {
54 | //UnityEngine.Assertions.Assert.IsTrue(t >= 0f && t <= 1f, "t is out of [0..1] range");
55 |
56 | if (_colorSpace == COLORSPACE.RGB)
57 | {
58 | if (useAlpha)
59 | {
60 | return new Color(RCurve.Evaluate(t), GCurve.Evaluate(t), BCurve.Evaluate(t), ACurve.Evaluate(t));
61 | }
62 | else
63 | {
64 | return new Color(RCurve.Evaluate(t), GCurve.Evaluate(t), BCurve.Evaluate(t));
65 | }
66 | }
67 | else // if(_colorSpace == COLORSPACE.HSV)
68 | {
69 | if (useAlpha)
70 | {
71 | Color ac = Color.HSVToRGB(RCurve.Evaluate(t), GCurve.Evaluate(t), BCurve.Evaluate(t));
72 | return new Color(ac.r, ac.g, ac.b, ACurve.Evaluate(t));
73 | }
74 | else
75 | {
76 | return Color.HSVToRGB(RCurve.Evaluate(t), GCurve.Evaluate(t), BCurve.Evaluate(t));
77 | }
78 | }
79 | }
80 |
81 | ///
82 | /// Builds the preview texture.
83 | ///
84 | void buildPreviewTexture()
85 | {
86 | // This can happen on load project and other cases
87 | if(previewTexture == null)
88 | {
89 | if(biggerPreview)
90 | previewTexture = new Texture2D(Wt_big, Ht_big, TextureFormat.RGBA32, false);
91 | else
92 | previewTexture = new Texture2D(Wt, Ht, TextureFormat.RGBA32, false);
93 | }
94 |
95 | int W = previewTexture.width;
96 | int H = previewTexture.height;
97 | previewTexture.wrapMode = TextureWrapMode.Clamp;
98 | previewTexture.filterMode = FilterMode.Point;
99 |
100 | Color[] colors = new Color[W*H];
101 |
102 | Color bgColor = Color.black;
103 |
104 |
105 | for(int i=0; i
166 | /// Evaluates color curves at time time01
167 | ///
168 | /// The time point where the color is computed. Value must be between 0 and 1.
169 | /// The color in the current color space.
170 | public Color Evaluate(float time01)
171 | {
172 | if(!discrete)
173 | {
174 | //return new Color(RCurve.Evaluate(time01), GCurve.Evaluate(time01), BCurve.Evaluate(time01)); // HSV FIX
175 | return GetColorAt(time01, false, colorSpace);
176 | }
177 | else
178 | {
179 | float t = -1f;
180 | if (discreteMethod == DISCRETE_METHOD.LEFT_VALUE)
181 | t = Mathf.Floor(time01 * discreteSteps) / discreteSteps;
182 | else if (discreteMethod == DISCRETE_METHOD.RIGHT_VALUE)
183 | t = Mathf.Ceil(time01 * discreteSteps) / discreteSteps;
184 | else if (discreteMethod == DISCRETE_METHOD.CENTER_VALUE)
185 | t = 0.5f * (Mathf.Floor(time01 * discreteSteps) / discreteSteps + Mathf.Ceil(time01 * discreteSteps) / discreteSteps);
186 | return GetColorAt(t, false, colorSpace);
187 | }
188 |
189 | }
190 |
191 | }
192 |
--------------------------------------------------------------------------------
/ColorBand/ColorBand.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4d56735a19688dd489c679a17ae01b84
3 | timeCreated: 1448362275
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 695f70342cbc836408e35a09fcbf562d
3 | folderAsset: yes
4 | timeCreated: 1448376416
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Alpha Green.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/Alpha Green.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Alpha Green.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 47d875c9023372d4a8adfc6e25af0fdf
3 | timeCreated: 1471255725
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Alpha Waves.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/Alpha Waves.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Alpha Waves.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ad38dd76972764fd8b16488c2c25bae5
3 | timeCreated: 1450439930
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Butterfly 01.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/Butterfly 01.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Butterfly 01.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3427678bce87a0845b966419f2222e77
3 | timeCreated: 1448376617
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Chrome Ice.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/Chrome Ice.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Chrome Ice.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 36d55f79ee15005408b04512823d0ad6
3 | timeCreated: 1448376777
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Discrete 01.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/Discrete 01.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Discrete 01.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d5437f2927c4c314ab6ea7c013c3962e
3 | timeCreated: 1471254370
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Discrete 02.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/Discrete 02.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Discrete 02.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 20863af5a6e12cb47bad6b4d861ecf03
3 | timeCreated: 1471256054
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Discrete BW.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/Discrete BW.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Discrete BW.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: dac52645bf3d069498b600e076ea862a
3 | timeCreated: 1471254370
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Fairy Wings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/Fairy Wings.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Fairy Wings.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 05215f764363ac14babbad592cbde30b
3 | timeCreated: 1448375861
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/HSVFullBand.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/HSVFullBand.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/HSVFullBand.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e35e9a4e5ea80444d8fef6a2b5103ef3
3 | timeCreated: 1472128845
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Hard Edge Blue Waves.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/Hard Edge Blue Waves.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Hard Edge Blue Waves.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3f85df20677e6834084bc2ffba82bc28
3 | timeCreated: 1448377437
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/HeatMap.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/HeatMap.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/HeatMap.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 763cdc666bc3d4448b0688a8c0e179e2
3 | timeCreated: 1448371002
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Lava 1.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/Lava 1.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Lava 1.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7a8f6f068c6c33b46a9518b7e4ccb0ba
3 | timeCreated: 1448375992
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Lovely Pastel.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/Lovely Pastel.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/Lovely Pastel.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: dfe714601153cfd41a6cd9bbfff971cb
3 | timeCreated: 1448370527
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/RedToBlue.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/RedToBlue.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/RedToBlue.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 52c2140e71706154c9cb2534583a67ba
3 | timeCreated: 1448370443
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/StunningHeatmap 2.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/StunningHeatmap 2.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/StunningHeatmap.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/StunningHeatmap.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/_CantDoThisWithGradients 01.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/_CantDoThisWithGradients 01.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/_CantDoThisWithGradients 01.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a2d22a17a896ca14c898879f42921ff0
3 | timeCreated: 1448961672
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/ColorBands/_CantDoThisWithGradients 02.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/ColorBand/ColorBands/_CantDoThisWithGradients 02.asset
--------------------------------------------------------------------------------
/ColorBand/ColorBands/_CantDoThisWithGradients 02.asset.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4f71625bb41e72347934d36c1fea8835
3 | timeCreated: 1448964822
4 | licenseType: Pro
5 | NativeFormatImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ColorBand/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a472e379aedfc0645bdbc170a29f38be
3 | folderAsset: yes
4 | timeCreated: 1448877998
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/ColorBand/Editor/ColorBandEditor.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using UnityEditor;
4 |
5 | [CustomEditor(typeof(ColorBand))]
6 | public class ColorBandEditor : Editor {
7 |
8 | public static Texture2D alphaPatternTexture;
9 |
10 | Color guiColor, guiContentColor, guiBackgroundColor;
11 |
12 | // TESTING FIELDS
13 | bool m_testingFoldout;
14 | float m_test_time_sample;
15 | Color m_test_out_color;
16 |
17 | public override void OnInspectorGUI ()
18 | {
19 | guiColor = GUI.color;
20 | guiContentColor = GUI.contentColor;
21 | guiBackgroundColor = GUI.backgroundColor;
22 |
23 | // get the target class
24 | ColorBand _target = (ColorBand)target;
25 |
26 | Undo.RecordObject(_target, "Color Band Change");
27 |
28 | bool previousBiggerPreviewToggle = _target.biggerPreview;
29 |
30 | if (alphaPatternTexture == null)
31 | InitAlphaBackgroundPattern();
32 |
33 | // the preview texture leaks at non deterministic times in the editor so we have to watch it
34 | if(_target.previewTexture == null)
35 | {
36 | _target.rebuildPreviewTexture();
37 | }
38 |
39 | EditorGUILayout.BeginVertical();
40 | EditorGUILayout.BeginHorizontal();
41 | GUILayout.Label("Preview", GUILayout.Width(100f));
42 | GUILayout.Label("(high precision preview", GUILayout.Width(150f));
43 | _target.biggerPreview = EditorGUILayout.Toggle(_target.biggerPreview, GUILayout.MaxWidth(10f));
44 | GUILayout.Label(")", GUILayout.Width(8f));
45 | // force to rebuild texture when switching to bigger and back
46 | if (previousBiggerPreviewToggle != _target.biggerPreview)
47 | {
48 | _target.previewTexture = null;
49 | _target.rebuildPreviewTexture();
50 | }
51 | EditorGUILayout.EndHorizontal();
52 |
53 | EditorGUILayout.Space();
54 | Rect r = GUILayoutUtility.GetLastRect();
55 | r.height = 32f;
56 | GUI.DrawTextureWithTexCoords(r, alphaPatternTexture, new Rect(0, 0, r.width * .75f / alphaPatternTexture.width, r.height * .75f / alphaPatternTexture.height));
57 | GUI.DrawTexture(r, _target.previewTexture, ScaleMode.StretchToFill, true);
58 | EditorGUILayout.Space();
59 | EditorGUILayout.Space();
60 | EditorGUILayout.Space();
61 | EditorGUILayout.Space();
62 | EditorGUILayout.Space();
63 | //GUILayout.Label(_target.previewTexture);
64 | //EditorGUILayout.ColorField(new Color(0f,0f,0.5f));
65 |
66 | EditorGUILayout.BeginHorizontal();
67 |
68 | _target.name = EditorGUILayout.TextField("Name", _target.name);
69 | // Get filename of the colorband and set its name with the resulting string
70 | if (GUILayout.Button("Set as filename", GUILayout.MaxWidth(110f)))
71 | {
72 | string[] pathParts = (AssetDatabase.GetAssetPath(_target)).Split('/');
73 | string assetName = pathParts[pathParts.Length - 1].Split('.')[0];
74 | _target.name = assetName;
75 | }
76 | EditorGUILayout.EndHorizontal();
77 |
78 | //Color Space
79 | _target.colorSpace = (ColorBand.COLORSPACE) EditorGUILayout.EnumPopup("Color Space", _target.colorSpace);
80 |
81 | // Curve controls
82 | GUI.contentColor = new Color (1f, .4f, .4f);
83 | string rcurvename = (_target.colorSpace == ColorBand.COLORSPACE.RGB) ? "Red Curve" : "Hue Curve";
84 | _target.RCurve = EditorGUILayout.CurveField(rcurvename, _target.RCurve);
85 | GUI.contentColor = new Color (.4f, 1f, .4f);
86 | string gcurvename = (_target.colorSpace == ColorBand.COLORSPACE.RGB) ? "Green Curve" : "Saturation Curve";
87 | _target.GCurve = EditorGUILayout.CurveField(gcurvename, _target.GCurve);
88 | GUI.contentColor = new Color (.4f, .4f, 1f);
89 | string bcurvename = (_target.colorSpace == ColorBand.COLORSPACE.RGB) ? "Blue Curve" : "Value Curve";
90 | _target.BCurve = EditorGUILayout.CurveField(bcurvename, _target.BCurve);
91 | GUI.contentColor = new Color (.85f, .85f, .95f);
92 | _target.ACurve = EditorGUILayout.CurveField("Alpha Curve", _target.ACurve);
93 | EditorGUILayout.EndVertical();
94 |
95 | GUI.contentColor = guiColor;
96 |
97 | EditorGUILayout.Space();
98 |
99 |
100 | EditorGUILayout.BeginHorizontal();
101 | _target.discrete = EditorGUILayout.Toggle("Discrete", _target.discrete);
102 | if (_target.discrete)
103 | {
104 | _target.discreteSteps = EditorGUILayout.IntSlider("Steps", _target.discreteSteps, 2, 256);
105 | }
106 | EditorGUILayout.EndHorizontal();
107 | if(_target.discrete)
108 | {
109 | _target.discreteMethod = (ColorBand.DISCRETE_METHOD)EditorGUILayout.EnumPopup("Discretization Method", _target.discreteMethod);
110 | }
111 |
112 | EditorGUILayout.BeginHorizontal();
113 | if(GUILayout.Button("Save as image"))
114 | {
115 | string saveFileName = EditorUtility.SaveFilePanelInProject("Save ColorBand as PNG", _target.name, "png", "Please enter a filename to save the ColorBand to");
116 | if (saveFileName != "")
117 | {
118 | _target.rebuildPreviewTexture();
119 | byte[] bytes = _target.previewTexture.EncodeToPNG();
120 | System.IO.File.WriteAllBytes(saveFileName, bytes);
121 | }
122 | }
123 | EditorGUILayout.EndHorizontal();
124 |
125 | // When GUI changes save the ColorBand and rebuild the texture.
126 | if(GUI.changed)
127 | {
128 | _target.rebuildPreviewTexture();
129 | _target.applyRequired = true;
130 | }
131 |
132 | if(_target.applyRequired)
133 | {
134 | GUI.color = new Color(1f, .4f, 0f);
135 | if(GUILayout.Button("Apply"))
136 | {
137 | AssetDatabase.SaveAssets();
138 | EditorUtility.SetDirty(_target);
139 | _target.rebuildPreviewTexture();
140 | _target.applyRequired = false;
141 | }
142 | GUI.color = guiColor;
143 | EditorGUILayout.HelpBox("Applying is required to make changes persistent.", MessageType.Warning);
144 | }
145 |
146 | if(m_testingFoldout = EditorGUILayout.Foldout(m_testingFoldout, "Testing Tools"))
147 | {
148 | DebugSample();
149 | }
150 |
151 | #if UNITY_5
152 | EditorGUILayout.Space();
153 | EditorGUILayout.HelpBox("Warning: In Unity 5 there's some color inconsistency between preview and actual evaluated vaules. See Known Issues at https://github.com/rstecca/ColorBands/ for further details.", MessageType.Warning);
154 | #endif
155 |
156 | }
157 |
158 | [MenuItem("Assets/Create/Color Band")]
159 | public static void CreateColorBand()
160 | {
161 | ColorBand newCB = ScriptableObject.CreateInstance();
162 | string newfnameRoot = "New Color Band";
163 | string newfname = newfnameRoot;
164 | int i=0;
165 | while(System.IO.File.Exists("Assets/" + newfname + ".asset") && i<1000)
166 | {
167 | newfname = new System.Text.StringBuilder(newfnameRoot).Append(" ").Append(i.ToString("D" + 3)).ToString();
168 | i++;
169 | }
170 | newCB.name = newfname;
171 | AssetDatabase.CreateAsset(newCB, "Assets/"+newfname+".asset");
172 | AssetDatabase.SaveAssets();
173 |
174 | EditorUtility.FocusProjectWindow();
175 |
176 | Selection.activeObject = newCB;
177 | }
178 |
179 |
180 | public void DebugSample()
181 | {
182 | ColorBand _target = (ColorBand)target;
183 | EditorGUILayout.LabelField("Sample", EditorStyles.boldLabel);
184 | EditorGUILayout.BeginHorizontal();
185 | serializedObject.Update();
186 | EditorGUI.BeginChangeCheck();
187 | m_test_time_sample = EditorGUILayout.Slider(m_test_time_sample, 0f, 1f);
188 | if (EditorGUI.EndChangeCheck())
189 | {
190 | m_test_out_color = _target.Evaluate(m_test_time_sample);
191 | }
192 | serializedObject.ApplyModifiedProperties();
193 | EditorGUILayout.ColorField(m_test_out_color, GUILayout.MaxWidth(100f));
194 | EditorGUILayout.EndHorizontal();
195 |
196 | // Further infos
197 | //EditorGUILayout.BeginHorizontal();
198 | //EditorGUILayout.LabelField(
199 | // string.Format("R {0:0.000}\t{1:000}\t{2:X}\nG {3:0.000}\t{4:000}\t{5:X}\nB {6:0.000}\t{7:000}\t{8:X}\nA {9:0.000}\t{10:000}\t{11:X}", m_test_out_color.r, m_test_out_color.r*255, (System.Byte)(m_test_out_color.r*255), m_test_out_color.g, m_test_out_color.g * 255, (System.Byte)(m_test_out_color.g * 255), m_test_out_color.b, m_test_out_color.b * 255, (System.Byte)(m_test_out_color.b * 255), m_test_out_color.a, m_test_out_color.a * 255, (System.Byte)(m_test_out_color.a * 255))
200 | // , EditorStyles.helpBox, GUILayout.MaxWidth(160f));
201 | //EditorGUILayout.EndHorizontal();
202 |
203 | }
204 |
205 | private void InitAlphaBackgroundPattern()
206 | {
207 | // GENERATE ALPHA BACKGROUND PATTERN
208 | if (alphaPatternTexture == null)
209 | {
210 | alphaPatternTexture = new Texture2D(8, 8);
211 | int w = alphaPatternTexture.width;
212 | int h = alphaPatternTexture.height;
213 | Color patternColor1 = new Color(.75f, .75f, .75f); // BRIGHT
214 | Color patternColor2 = new Color(.5f, .5f, .5f); // DARK
215 | Color bgColor;
216 | Color[] colors = new Color[w * h];
217 | for (int i = 0; i < w; i++)
218 | {
219 | for (int j = 0; j < h; j++)
220 | {
221 | if ((i % 8 ^ j % 8) < 4)
222 | bgColor = patternColor1;
223 | else
224 | bgColor = patternColor2;
225 |
226 | colors[i + j * w] = bgColor;
227 | }
228 | }
229 | alphaPatternTexture.SetPixels(colors);
230 | alphaPatternTexture.wrapMode = TextureWrapMode.Repeat;
231 | alphaPatternTexture.filterMode = FilterMode.Bilinear;
232 | alphaPatternTexture.Apply();
233 | }
234 | }
235 |
236 | }
237 |
--------------------------------------------------------------------------------
/ColorBand/Editor/ColorBandEditor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c05d21664e58d67469784a66d3045130
3 | timeCreated: 1448362493
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Images/._CannotDoThisWithGradients 01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/._CannotDoThisWithGradients 01.png
--------------------------------------------------------------------------------
/Images/._CannotDoThisWithGradients 02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/._CannotDoThisWithGradients 02.png
--------------------------------------------------------------------------------
/Images/._ColorSpace.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/._ColorSpace.png
--------------------------------------------------------------------------------
/Images/._Discrete02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/._Discrete02.png
--------------------------------------------------------------------------------
/Images/._HSVExample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/._HSVExample.png
--------------------------------------------------------------------------------
/Images/._Screenshot_03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/._Screenshot_03.png
--------------------------------------------------------------------------------
/Images/._Screenshot_05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/._Screenshot_05.png
--------------------------------------------------------------------------------
/Images/.__CantDoThisWithGradients 03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/.__CantDoThisWithGradients 03.png
--------------------------------------------------------------------------------
/Images/._screenshot_01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/._screenshot_01.png
--------------------------------------------------------------------------------
/Images/CannotDoThisWithGradients 01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/CannotDoThisWithGradients 01.png
--------------------------------------------------------------------------------
/Images/CannotDoThisWithGradients 02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/CannotDoThisWithGradients 02.png
--------------------------------------------------------------------------------
/Images/ColorSpace.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/ColorSpace.png
--------------------------------------------------------------------------------
/Images/Discrete02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/Discrete02.png
--------------------------------------------------------------------------------
/Images/HSVExample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/HSVExample.png
--------------------------------------------------------------------------------
/Images/Screenshot_02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/Screenshot_02.png
--------------------------------------------------------------------------------
/Images/Screenshot_03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/Screenshot_03.png
--------------------------------------------------------------------------------
/Images/Screenshot_04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/Screenshot_04.png
--------------------------------------------------------------------------------
/Images/Screenshot_05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/Screenshot_05.png
--------------------------------------------------------------------------------
/Images/Screenshot_06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/Screenshot_06.png
--------------------------------------------------------------------------------
/Images/_CantDoThisWithGradients 03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/_CantDoThisWithGradients 03.png
--------------------------------------------------------------------------------
/Images/screenshot_01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rstecca/ColorBands/97d913ebc21f9309485519bd2d4da8928342a88d/Images/screenshot_01.png
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Riccardo Stecca
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # New Features
2 |
3 | 19/11/2018: better preview, improved input method and preview update performance.
4 |
5 | 06/12/2018: inspector testing tools: Sample Test allows to quickly test the color resulting from a [0..1] value.
6 |
7 | **Please note that whilst images in this documentation are still OK for reference they are not up to date and they will be updated as soon as possible.**
8 |
9 | # ColorBands
10 | Unity 3D's *Gradient* is a handy data type but comes with some limitations: for example you cannot set more than 8 color keys in its editor and RGB is the only color space available. *ColorBand* data type offers an alternative with less limitations. Creating ColorBands is fun and easy; they are stored as assets and can be accessed from code through an *Evaluate* method to get the color at time t, as for *Gradient*. RGB (or HSV) values are described by individual curves, allowing a better control over how the color function evolves between your points.
11 | Color bands are used in all kinds of applications including games, data visualization and other fields.
12 |
13 | 
14 |
15 | **Examples of color bands you cannot obtain with Unity's Gradient**
16 |
17 | 
18 |
19 | 
20 |
21 | 
23 |
24 | ## Usage
25 | 1) **Create a new Color Band asset**
26 |
27 | 
28 |
29 | Newly created ColorBands will be placed in Assets folder's root.
30 |
31 | 2) **Change its name and its red, green, blue and alpha curves to obtain the desired effect**. You can hit *Set as filename* to quickly set the name from the new color band's filename. Note that curves' values should remain between 0 and 1 in both dimensions *time* and *value*.
32 |
33 | 
34 |
35 | 
36 |
37 | 3) **Declare a public ColorBand variable in your script**
38 |
39 | 4) **Assign a color band asset to it**
40 |
41 | 5) **Use it in code by calling the *ColorBand.Evaluate(float t)* method** where t is a floating point value between 0 and 1.
42 |
43 | 
44 |
45 | ## Discretization
46 | A ColorBand can be discretized which means it will be turned into a set of flat intervals that will return a constant color.
47 | To make a ColorBand discrete just set its discrete toggle to true and decide the number of steps the ColorBand will be subdivided into. This will result in discrete bands like the following:
48 |
49 | 
50 |
51 | Three different discretization methods are available:
52 | - LEFT_VALUE will build color intervals by evaluating the color at their left extreme.
53 | - RIGHT_VALUE will build color intervals by evaluating the color at their right extreme.
54 | - CENTER_VALUE will build color intervals by evaluating the color at their center.
55 |
56 | ## Color Space
57 |
58 | 
59 |
60 | ColorBands can be described in the two main, standard color spaces RGB and HSV. By default a ColorBand will be set to RGB. When changing color space all the curves remain unvaried but they represent the respective values of the two spaces so that when switching to HSV, the first curve becomes hue, the second one saturation and the third one value. The alpha curve has the same meaning in both color spaces.
61 |
62 | 
63 |
64 | # Known Issues
65 | 1. In Unity 5.6.4 and likely in other subversions of Unity 5, there's color inconsistency between the preview in the inspector and the actual evaluated values. This can be seen when exporting the ColorBand to PNG. A good case to look at is the ColorBand called 'Red to Blue', included in the repo. The issue seems to have been solved as in Unity 2017 and 2018 this doesn't happen.
66 | 2. In Testing Tools > Sample, the color in the box is not initialized with it's real value at zero. It falls back to black instead.
67 |
--------------------------------------------------------------------------------