Exemple #1
0
        void OnModeChanged()
        {
            ColorPickerMode mode = ColorPickerUtils.GetActiveMode(m_ColorController.IsHdr);
            ColorPickerInfo info = ColorPickerUtils.GetInfoForMode(mode);

            if (m_ColorPickerSelectorBorderCube != null && m_ColorPickerSelectorBorderCylinder != null)
            {
                m_ColorPickerSelectorBorderCube.enabled     = false;
                m_ColorPickerSelectorBorderCylinder.enabled = false;
                if (info.cylindrical)
                {
                    m_ColorPickerSelectorBorderCylinder.enabled = true;
                }
                else
                {
                    m_ColorPickerSelectorBorderCube.enabled = true;
                }
            }

            if (m_CircleBack != null)
            {
                m_CircleBack.SetActive(info.cylindrical);
            }

            m_ColorPickerSelector.SetLocalMode(mode);
            m_ColorPickerSlider.SetLocalMode(mode);

            m_ColorController.CurrentColor = m_ColorController.CurrentColor;
        }
Exemple #2
0
        void UpdateColorSelectorAndSlider(bool inputValid, Ray inputRay, Collider parentCollider)
        {
            // Reset our input object if we're not holding the trigger.
            if (!InputManager.m_Instance.GetCommand(InputManager.SketchCommands.Activate))
            {
                ResetActiveInputObject();
            }

            // Color limits if we're tied to the brush color.
            float luminanceMin  = 0.0f;
            float saturationMax = 1.0f;
            BrushColorController brushController = m_ColorController as BrushColorController;

            if (brushController != null)
            {
                luminanceMin  = brushController.BrushLuminanceMin;
                saturationMax = brushController.BrushSaturationMax;
            }

            // Cache mode cause we use it a bunch.
            ColorPickerMode mode = ColorPickerUtils.GetActiveMode(m_ColorController.IsHdr);

            // Check for collision against our color slider first.
            RaycastHit hitInfo;

            if (m_ActiveInputObject == null || m_ActiveInputObject == m_ColorPickerSlider.gameObject)
            {
                bool validCollision = BasePanel.DoesRayHitCollider(inputRay,
                                                                   m_ColorPickerSlider.GetCollider(), out hitInfo);

                // TODO : ColorPickerSlider should be a UIComponent that handles this stuff
                // on its own.
                // If we're not colliding with the slider, but we were before, get our collision with
                // our parent collider.
                if (!validCollision && m_ActiveInputObject == m_ColorPickerSlider.gameObject)
                {
                    validCollision = BasePanel.DoesRayHitCollider(inputRay, parentCollider, out hitInfo);
                }

                if (validCollision)
                {
                    // Over slider, check for mouse down.
                    if (InputManager.m_Instance.GetCommand(InputManager.SketchCommands.Activate))
                    {
                        float value = ColorPickerUtils.ApplySliderConstraint(mode,
                                                                             m_ColorPickerSlider.GetValueFromHit(hitInfo),
                                                                             luminanceMin, saturationMax);
                        UpdateSelectorSlider(value);
                        UpdateSliderPosition();
                        Color newColor;
                        if (ColorPickerUtils.RawValueToColor(mode,
                                                             m_ColorPickerSelector.RawValue, out newColor))
                        {
                            m_ColorController.SetCurrentColorSilently(newColor);
                            TriggerColorPicked(newColor);
                        }
                        else
                        {
                            // Indicates some logic fault: the user isn't modifying the color plane,
                            // so why is the color plane's value outside the valid range?
                            Debug.LogErrorFormat("Unexpected bad RawValue. mode:{0} val:{1}", mode,
                                                 m_ColorPickerSelector.RawValue);
                        }

                        SketchSurfacePanel.m_Instance.VerifyValidToolWithColorUpdate();
                        m_ActiveInputObject = m_ColorPickerSlider.gameObject;
                    }
                }
            }

            if (m_ActiveInputObject == null || m_ActiveInputObject == m_ColorPickerSelector.gameObject)
            {
                if (BasePanel.DoesRayHitCollider(inputRay, m_ColorPickerSelector.GetCollider(),
                                                 out hitInfo))
                {
                    // Over color picker, check for input.
                    if (InputManager.m_Instance.GetCommand(InputManager.SketchCommands.Activate))
                    {
                        Vector3 value = ColorPickerUtils.ApplyPlanarConstraint(
                            m_ColorPickerSelector.GetValueFromHit(hitInfo),
                            mode, luminanceMin, saturationMax);
                        Color color;
                        if (ColorPickerUtils.RawValueToColor(mode, value, out color))
                        {
                            m_ColorPickerSelector.RawValue = value;
                            m_ColorController.SetCurrentColorSilently(color);
                            TriggerColorPicked(color);
                            m_ColorPickerSlider.OnColorChanged(mode, value);

                            SketchSurfacePanel.m_Instance.VerifyValidToolWithColorUpdate();
                            m_ActiveInputObject = m_ColorPickerSelector.gameObject;
                        }
                    }
                }
            }
        }