Skip to content

Commit 9e233df

Browse files
authored
Merge pull request #110 from OpenCommissioning/development
Development
2 parents 0f524dd + c8f2cc5 commit 9e233df

36 files changed

Lines changed: 252 additions & 95 deletions

Runtime/Scripts/Common/MonoBehaviourSingleton.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class MonoBehaviourSingleton<T> : MonoBehaviour where T : Component
77
public Component Component => this;
88
public static T Instance { get; private set; }
99

10-
public virtual void Awake ()
10+
protected virtual void Awake ()
1111
{
1212
if (Instance == null)
1313
{

Runtime/Scripts/Components/Axis.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
using System;
22
using UnityEngine;
3+
using UnityEngine.Serialization;
34

45
namespace OC.Components
56
{
67
[AddComponentMenu("Open Commissioning/Actor/Axis")]
78
[SelectionBase]
89
[DisallowMultipleComponent]
910
[DefaultExecutionOrder(1000)]
10-
public class Axis : Actor, IInteractable, ICustomInspector
11+
public class Axis : Actor, IInteractable
1112
{
13+
public Type ReferenceType => typeof(Axis);
14+
1215
public Actor Actor
1316
{
1417
set => _actor = value;
@@ -58,6 +61,7 @@ public AxisDirection Direction
5861
protected float _offset;
5962
[SerializeField]
6063
protected AxisDirection _direction = AxisDirection.X;
64+
[FormerlySerializedAs("_axisType")]
6165
[SerializeField]
6266
protected AxisType _type = AxisType.Translation;
6367
[SerializeField]

Runtime/Scripts/Components/Cylinder.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

Runtime/Scripts/Components/DataReader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace OC.Components
1313
[RequireComponent(typeof(BoxCollider))]
1414
public class DataReader : Detector, IMeasurement<float>, IInteractable
1515
{
16+
public Type ReferenceType => typeof(DataReader);
1617
public IProperty<string> TargetData => _targetData;
1718
public IPropertyReadOnly<string> RawData => _rawData;
1819
public IPropertyReadOnly<float> Value => _value;

Runtime/Scripts/Components/Drive.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections;
23
using System.Globalization;
34
using OC.Communication;
@@ -10,8 +11,9 @@ namespace OC.Components
1011
[AddComponentMenu("Open Commissioning/Actor/Drive")]
1112
[SelectionBase]
1213
[DisallowMultipleComponent]
13-
public abstract class Drive : Actor, IDevice, IMetadataAsset, ICustomInspector, IInteractable
14+
public abstract class Drive : Actor, IDevice, IMetadataAsset, IInteractable
1415
{
16+
public abstract Type ReferenceType { get; }
1517
public Link Link => _link;
1618
public IProperty<bool> Override => _override;
1719
public int MetadataAssetLength => 1;

Runtime/Scripts/Components/DrivePosition.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using OC.Communication;
23
using UnityEngine;
34

@@ -9,6 +10,7 @@ namespace OC.Components
910
[DefaultExecutionOrder(100)]
1011
public class DrivePosition : Drive
1112
{
13+
public override Type ReferenceType => typeof(DrivePosition);
1214
public IProperty<float> Speed => _speed;
1315

1416
[SerializeField]

Runtime/Scripts/Components/DriveSimple.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using UnityEngine;
23
using OC.Communication;
34

@@ -8,6 +9,8 @@ namespace OC.Components
89
[DisallowMultipleComponent]
910
public class DriveSimple : DriveSpeed
1011
{
12+
public override Type ReferenceType => typeof(DriveSimple);
13+
1114
public IProperty<float> Speed => _speed;
1215
public IProperty<bool> Forward => _forward;
1316
public IProperty<bool> Backward => _backward;

Runtime/Scripts/Components/DriveSpeed.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using UnityEngine;
23
using OC.Communication;
34

@@ -8,6 +9,8 @@ namespace OC.Components
89
[DisallowMultipleComponent]
910
public class DriveSpeed : Drive
1011
{
12+
public override Type ReferenceType => typeof(DriveSpeed);
13+
1114
public IProperty<float> Acceleration => _acceleration;
1215

1316
[SerializeField]

Runtime/Scripts/Components/ICustomInspector.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

Runtime/Scripts/Components/ICustomInspector.cs.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)