@@ -8,8 +8,9 @@ namespace OC.Components
88 [ AddComponentMenu ( "Open Commissioning/Actor/Cylinder" ) ]
99 [ SelectionBase ]
1010 [ DisallowMultipleComponent ]
11- public class Cylinder : Actor , IDevice , ICustomInspector , IInteractable
11+ public class Cylinder : Actor , IDevice , IInteractable
1212 {
13+ public Type ReferenceType => typeof ( Cylinder ) ;
1314 public Link Link => _link ;
1415 public IProperty < bool > Override => _override ;
1516 public IProperty < bool > Minus => _minus ;
@@ -72,13 +73,10 @@ public bool JogPlus
7273 protected void Start ( )
7374 {
7475 _link . Initialize ( this ) ;
75-
76- RefreshState ( _progress . Value ) ;
7776 }
7877
7978 protected void OnEnable ( )
8079 {
81- _progress . OnValueChanged += RefreshState ;
8280 _isActive . Subscribe ( OnActiveChanged . Invoke ) ;
8381 _onLimitMin . Subscribe ( OnLimitMinEvent . Invoke ) ;
8482 _onLimitMax . Subscribe ( OnLimitMaxEvent . Invoke ) ;
@@ -88,7 +86,6 @@ protected void OnEnable()
8886
8987 protected void OnDisable ( )
9088 {
91- _progress . OnValueChanged -= RefreshState ;
9289 _isActive . Unsubscribe ( OnActiveChanged . Invoke ) ;
9390 _onLimitMin . Unsubscribe ( OnLimitMinEvent . Invoke ) ;
9491 _onLimitMax . Unsubscribe ( OnLimitMaxEvent . Invoke ) ;
@@ -118,26 +115,28 @@ private void GetLinkData()
118115
119116 private void SetLinkData ( )
120117 {
121- _link . Status . SetBit ( 0 , _onLimitMin ) ;
122- _link . Status . SetBit ( 1 , _onLimitMax ) ;
118+ _link . Status . SetBit ( 0 , _onLimitMin . Value ) ;
119+ _link . Status . SetBit ( 1 , _onLimitMax . Value ) ;
123120 }
124121
125122 private void Operation ( float deltaTime )
126123 {
127124 switch ( _type . Value )
128125 {
129126 case CylinderType . DoubleActing :
130- if ( _minus . Value ^ _plus . Value ) IntegrateProgress ( deltaTime , _plus . Value ? _timeToMax : - _timeToMin ) ;
127+ if ( _minus . Value ^ _plus . Value ) IntegrateProgress ( deltaTime , _plus . Value ? _timeToMax . Value : - _timeToMin . Value ) ;
131128 break ;
132129 case CylinderType . SingleActingNegative :
133- IntegrateProgress ( deltaTime , _plus . Value ? _timeToMax : - _timeToMin ) ;
130+ IntegrateProgress ( deltaTime , _plus . Value ? _timeToMax . Value : - _timeToMin . Value ) ;
134131 break ;
135132 case CylinderType . SingleActingPositive :
136- IntegrateProgress ( deltaTime , _minus . Value ? - _timeToMin : _timeToMax ) ;
133+ IntegrateProgress ( deltaTime , _minus . Value ? - _timeToMin . Value : _timeToMax . Value ) ;
137134 break ;
138135 default :
139136 throw new ArgumentOutOfRangeException ( ) ;
140137 }
138+
139+ UpdateState ( ) ;
141140 }
142141
143142 public enum CylinderType
@@ -148,21 +147,20 @@ public enum CylinderType
148147 }
149148
150149 public void SetProgress ( float value ) => _progress . Value = Mathf . Clamp01 ( value ) ;
151-
150+
152151 private void IntegrateProgress ( float deltaTime , float duration )
153152 {
154153 var progress = _progress . Value + deltaTime / duration ;
155154 _progress . Value = Mathf . Clamp01 ( progress ) ;
156155 }
157-
158- private void RefreshState ( float value )
156+
157+ private void UpdateState ( )
159158 {
160- _target . Value = Mathf . Lerp ( _limits . Value . x , _limits . Value . y , _profile . Evaluate ( _progress ) ) ;
161- _isActive . Value = Math . FastApproximately ( _target , _value , 1e-3f ) ;
159+ _target . Value = Mathf . Lerp ( _limits . Value . x , _limits . Value . y , _profile . Evaluate ( _progress . Value ) ) ;
160+ _isActive . Value = ! Math . FastApproximately ( _target . Value , _value . Value , 1e-1f ) ;
162161 _value . Value = _target . Value ;
163- _onLimitMin . Value = Math . FastApproximately ( _value , _limits . Value . x , 1e-3f ) ;
164- _onLimitMax . Value = Math . FastApproximately ( _value , _limits . Value . y , 1e-3f ) ;
165- SetLinkData ( ) ;
162+ _onLimitMin . Value = Math . FastApproximately ( _value . Value , _limits . Value . x , 1e-3f ) ;
163+ _onLimitMax . Value = Math . FastApproximately ( _value . Value , _limits . Value . y , 1e-3f ) ;
166164 }
167165 }
168166}
0 commit comments