using System; using System.Collections.Generic; using uiwidgets; using Unity.UIWidgets.cupertino; using Unity.UIWidgets.material; using Unity.UIWidgets.painting; using Unity.UIWidgets.ui; using Unity.UIWidgets.widgets; using UnityEngine; using Color = Unity.UIWidgets.ui.Color; namespace UIWidgetsSample.RaycastableScene { public class SceneBoard : StatefulWidget { public override State createState() { return new SceneBoardState(); } } public class SceneBoardState : State { public override Widget build(BuildContext context) { return new Container( height: 50, color: Colors.orange, child: new Row( children: new List() { new ActionBox( name: "Light", onChange: value => { Debug.Log($"input ${value}"); LightController.SwitchLight(value); }), new LightSlider() // new ColorPicker(300) } ) ); } } public class ActionBox : StatefulWidget { public string name; public Action onChange; public ActionBox(string name, Action onChange) { this.name = name; this.onChange = onChange; } public override State createState() { return new ActionBoxState(); } } public class ActionBoxState : State { private bool value = true; public override Widget build(BuildContext context) { return new Row( children: new List() { new CupertinoSwitch( value: value, onChanged: valueIn => { setState(() => { value = valueIn; widget.onChange?.Invoke(value); }); } ), new Text(widget.name) } ); } } class LightSlider : StatefulWidget { public override State createState() { return new LightSliderState(); } } internal class LightSliderState : State { private float _currentSliderValue = 0; public override Widget build(BuildContext context) { return new Slider( value: _currentSliderValue, min: 0, max: 1, onChanged: (value) => { setState(() => { _currentSliderValue = value; LightController.ChangeLightColor(value); }); } ); } } class ColorPicker : StatefulWidget { public readonly float width; public ColorPicker(float width) { this.width = width; } public override State createState() => new _ColorPickerState(); } class _ColorPickerState : State { readonly List _colors = new List(){ Color.fromARGB(255, 255, 0, 0), Color.fromARGB(255, 255, 128, 0), Color.fromARGB(255, 255, 255, 0), Color.fromARGB(255, 128, 255, 0), Color.fromARGB(255, 0, 255, 0), Color.fromARGB(255, 0, 255, 128), Color.fromARGB(255, 0, 255, 255), Color.fromARGB(255, 0, 128, 255), Color.fromARGB(255, 0, 0, 255), Color.fromARGB(255, 127, 0, 255), Color.fromARGB(255, 255, 0, 255), Color.fromARGB(255, 255, 0, 127), Color.fromARGB(255, 128, 128, 128), }; public override Widget build(BuildContext context) { return new Column( children: new List{ new Center( child: new Container( width: widget.width, height: 15, decoration: new BoxDecoration( border: Border.all(width: 2, color: Colors.grey[800]), borderRadius: BorderRadius.circular(15), gradient: new LinearGradient(colors: _colors) ) ) ) } ); } } }