} //LoadCustomColors //--Private Functions---------------------------------------------------------------- //------------------------------------------------------------------------------------------- private void InitFromColor(Color c) { _oldRGBColor.FromUnityColor(c); _rgbColor.FromUnityColor(c); _hsvColor = _rgbColor.ToHSV(); _hexStr = _rgbColor.ToHexStr(); _colorPickBoxTintColor = new HSVColor(_hsvColor.h, 1.0f, 1.0f).ToRGBColor(null).ToUnityColor(); } //InitFromColor
} //SetMode void Update() { if (!_showCP) { return; } _mousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y); _mousePosition.y = Screen.height - _mousePosition.y; Vector2 correctedMP = _mousePosition; if (_draggingHMeter) { correctedMP.x = correctedMP.x - (_cpWinRect.x + _cpHSliderVerticalRect.x); correctedMP.y = Mathf.Clamp(correctedMP.y - (_cpWinRect.y + _cpHSliderVerticalRect.y), 0, _cpHSliderVerticalRect.height); _hsvColor.h = (correctedMP.y / _cpHSliderVerticalRect.height) * 359; _rgbColor = _hsvColor.ToRGBColor(_rgbColor); _hexStr = _rgbColor.ToHexStr(); _colorPickBoxTintColor = new HSVColor(_hsvColor.h, 1.0f, 1.0f).ToRGBColor(null).ToUnityColor(); AssignColor(_rgbColor); if (Input.GetMouseButtonUp(0)) { _draggingHMeter = false; } } //if if (_draggingColorCursor) { correctedMP.x = Mathf.Clamp(correctedMP.x - (_cpWinRect.x + _cpColorSelectRect.x), 0, _cpColorSelectRect.width); correctedMP.y = Mathf.Clamp(correctedMP.y - (_cpWinRect.y + _cpColorSelectRect.y), 0, _cpColorSelectRect.height); if (_cpMode == CPMODE.COLORBOX) { _hsvColor.s = correctedMP.x / _cpColorSelectRect.width; _hsvColor.v = (_cpColorSelectRect.height - correctedMP.y) / _cpColorSelectRect.height; } //if else { float distance = Mathf.Clamp(Vector2.Distance(correctedMP, new Vector2(_cpColorSelectRect.width / 2, _cpColorSelectRect.width / 2)), 0, _cpColorSelectRect.width / 2); correctedMP.x = ((correctedMP.x / _cpColorSelectRect.width) * 2) - 1; correctedMP.y = ((correctedMP.y / _cpColorSelectRect.width) * 2) - 1; _hsvColor.h = Mathf.Atan2(-correctedMP.y, correctedMP.x); if (_hsvColor.h < 0) { _hsvColor.h += Mathf.PI * 2; } _hsvColor.h = _hsvColor.h * Mathf.Rad2Deg; _hsvColor.s = distance / (_cpColorSelectRect.width / 2); } //else _rgbColor = _hsvColor.ToRGBColor(_rgbColor); _hexStr = _rgbColor.ToHexStr(); _colorPickBoxTintColor = new HSVColor(_hsvColor.h, 1.0f, 1.0f).ToRGBColor(null).ToUnityColor(); AssignColor(_rgbColor); if (Input.GetMouseButtonUp(0)) { _draggingColorCursor = false; } } //if if (_eyeDropperActive) { UpdateZoomedTexture(); if (Input.GetMouseButtonDown(0)) { _rgbColor.FromUnityColor(ZoomedTex.GetPixel(5, 5)); //_rgbColor.a = 1.0; _hsvColor = _rgbColor.ToHSV(); _hexStr = _rgbColor.ToHexStr(); _colorPickBoxTintColor = new HSVColor(_hsvColor.h, 1.0f, 1.0f).ToRGBColor(null).ToUnityColor(); AssignColor(_rgbColor); _eyeDropperActive = false; } //if } //if //Close ColorPicker if Escape is pressed if (Input.GetKeyUp(KeyCode.Escape)) { AssignColor(_oldRGBColor); OnColorCancelEvent(_oldRGBColor, _rgbColor); Hide(); } //if if (_customColorsDirty && _customColorsUpdateTime > 1.5f) { _customColorsUpdateTime = 0.0f; _customColorsDirty = false; OnCustomColorSaveEvent(BuildCustomColorFileContent()); } //if else { _customColorsUpdateTime += Time.deltaTime; } //else } //Update