Colorx
(→Unity Package) |
m |
||
(6 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
Author: Jonathan Czeck (aarku) | Author: Jonathan Czeck (aarku) | ||
==Description== | ==Description== | ||
Line 16: | Line 13: | ||
==C# - Colorx.cs== | ==C# - Colorx.cs== | ||
− | <csharp>using UnityEngine; | + | <syntaxhighlight lang="csharp">using UnityEngine; |
public class Colorx | public class Colorx | ||
Line 25: | Line 22: | ||
} | } | ||
} | } | ||
− | </csharp> | + | </syntaxhighlight> |
+ | |||
+ | |||
+ | ==C# - Extended Colorx.cs== | ||
+ | This version of Colorx adds functions to manipulate H, S, and B values of any Color. By: [[User:Josh Koleszar|Josh Koleszar]] ([[User talk:Josh Koleszar|talk]]) 23:35, 20 October 2013 (CEST) | ||
+ | |||
+ | |||
+ | <syntaxhighlight lang="csharp"> | ||
+ | using UnityEngine; | ||
+ | using System.Collections; | ||
+ | |||
+ | public static class Colorx | ||
+ | { | ||
+ | // These functions are accessible from any Color struct. | ||
+ | // (Put this script in the Plugins folder for Javascript access) | ||
+ | |||
+ | public static Color Slerp(this Color a, Color b, float t) | ||
+ | { | ||
+ | return (HSBColor.Lerp(HSBColor.FromColor(a), HSBColor.FromColor(b), t)).ToColor(); | ||
+ | } | ||
+ | |||
+ | // To use the following functions, you must input the Color you wish to change. | ||
+ | // Example: | ||
+ | // myColor.H(180, ref myColor); | ||
+ | |||
+ | // You can either manipulate the values on a scale from 0 to 360 or | ||
+ | // on a scale from 0 to 1. | ||
+ | |||
+ | public static void H(this Color c, int hue0to360, ref Color thisColor) | ||
+ | { | ||
+ | HSBColor temp = HSBColor.FromColor(c); | ||
+ | temp.h = (hue0to360 / 360.0f); | ||
+ | thisColor = HSBColor.ToColor(temp); | ||
+ | } | ||
+ | |||
+ | public static void H(this Color c, float hue0to1, ref Color thisColor) | ||
+ | { | ||
+ | HSBColor temp = HSBColor.FromColor(thisColor); | ||
+ | temp.h = hue0to1; | ||
+ | thisColor = HSBColor.ToColor(temp); | ||
+ | } | ||
+ | |||
+ | public static void S(this Color c, int saturation0to360, ref Color thisColor) | ||
+ | { | ||
+ | HSBColor temp = HSBColor.FromColor(thisColor); | ||
+ | temp.s = saturation0to360 / 360.0f; | ||
+ | thisColor = HSBColor.ToColor(temp); | ||
+ | } | ||
+ | |||
+ | public static void S(this Color c, float saturation0to1, ref Color thisColor) | ||
+ | { | ||
+ | HSBColor temp = HSBColor.FromColor(thisColor); | ||
+ | temp.s = saturation0to1; | ||
+ | thisColor = HSBColor.ToColor(temp); | ||
+ | } | ||
+ | |||
+ | public static void B(this Color c, int brightness0to360, ref Color thisColor) | ||
+ | { | ||
+ | HSBColor temp = HSBColor.FromColor(thisColor); | ||
+ | temp.b = brightness0to360 / 360.0f; | ||
+ | thisColor = HSBColor.ToColor(temp); | ||
+ | } | ||
+ | |||
+ | public static void B(this Color c, float brightness0to1, ref Color thisColor) | ||
+ | { | ||
+ | HSBColor temp = HSBColor.FromColor(thisColor); | ||
+ | temp.b = brightness0to1; | ||
+ | thisColor = HSBColor.ToColor(temp); | ||
+ | } | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | [[Category: C Sharp]] | ||
+ | [[Category: Plugin]] | ||
+ | [[Category: Utility]] | ||
+ | [[Category: Color]] | ||
+ | [[Category: HSB]] |
Latest revision as of 21:36, 20 October 2013
Author: Jonathan Czeck (aarku)
Contents |
[edit] Description
This script provides a helper function to tie in with HSBColor that will let you slerp between two Unity Colors. The slerp function provides much more pleasing visual results than Color.Lerp.
[edit] Usage
Put this script in a file in /Plugins/Colorx.cs so that it may be callable by JavaScript. Additionally, there is a helper class called HSBColor that this relies on. This script, Colorx.cs, provides a quick helper function to slerp between two Colors, which gives much more visually pleasing results than Color.Lerp.
[edit] Unity Package
Download the attached package and import it into one of your projects.
[edit] C# - Colorx.cs
using UnityEngine; public class Colorx { public static Color Slerp(Color a, Color b, float t) { return (HSBColor.Lerp(HSBColor.FromColor(a), HSBColor.FromColor(b), t)).ToColor(); } }
[edit] C# - Extended Colorx.cs
This version of Colorx adds functions to manipulate H, S, and B values of any Color. By: Josh Koleszar (talk) 23:35, 20 October 2013 (CEST)
using UnityEngine; using System.Collections; public static class Colorx { // These functions are accessible from any Color struct. // (Put this script in the Plugins folder for Javascript access) public static Color Slerp(this Color a, Color b, float t) { return (HSBColor.Lerp(HSBColor.FromColor(a), HSBColor.FromColor(b), t)).ToColor(); } // To use the following functions, you must input the Color you wish to change. // Example: // myColor.H(180, ref myColor); // You can either manipulate the values on a scale from 0 to 360 or // on a scale from 0 to 1. public static void H(this Color c, int hue0to360, ref Color thisColor) { HSBColor temp = HSBColor.FromColor(c); temp.h = (hue0to360 / 360.0f); thisColor = HSBColor.ToColor(temp); } public static void H(this Color c, float hue0to1, ref Color thisColor) { HSBColor temp = HSBColor.FromColor(thisColor); temp.h = hue0to1; thisColor = HSBColor.ToColor(temp); } public static void S(this Color c, int saturation0to360, ref Color thisColor) { HSBColor temp = HSBColor.FromColor(thisColor); temp.s = saturation0to360 / 360.0f; thisColor = HSBColor.ToColor(temp); } public static void S(this Color c, float saturation0to1, ref Color thisColor) { HSBColor temp = HSBColor.FromColor(thisColor); temp.s = saturation0to1; thisColor = HSBColor.ToColor(temp); } public static void B(this Color c, int brightness0to360, ref Color thisColor) { HSBColor temp = HSBColor.FromColor(thisColor); temp.b = brightness0to360 / 360.0f; thisColor = HSBColor.ToColor(temp); } public static void B(this Color c, float brightness0to1, ref Color thisColor) { HSBColor temp = HSBColor.FromColor(thisColor); temp.b = brightness0to1; thisColor = HSBColor.ToColor(temp); } }