コード例 #1
0
        public static void DrawRandomizableFloatInput(float x, ref float y, RandomizableFieldValue <float> fv)
        {
            if (fv.GetRandomizableValue())
            {
                DrawLabel(x, y, 150, fv.Label);
            }
            else
            {
                fv.Buffer = DrawLabeledInput(x, y, fv.Label, fv.Buffer, out float nextX);
                if (float.TryParse(fv.Buffer, out float f))
                {
                    fv.OnChange(f);
                }
                if (fv.Default != 0 && Widgets.ButtonText(new Rect(nextX, y, 100, 28), "CM.Default".Translate()))
                {
                    fv.OnChange(fv.Default);
                    fv.UpdateBuffer();
                }
            }
            y += 30;
            Widgets.Label(new Rect(x, y, 100, 28), "Randomize".Translate());
            var r = fv.GetRandomizableValue();

            Widgets.Checkbox(new Vector2(x + 110, y - 2), ref r);
            fv.OnRandomizableChange(r);
            y += 30;
        }
コード例 #2
0
        public static void DrawInputRandomizableWithSlider(float x, ref float y, RandomizableFieldValue <float> fv)
        {
            DrawRandomizableFloatInput(x, ref y, fv);
            y += 10;

            if (!float.TryParse(fv.Buffer, out float orig))
            {
                orig = 0;
            }

            if (!fv.GetRandomizableValue())
            {
                var result = Widgets.HorizontalSlider(new Rect(x, y, 300, 20), orig, fv.Min, fv.Max, false, null, fv.Min.ToString("0.0"), fv.Max.ToString("0.0"));
                if (orig != result && Math.Abs(orig - result) > 0.001)
                {
                    fv.OnChange(result);
                    fv.UpdateBuffer();
                }
                y += 40;
            }
        }