@@ -51,6 +51,8 @@ public class Cylinder : Actor, IDevice, ICustomInspector, IInteractable
5151 public UnityEvent < bool > OnActiveChanged ;
5252 public UnityEvent < bool > OnLimitMinEvent ;
5353 public UnityEvent < bool > OnLimitMaxEvent ;
54+ public UnityEvent < float > OnValueChanged ;
55+ public UnityEvent < float > OnProgressChanged ;
5456
5557 public bool JogMinus
5658 {
@@ -67,23 +69,40 @@ public bool JogPlus
6769 [ SerializeField ]
6870 protected Link _link = new ( ) { Type = "FB_Cylinder" } ;
6971
70- private void Start ( )
72+ protected void Start ( )
7173 {
7274 _link . Initialize ( this ) ;
73- _progress . OnValueChanged += OnProgressChanged ;
74- _isActive . OnValueChanged += value => OnActiveChanged ? . Invoke ( value ) ;
75- _onLimitMin . OnValueChanged += value => OnLimitMinEvent ? . Invoke ( value ) ;
76- _onLimitMax . OnValueChanged += value => OnLimitMaxEvent ? . Invoke ( value ) ;
77- OnProgressChanged ( _progress . Value ) ;
75+
76+ RefreshState ( _progress . Value ) ;
7877 }
7978
80- private void OnValidate ( )
79+ protected void OnEnable ( )
80+ {
81+ _progress . OnValueChanged += RefreshState ;
82+ _isActive . Subscribe ( OnActiveChanged . Invoke ) ;
83+ _onLimitMin . Subscribe ( OnLimitMinEvent . Invoke ) ;
84+ _onLimitMax . Subscribe ( OnLimitMaxEvent . Invoke ) ;
85+ _value . Subscribe ( OnValueChanged . Invoke ) ;
86+ _progress . Subscribe ( OnProgressChanged . Invoke ) ;
87+ }
88+
89+ protected void OnDisable ( )
90+ {
91+ _progress . OnValueChanged -= RefreshState ;
92+ _isActive . Unsubscribe ( OnActiveChanged . Invoke ) ;
93+ _onLimitMin . Unsubscribe ( OnLimitMinEvent . Invoke ) ;
94+ _onLimitMax . Unsubscribe ( OnLimitMaxEvent . Invoke ) ;
95+ _value . Unsubscribe ( OnValueChanged . Invoke ) ;
96+ _progress . Unsubscribe ( OnProgressChanged . Invoke ) ;
97+ }
98+
99+ protected void OnValidate ( )
81100 {
82101 _minus . OnValidate ( ) ;
83102 _plus . OnValidate ( ) ;
84103 }
85104
86- private void FixedUpdate ( )
105+ protected void FixedUpdate ( )
87106 {
88107 GetLinkData ( ) ;
89108 Operation ( Time . fixedDeltaTime ) ;
@@ -136,7 +155,7 @@ private void IntegrateProgress(float deltaTime, float duration)
136155 _progress . Value = Mathf . Clamp01 ( progress ) ;
137156 }
138157
139- private void OnProgressChanged ( float value )
158+ private void RefreshState ( float value )
140159 {
141160 _target . Value = Mathf . Lerp ( _limits . Value . x , _limits . Value . y , _profile . Evaluate ( _progress ) ) ;
142161 _isActive . Value = Math . FastApproximately ( _target , _value , 1e-3f ) ;
0 commit comments