Beispiel #1
0
        public void GenerateTextures()
        {
            rainbow    = TextureUtils.GenerateRainbowGradient(120, 20);
            colorField = TextureUtils.GenerateColorField(colorFieldSize, colorFieldSize,
                                                         currentRGBColor);

            if (sliderMode == 0)
            {
                slider1Texture = TextureUtils.GenerateGradientTexture(100, 20,
                                                                      new Color(0.0f, currentRGBColor.g, currentRGBColor.b, 1.0f),
                                                                      new Color(1.0f, currentRGBColor.g, currentRGBColor.b, 1.0f));
                slider2Texture = TextureUtils.GenerateGradientTexture(100, 20,
                                                                      new Color(currentRGBColor.r, 0f, currentRGBColor.b, 1.0f),
                                                                      new Color(currentRGBColor.r, 1f, currentRGBColor.b, 1.0f));
                slider3Texture = TextureUtils.GenerateGradientTexture(100, 20,
                                                                      new Color(currentRGBColor.r, currentRGBColor.g, 0f, 1.0f),
                                                                      new Color(currentRGBColor.r, currentRGBColor.g, 1f, 1.0f));
                slider4Texture = TextureUtils.GenerateGradientTexture(100, 20,
                                                                      Color.black,
                                                                      Color.white);
            }
            else
            {
                slider1Texture = TextureUtils.GenerateRainbowGradient(120, 20);
                slider2Texture = TextureUtils.GenerateGradientTexture(100, 20,
                                                                      new ColorHSV(currentHSVColor.h, 0f, currentHSVColor.v).ToRGB(),
                                                                      new ColorHSV(currentHSVColor.h, 1f, currentHSVColor.v).ToRGB());
                slider3Texture = TextureUtils.GenerateGradientTexture(100, 20,
                                                                      new ColorHSV(currentHSVColor.h, currentHSVColor.s, 0f).ToRGB(),
                                                                      new ColorHSV(currentHSVColor.h, currentHSVColor.s, 1f).ToRGB());
                slider4Texture = TextureUtils.GenerateGradientTexture(100, 20,
                                                                      Color.black,
                                                                      Color.white);
            }

            swatch = TextureUtils.GenerateColorTexture(40, 20,
                                                       currentRGBColor);


            barCarat = TextureUtils.GenerateSliderCarat(5, 20,
                                                        new Color(1f, 1f, 1f, 0.75f),
                                                        Color.black);

            fieldCarat = TextureUtils.GenerateRoundCarat(20, 20, Color.white, Color.black);
        }
        private void GetLightValues()
        {
            intensityValue  = light.intensity;
            intensityString = light.intensity.ToString();

            rangeString = light.range.ToString();
            rangeValue  = light.range;

            angleString = light.angle.ToString();
            angleValue  = light.angle;

            colorValue   = light.color;
            colorString  = MaterialUtils.ColorToStringArray(colorValue);
            colorTexture = TextureUtils.GenerateColorTexture(32, 32, colorValue);

            if (light.lightType == LightType.Point)
            {
                typeFlag = 1;
            }
            else
            {
                typeFlag = 0;
            }
        }
        protected void DrawLightEdit()
        {
            float  headerWidth = 120f;
            bool   delta       = false;
            float  sliderVal;
            string textVal;

            GUILayout.Label("<b>Light Parameters</b>");

            GUILayout.BeginHorizontal();
            GUILayout.Label("Light Color", GUILayout.Width(headerWidth));
            GUILayout.Space(10);

            // Button to set that we are toggling the color picker
            if (GUILayout.Button("", GUILayout.Width(60)))
            {
                colorEdit = !colorEdit;
                Utils.Log($"[CP] Edit flag state {colorEdit}", LogType.UI);
                // if yes, open the window
                if (colorEdit)
                {
                    WaterfallUI.Instance.OpenColorEditWindow(colorValue);
                    Utils.Log("[CP] Open Window", LogType.UI);
                }
            }

            // If picker open
            if (colorEdit)
            {
                // Close all other pickers


                var c = WaterfallUI.Instance.GetColorFromPicker();
                if (!c.IsEqualTo(colorValue))
                {
                    colorValue = c;
                    delta      = true;
                }

                if (delta)
                {
                    colorTexture = TextureUtils.GenerateColorTexture(64, 32, colorValue);
                    model.SetLightColor(light, colorValue);
                }
            }


            var tRect = GUILayoutUtility.GetLastRect();

            tRect = new(tRect.x + 3, tRect.y + 3, tRect.width - 6, tRect.height - 6);
            GUI.DrawTexture(tRect, colorTexture);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Light Type", GUILayout.Width(headerWidth));
            int newFlag = GUILayout.SelectionGrid(typeFlag,
                                                  typeOptions,
                                                  2,
                                                  UIResources.GetStyle("radio_text_button"));


            if (newFlag != typeFlag)
            {
                typeFlag = newFlag;
                if (typeFlag == 1)
                {
                    model.SetLightType(light, LightType.Point);
                }
                if (typeFlag == 0)
                {
                    model.SetLightType(light, LightType.Spot);
                }
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Intensity", GUILayout.Width(headerWidth));
            sliderVal = GUILayout.HorizontalSlider(intensityValue, 0f, 10f);
            if (sliderVal != intensityValue)
            {
                intensityValue  = sliderVal;
                intensityString = sliderVal.ToString();
                model.SetLightIntensity(light, intensityValue);
            }

            textVal = GUILayout.TextArea(intensityString, GUILayout.Width(90f));
            if (textVal != intensityString)
            {
                float outVal;
                if (Single.TryParse(textVal, out outVal))
                {
                    intensityValue = outVal;
                    model.SetLightIntensity(light, intensityValue);
                }

                intensityString = textVal;
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Range", GUILayout.Width(headerWidth));
            sliderVal = GUILayout.HorizontalSlider(rangeValue, 0f, 100f);
            if (sliderVal != rangeValue)
            {
                rangeValue  = sliderVal;
                rangeString = sliderVal.ToString();
                model.SetLightRange(light, rangeValue);
            }

            textVal = GUILayout.TextArea(rangeString, GUILayout.Width(90f));
            if (textVal != rangeString)
            {
                float outVal;
                if (Single.TryParse(textVal, out outVal))
                {
                    rangeValue = outVal;
                    model.SetLightRange(light, rangeValue);
                }

                rangeString = textVal;
            }

            GUILayout.EndHorizontal();
            if (typeFlag == 0)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Spot Angle", GUILayout.Width(headerWidth));
                sliderVal = GUILayout.HorizontalSlider(angleValue, 0f, 100f);
                if (sliderVal != angleValue)
                {
                    angleValue  = sliderVal;
                    angleString = sliderVal.ToString();
                    model.SetLightAngle(light, angleValue);
                }

                textVal = GUILayout.TextArea(angleString, GUILayout.Width(90f));
                if (textVal != angleString)
                {
                    float outVal;
                    if (Single.TryParse(textVal, out outVal))
                    {
                        angleValue = outVal;
                        model.SetLightAngle(light, angleValue);
                    }

                    angleString = textVal;
                }

                GUILayout.EndHorizontal();
            }
        }