File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ public class SerialOutputTarget : IOutputTarget
1212 private JSONStorableStringChooser ComPortChooser ;
1313 private UIHorizontalGroup ButtonGroup ;
1414
15+ private JSONStorableAction StartSerialAction ;
16+ private JSONStorableAction StopSerialAction ;
17+
1518 private SerialPort _serial ;
1619
1720 public void CreateUI ( IUIBuilder builder )
@@ -26,12 +29,18 @@ public void CreateUI(IUIBuilder builder)
2629 var stopSerialButton = ButtonGroup . items [ 1 ] . GetComponent < UIDynamicButton > ( ) ;
2730 stopSerialButton . label = "Stop Serial" ;
2831 stopSerialButton . button . onClick . AddListener ( StopSerial ) ;
32+
33+ StartSerialAction = UIManager . CreateAction ( "Start Serial" , StartSerial ) ;
34+ StopSerialAction = UIManager . CreateAction ( "Stop Serial" , StopSerial ) ;
2935 }
3036
3137 public void DestroyUI ( IUIBuilder builder )
3238 {
3339 builder . Destroy ( ComPortChooser ) ;
3440 builder . Destroy ( ButtonGroup ) ;
41+
42+ UIManager . RemoveAction ( StartSerialAction ) ;
43+ UIManager . RemoveAction ( StopSerialAction ) ;
3544 }
3645
3746 public void RestoreConfig ( JSONNode config )
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ public class UdpOutputTarget : IOutputTarget
1717 private JSONStorableString PortText ;
1818 private UIHorizontalGroup ButtonGroup ;
1919
20+ private JSONStorableAction StartUdpAction ;
21+ private JSONStorableAction StopUdpAction ;
22+
2023 private UdpClient _client ;
2124
2225 public void CreateUI ( IUIBuilder builder )
@@ -34,13 +37,19 @@ public void CreateUI(IUIBuilder builder)
3437 var stopSerialButton = ButtonGroup . items [ 1 ] . GetComponent < UIDynamicButton > ( ) ;
3538 stopSerialButton . label = "Stop Udp" ;
3639 stopSerialButton . button . onClick . AddListener ( StopUdp ) ;
40+
41+ StartUdpAction = UIManager . CreateAction ( "Start Udp" , StartUdp ) ;
42+ StopUdpAction = UIManager . CreateAction ( "Stop Udp" , StopUdp ) ;
3743 }
3844
3945 public void DestroyUI ( IUIBuilder builder )
4046 {
4147 builder . Destroy ( AddressInput ) ;
4248 builder . Destroy ( PortInput ) ;
4349 builder . Destroy ( ButtonGroup ) ;
50+
51+ UIManager . RemoveAction ( StartUdpAction ) ;
52+ UIManager . RemoveAction ( StopUdpAction ) ;
4453 }
4554
4655 public void RestoreConfig ( JSONNode config )
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ public abstract class AbstractRefreshableMotionSource : IMotionSource
1010 private UIDynamicButton RefreshButton ;
1111 private UIDynamic Spacer ;
1212
13+ private JSONStorableAction RefreshAction ;
14+
1315 public abstract Vector3 ReferencePosition { get ; }
1416 public abstract Vector3 ReferenceUp { get ; }
1517 public abstract Vector3 ReferenceRight { get ; }
@@ -28,20 +30,29 @@ public abstract class AbstractRefreshableMotionSource : IMotionSource
2830
2931 public virtual void CreateUI ( IUIBuilder builder )
3032 {
31- RefreshButton = builder . CreateButton ( "Refresh" , ( ) => {
33+ RefreshButton = builder . CreateButton ( "Refresh" , ( ) =>
34+ {
3235 ComponentCache . Clear ( ) ;
3336 RefreshButtonCallback ( ) ;
3437 } ) ;
3538 RefreshButton . buttonColor = new Color ( 0 , 0.75f , 1f ) * 0.8f ;
3639 RefreshButton . textColor = Color . white ;
3740
3841 Spacer = builder . CreateSpacer ( 200 ) ;
42+
43+ RefreshAction = UIManager . CreateAction ( "Refresh Motion Source" , ( ) =>
44+ {
45+ ComponentCache . Clear ( ) ;
46+ RefreshButtonCallback ( ) ;
47+ } ) ;
3948 }
4049
4150 public virtual void DestroyUI ( IUIBuilder builder )
4251 {
4352 builder . Destroy ( RefreshButton ) ;
4453 builder . Destroy ( Spacer ) ;
54+
55+ UIManager . RemoveAction ( RefreshAction ) ;
4556 }
4657
4758 protected abstract void RefreshButtonCallback ( ) ;
Original file line number Diff line number Diff line change 1- using System . Collections . Generic ;
1+ using System ;
2+ using System . Collections . Generic ;
23using UnityEngine ;
34
45namespace ToySerialController . UI
@@ -30,6 +31,15 @@ public static void Initialize(MVRScript plugin)
3031 Instance = new UIManager ( plugin ) ;
3132 }
3233
34+ public static JSONStorableAction CreateAction ( string name , Action callback )
35+ {
36+ var action = new JSONStorableAction ( name , new JSONStorableAction . ActionCallback ( callback ) ) ;
37+ Instance . plugin . RegisterAction ( action ) ;
38+ return action ;
39+ }
40+
41+ public static void RemoveAction ( JSONStorableAction action ) => Instance . plugin . DeregisterAction ( action ) ;
42+
3343 public static void RemoveSpacer ( UIDynamic o ) => Instance . plugin . RemoveSpacer ( o ) ;
3444 public static void RemoveButton ( UIDynamicButton o ) => Instance . plugin . RemoveButton ( o ) ;
3545
You can’t perform that action at this time.
0 commit comments