コード例 #1
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();
            }
        }