Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

static function RGBToHSV(rgbColor: Color, H: float, S: float, V: float): void;
static void RGBToHSV(Color rgbColor, float H, float S, float V);
static def RGBToHSV(rgbColor as Color, H as float, S as float, V as float) as void

Parameters

rgbColorThe color to convert from.
HThe hue of the color is written to this variable.
SThe saturation of the color is written to this variable.
VThe value of the color is written to this variable.

Description

Convert a color from RGB to HSV color space.

All values are in the 0-1 range

See Also: HSVToRGB.

	// Simple script that shows the color info on 
	// RGB (Red Green Blue) values and
	// HSV (Hue Saturation Value) values.
	
	class RGBHSVInfo extends Editor{
			
		@MenuItem("Examples/Color Info")
		static function CheckColor() {
			var h : float = 0;
			var s : float = 0;
			var v : float = 0;		
			var objColor : Color = Color.white;
		
			var obj = Selection.activeGameObject.renderer;
			if(!obj.renderer.material) {
				Debug.LogError("Selected Object doesnt have a material.");
				return;
			}
			objColor = obj.renderer.sharedMaterial.color;
			EditorGUIUtility.RGBToHSV(objColor,h,s,v);
			objColor = EditorGUIUtility.HSVToRGB(h,s,v);
			Debug.Log("RGB: " + objColor.r + "," + objColor.g + "," + objColor.b);
			Debug.Log("HSV: " + h + "," + s + "," + v);
		}
		
		@MenuItem("Examples/Color Info", true)
		static function ValidateCheckColor() {
			return Selection.activeGameObject != null;
		}
	}