Skip to content

Commit 57c77bf

Browse files
authored
Merge pull request #95 from OpenCommissioning/development
Development
2 parents 369d215 + 49895f4 commit 57c77bf

4 files changed

Lines changed: 61 additions & 12 deletions

File tree

Editor/Scripts/Inspector/Cylinder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public override VisualElement CreateInspectorGUI()
3737
groupEvents.Add(new PropertyField{bindingPath = "OnActiveChanged"});
3838
groupEvents.Add(new PropertyField{bindingPath = "OnLimitMinEvent"});
3939
groupEvents.Add(new PropertyField{bindingPath = "OnLimitMaxEvent"});
40+
groupEvents.Add(new PropertyField{bindingPath = "OnValueChanged"});
41+
groupEvents.Add(new PropertyField{bindingPath = "OnProgressChanged"});
4042

4143
container.Add(groupControl);
4244
container.Add(groupStatus);

Runtime/Scripts/Components/Cylinder.cs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

Runtime/Scripts/Components/Drive.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,23 @@ public abstract class Drive : Actor, IDevice, IMetadataAsset, ICustomInspector,
2828
[HideInInspector]
2929
[SerializeField]
3030
protected DriveStateObserver _stateObserver = new ();
31+
32+
protected void OnEnable()
33+
{
34+
_stateObserver.IsActive.Subscribe(OnActiveChanged.Invoke);
35+
}
36+
37+
protected void OnDisable()
38+
{
39+
_stateObserver.IsActive.Unsubscribe(OnActiveChanged.Invoke);
40+
}
3141

32-
private void Start()
42+
protected void Start()
3343
{
3444
_link.Initialize(this);
35-
_stateObserver.IsActive.OnValueChanged += value => OnActiveChanged?.Invoke(value);
3645
}
3746

38-
private void FixedUpdate()
47+
protected void FixedUpdate()
3948
{
4049
if (!_override && _link.Connected) GetLinkData();
4150
Operation(Time.fixedDeltaTime);

Samples/Demo/0.1 Devices.unity

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,12 @@ MonoBehaviour:
790790
OnLimitMaxEvent:
791791
m_PersistentCalls:
792792
m_Calls: []
793+
OnValueChanged:
794+
m_PersistentCalls:
795+
m_Calls: []
796+
OnProgressChanged:
797+
m_PersistentCalls:
798+
m_Calls: []
793799
_link:
794800
Control: 0
795801
Status: 0
@@ -3942,6 +3948,12 @@ MonoBehaviour:
39423948
OnLimitMaxEvent:
39433949
m_PersistentCalls:
39443950
m_Calls: []
3951+
OnValueChanged:
3952+
m_PersistentCalls:
3953+
m_Calls: []
3954+
OnProgressChanged:
3955+
m_PersistentCalls:
3956+
m_Calls: []
39453957
_link:
39463958
Control: 0
39473959
Status: 0
@@ -4928,6 +4940,7 @@ MonoBehaviour:
49284940
m_EditorClassIdentifier:
49294941
_productDataDirectories:
49304942
- Name: RFID
4943+
Path:
49314944
--- !u!1 &1571801102
49324945
GameObject:
49334946
m_ObjectHideFlags: 0
@@ -5386,6 +5399,12 @@ MonoBehaviour:
53865399
OnLimitMaxEvent:
53875400
m_PersistentCalls:
53885401
m_Calls: []
5402+
OnValueChanged:
5403+
m_PersistentCalls:
5404+
m_Calls: []
5405+
OnProgressChanged:
5406+
m_PersistentCalls:
5407+
m_Calls: []
53895408
_link:
53905409
Control: 0
53915410
Status: 0

0 commit comments

Comments
 (0)