From a250b4cb575e646308d76b15a1c3348198e648df Mon Sep 17 00:00:00 2001 From: Viktor Gaponenko Date: Fri, 27 Jun 2025 15:36:21 +0200 Subject: [PATCH] fix(Link): link type initialization --- Runtime/Scripts/Communication/Link/Link.cs | 12 ++++- .../Communication/Link/LinkDataByte.cs | 2 + .../Communication/Link/LinkDataDWord.cs | 2 + .../Communication/Link/LinkDataFloat.cs | 2 + .../Communication/Link/LinkDataLWord.cs | 2 + .../Communication/Link/LinkDataRobot.cs | 2 + .../Communication/Link/LinkDataWord.cs | 2 + Runtime/Scripts/Components/Cylinder.cs | 50 ++++--------------- Runtime/Scripts/Components/Device.cs | 32 ------------ Runtime/Scripts/Components/DeviceDWord.cs | 33 ------------ .../Scripts/Components/DeviceDWord.cs.meta | 11 ---- Runtime/Scripts/Components/DeviceWord.cs | 33 ------------ Runtime/Scripts/Components/DeviceWord.cs.meta | 11 ---- Runtime/Scripts/Components/Drive.cs | 12 +---- Runtime/Scripts/Components/LinkByte.cs | 10 +--- Runtime/Scripts/Components/Robot6R.cs | 10 +--- Runtime/Scripts/Components/SampleDevice.cs | 17 +++++++ .../{Device.cs.meta => SampleDevice.cs.meta} | 0 Runtime/Scripts/Components/SensorAnalog.cs | 10 +--- Runtime/Scripts/Components/TagReader.cs | 16 ++---- Runtime/Scripts/Components/Transport.cs | 1 - Runtime/Scripts/Components/TransportCurved.cs | 1 - Runtime/Scripts/Interactions/Button.cs | 19 +++---- Runtime/Scripts/Interactions/Lamp.cs | 19 +++---- Runtime/Scripts/Interactions/Lock.cs | 12 +---- Runtime/Scripts/Interactions/PanelSampler.cs | 14 ++---- Runtime/Scripts/Interactions/Switch.cs | 23 +++++---- .../Interactions/VisualElements/Factory.cs | 6 +-- Samples/Demo/0.1 Devices.unity | 48 +++++++++++++++--- Samples/Demo/Prefabs/Button.prefab | 22 ++++---- Tests/Runtime/Components/TestCylinder.cs | 2 - 31 files changed, 145 insertions(+), 291 deletions(-) delete mode 100644 Runtime/Scripts/Components/Device.cs delete mode 100644 Runtime/Scripts/Components/DeviceDWord.cs delete mode 100644 Runtime/Scripts/Components/DeviceDWord.cs.meta delete mode 100644 Runtime/Scripts/Components/DeviceWord.cs delete mode 100644 Runtime/Scripts/Components/DeviceWord.cs.meta create mode 100644 Runtime/Scripts/Components/SampleDevice.cs rename Runtime/Scripts/Components/{Device.cs.meta => SampleDevice.cs.meta} (100%) diff --git a/Runtime/Scripts/Communication/Link/Link.cs b/Runtime/Scripts/Communication/Link/Link.cs index 684d866..0c300c2 100644 --- a/Runtime/Scripts/Communication/Link/Link.cs +++ b/Runtime/Scripts/Communication/Link/Link.cs @@ -65,7 +65,7 @@ public string Type [SerializeField] private string _clientPath; [SerializeField] - private string _type; + private string _type = "FB_Device"; [SerializeField] private Hierarchy _parent; [SerializeField] @@ -79,6 +79,16 @@ public string Type protected List _variables = new(); + public Link() + { + + } + + public Link(string type) + { + _type = type; + } + public void Initialize(Component component) { _component = component; diff --git a/Runtime/Scripts/Communication/Link/LinkDataByte.cs b/Runtime/Scripts/Communication/Link/LinkDataByte.cs index 7a46b17..f9fb671 100644 --- a/Runtime/Scripts/Communication/Link/LinkDataByte.cs +++ b/Runtime/Scripts/Communication/Link/LinkDataByte.cs @@ -9,6 +9,8 @@ public class LinkDataByte : Link public byte ControlData; public byte StatusData; + public LinkDataByte(string type) : base(type){} + protected override List GetClientVariableDescriptions() { var descriptions = new List diff --git a/Runtime/Scripts/Communication/Link/LinkDataDWord.cs b/Runtime/Scripts/Communication/Link/LinkDataDWord.cs index 007a504..e6fdbf7 100644 --- a/Runtime/Scripts/Communication/Link/LinkDataDWord.cs +++ b/Runtime/Scripts/Communication/Link/LinkDataDWord.cs @@ -9,6 +9,8 @@ public class LinkDataDWord : Link public uint ControlData; public uint StatusData; + public LinkDataDWord(string type) : base(type){} + protected override List GetClientVariableDescriptions() { var descriptions = new List diff --git a/Runtime/Scripts/Communication/Link/LinkDataFloat.cs b/Runtime/Scripts/Communication/Link/LinkDataFloat.cs index af48224..8972eca 100644 --- a/Runtime/Scripts/Communication/Link/LinkDataFloat.cs +++ b/Runtime/Scripts/Communication/Link/LinkDataFloat.cs @@ -9,6 +9,8 @@ public class LinkDataFloat : Link public float ControlData; public float StatusData; + public LinkDataFloat(string type) : base(type){} + protected override List GetClientVariableDescriptions() { var descriptions = new List diff --git a/Runtime/Scripts/Communication/Link/LinkDataLWord.cs b/Runtime/Scripts/Communication/Link/LinkDataLWord.cs index eab0839..7cf3db3 100644 --- a/Runtime/Scripts/Communication/Link/LinkDataLWord.cs +++ b/Runtime/Scripts/Communication/Link/LinkDataLWord.cs @@ -9,6 +9,8 @@ public class LinkDataLWord : Link public long ControlData; public long StatusData; + public LinkDataLWord(string type) : base(type){} + protected override List GetClientVariableDescriptions() { var descriptions = new List diff --git a/Runtime/Scripts/Communication/Link/LinkDataRobot.cs b/Runtime/Scripts/Communication/Link/LinkDataRobot.cs index f27a8df..b5e8ee6 100644 --- a/Runtime/Scripts/Communication/Link/LinkDataRobot.cs +++ b/Runtime/Scripts/Communication/Link/LinkDataRobot.cs @@ -9,6 +9,8 @@ public class LinkDataRobot : Link public float[] JointTarget = new float[12]; public float[] JointStatus = new float[12]; + public LinkDataRobot(string type) : base(type){} + protected override List GetClientVariableDescriptions() { var descriptions = new List diff --git a/Runtime/Scripts/Communication/Link/LinkDataWord.cs b/Runtime/Scripts/Communication/Link/LinkDataWord.cs index 8879685..4d0b6e6 100644 --- a/Runtime/Scripts/Communication/Link/LinkDataWord.cs +++ b/Runtime/Scripts/Communication/Link/LinkDataWord.cs @@ -9,6 +9,8 @@ public class LinkDataWord : Link public short ControlData; public short StatusData; + public LinkDataWord(string type) : base(type){} + protected override List GetClientVariableDescriptions() { var descriptions = new List diff --git a/Runtime/Scripts/Components/Cylinder.cs b/Runtime/Scripts/Components/Cylinder.cs index dd27577..fb06ede 100644 --- a/Runtime/Scripts/Components/Cylinder.cs +++ b/Runtime/Scripts/Components/Cylinder.cs @@ -12,10 +12,16 @@ public class Cylinder : Actor, IDevice, ICustomInspector, IInteractable { public Link Link => _link; public IProperty Override => _override; - - #region Control public IProperty Minus => _minus; public IProperty Plus => _plus; + public IPropertyReadOnly Progress => _progress; + public IPropertyReadOnly IsActive => _isActive; + public IPropertyReadOnly OnLimitMin => _onLimitMin; + public IPropertyReadOnly OnLimitMax => _onLimitMax; + public IProperty Limits => _limits; + public IProperty Type => _type; + public IProperty TimeToMin => _timeToMin; + public IProperty TimeToMax => _timeToMax; [SerializeField] protected Property _override = new (false); @@ -23,16 +29,6 @@ public class Cylinder : Actor, IDevice, ICustomInspector, IInteractable protected Property _minus = new (false); [SerializeField] protected Property _plus = new (false); - - #endregion - - #region Status - - public IPropertyReadOnly Progress => _progress; - public IPropertyReadOnly IsActive => _isActive; - public IPropertyReadOnly OnLimitMin => _onLimitMin; - public IPropertyReadOnly OnLimitMax => _onLimitMax; - [SerializeField] protected Property _progress = new (0); [SerializeField] @@ -41,16 +37,6 @@ public class Cylinder : Actor, IDevice, ICustomInspector, IInteractable protected Property _onLimitMin = new (false); [SerializeField] protected Property _onLimitMax = new (false); - - #endregion - - #region Settings - - public IProperty Limits => _limits; - public IProperty Type => _type; - public IProperty TimeToMin => _timeToMin; - public IProperty TimeToMax => _timeToMax; - [SerializeField] protected Property _limits = new (new Vector2(0, 100)); [SerializeField] @@ -61,17 +47,11 @@ public class Cylinder : Actor, IDevice, ICustomInspector, IInteractable protected Property _timeToMax = new (0.5f); [SerializeField] private AnimationCurve _profile = AnimationCurve.Linear(0, 0, 1, 1); - - #endregion - - #region Events - + public UnityEvent OnActiveChanged; public UnityEvent OnLimitMinEvent; public UnityEvent OnLimitMaxEvent; - - #endregion - + public bool JogMinus { set => _minus.Value = value; @@ -85,7 +65,7 @@ public bool JogPlus } [SerializeField] - protected Link _link; + protected Link _link = new() { Type = "FB_Cylinder" }; private void Start() { @@ -103,14 +83,6 @@ private void OnValidate() _plus.OnValidate(); } - public void Reset() - { - _link = new Link - { - Type = "FB_Cylinder" - }; - } - private void FixedUpdate() { GetLinkData(); diff --git a/Runtime/Scripts/Components/Device.cs b/Runtime/Scripts/Components/Device.cs deleted file mode 100644 index 48f947c..0000000 --- a/Runtime/Scripts/Components/Device.cs +++ /dev/null @@ -1,32 +0,0 @@ -using OC.Communication; -using UnityEngine; - -namespace OC.Components -{ - [SelectionBase] - [DisallowMultipleComponent] - public abstract class Device : MonoComponent, IDevice - { - public Link Link => _link; - public IProperty Override => _override; - public abstract int AllocatedBitLength { get; } - - [SerializeField] - protected Property _override = new (false); - [SerializeField] - protected Link _link; - - protected void Start() - { - _link.Initialize(this); - } - - public virtual void Reset() - { - _link = new Link - { - Type = "FB_Device" - }; - } - } -} diff --git a/Runtime/Scripts/Components/DeviceDWord.cs b/Runtime/Scripts/Components/DeviceDWord.cs deleted file mode 100644 index 8181e6a..0000000 --- a/Runtime/Scripts/Components/DeviceDWord.cs +++ /dev/null @@ -1,33 +0,0 @@ -using OC.Communication; -using UnityEngine; - -namespace OC.Components -{ - [SelectionBase] - [DisallowMultipleComponent] - [DefaultExecutionOrder(100)] - public abstract class DeviceDWord : MonoComponent, IDevice - { - public Link Link => _link; - public IProperty Override => _override; - public abstract int AllocatedBitLength { get; } - - [SerializeField] - protected Property _override = new (false); - [SerializeField] - protected LinkDataDWord _link; - - protected void Start() - { - _link.Initialize(this); - } - - public void Reset() - { - _link = new LinkDataDWord - { - Type = "FB_DeviceDWord" - }; - } - } -} diff --git a/Runtime/Scripts/Components/DeviceDWord.cs.meta b/Runtime/Scripts/Components/DeviceDWord.cs.meta deleted file mode 100644 index ae4b880..0000000 --- a/Runtime/Scripts/Components/DeviceDWord.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 3b2fea43df549fb428bd641127c9abff -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Scripts/Components/DeviceWord.cs b/Runtime/Scripts/Components/DeviceWord.cs deleted file mode 100644 index 48b1f81..0000000 --- a/Runtime/Scripts/Components/DeviceWord.cs +++ /dev/null @@ -1,33 +0,0 @@ -using OC.Communication; -using UnityEngine; - -namespace OC.Components -{ - [SelectionBase] - [DisallowMultipleComponent] - [DefaultExecutionOrder(100)] - public abstract class DeviceWord : MonoComponent, IDevice - { - public Link Link => _link; - public IProperty Override => _override; - public abstract int AllocatedBitLength { get; } - - [SerializeField] - protected Property _override = new (false); - [SerializeField] - protected LinkDataWord _link; - - protected void Start() - { - _link.Initialize(this); - } - - public void Reset() - { - _link = new LinkDataWord - { - Type = "FB_DeviceWord" - }; - } - } -} diff --git a/Runtime/Scripts/Components/DeviceWord.cs.meta b/Runtime/Scripts/Components/DeviceWord.cs.meta deleted file mode 100644 index aad1fa7..0000000 --- a/Runtime/Scripts/Components/DeviceWord.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ca0b5b884bcbe4d4080cf79f324ed1da -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Scripts/Components/Drive.cs b/Runtime/Scripts/Components/Drive.cs index 7d5339b..d9a96bf 100644 --- a/Runtime/Scripts/Components/Drive.cs +++ b/Runtime/Scripts/Components/Drive.cs @@ -10,7 +10,7 @@ namespace OC.Components [AddComponentMenu("Open Commissioning/Actor/Drive")] [SelectionBase] [DisallowMultipleComponent] - public abstract class Drive : Actor, IDeviceMetadata, ICustomInspector, IInteractable, IOverride + public abstract class Drive : Actor, IDevice, IMetadataAsset, ICustomInspector, IInteractable { public Link Link => _link; public IProperty Override => _override; @@ -24,7 +24,7 @@ public abstract class Drive : Actor, IDeviceMetadata, ICustomInspector, IInterac [SerializeField] protected Property _override = new (false); [SerializeField] - protected LinkDataFloat _link; + protected LinkDataFloat _link = new("FB_Drive"); [HideInInspector] [SerializeField] protected DriveStateObserver _stateObserver = new (); @@ -34,14 +34,6 @@ private void Start() _link.Initialize(this); _stateObserver.IsActive.OnValueChanged += value => OnActiveChanged?.Invoke(value); } - - public void Reset() - { - _link = new LinkDataFloat - { - Type = "FB_Drive" - }; - } private void FixedUpdate() { diff --git a/Runtime/Scripts/Components/LinkByte.cs b/Runtime/Scripts/Components/LinkByte.cs index ed85dbc..eab253c 100644 --- a/Runtime/Scripts/Components/LinkByte.cs +++ b/Runtime/Scripts/Components/LinkByte.cs @@ -32,21 +32,13 @@ public class LinkByte : MonoComponent, IDevice public UnityEvent OnBit7Changed; [SerializeField] - private LinkDataByte _link; + private LinkDataByte _link = new("FB_DeviceByte"); private void Start() { Link.Initialize(this); } - public void Reset() - { - _link = new LinkDataByte - { - Type = "FB_DeviceByte" - }; - } - private void Update() { if (!_link.Connected) return; diff --git a/Runtime/Scripts/Components/Robot6R.cs b/Runtime/Scripts/Components/Robot6R.cs index 32127a5..7f94b60 100644 --- a/Runtime/Scripts/Components/Robot6R.cs +++ b/Runtime/Scripts/Components/Robot6R.cs @@ -30,7 +30,7 @@ public class Robot6R : MonoComponent, IDevice [SerializeField] protected Property _override = new (false); [SerializeField] - private LinkDataRobot _link; + private LinkDataRobot _link = new("FB_Robot"); private readonly float[] _value = new float[12]; @@ -38,14 +38,6 @@ private void Start() { _link.Initialize(this); } - - private void Reset() - { - _link = new LinkDataRobot - { - Type = "FB_Robot" - }; - } private void FixedUpdate() { diff --git a/Runtime/Scripts/Components/SampleDevice.cs b/Runtime/Scripts/Components/SampleDevice.cs new file mode 100644 index 0000000..eb93c4a --- /dev/null +++ b/Runtime/Scripts/Components/SampleDevice.cs @@ -0,0 +1,17 @@ +using OC.Communication; +using UnityEngine; + +namespace OC.Components +{ + [SelectionBase] + [DisallowMultipleComponent] + public abstract class SampleDevice : MonoComponent, IDevice + { + public abstract Link Link { get; } + public IProperty Override => _override; + public abstract int AllocatedBitLength { get; } + + [SerializeField] + protected Property _override = new (false); + } +} diff --git a/Runtime/Scripts/Components/Device.cs.meta b/Runtime/Scripts/Components/SampleDevice.cs.meta similarity index 100% rename from Runtime/Scripts/Components/Device.cs.meta rename to Runtime/Scripts/Components/SampleDevice.cs.meta diff --git a/Runtime/Scripts/Components/SensorAnalog.cs b/Runtime/Scripts/Components/SensorAnalog.cs index 109c920..0cc43ff 100644 --- a/Runtime/Scripts/Components/SensorAnalog.cs +++ b/Runtime/Scripts/Components/SensorAnalog.cs @@ -26,7 +26,7 @@ public class SensorAnalog : MonoComponent, IDevice, ICustomInspector, IInteracta public UnityEvent OnValueChangedEvent; [SerializeField] - private LinkDataFloat _link; + private LinkDataFloat _link = new("FB_SensorAnalog"); private bool _isDeviceValid; private IMeasurement _measurementDevice; @@ -48,14 +48,6 @@ private void Start() OnValueChanged(_value.Value); } - private void Reset() - { - _link = new LinkDataFloat - { - Type = "FB_SensorAnalog" - }; - } - public void OnValidate() { _value.OnValidate(); diff --git a/Runtime/Scripts/Components/TagReader.cs b/Runtime/Scripts/Components/TagReader.cs index 7a0d03e..58739d0 100644 --- a/Runtime/Scripts/Components/TagReader.cs +++ b/Runtime/Scripts/Components/TagReader.cs @@ -20,14 +20,12 @@ public class TagReader : Detector, IDevice, IMeasurement, ICustomInspecto protected Property _override = new (false); [SerializeField] protected Property _value = new (0); - [SerializeField] private bool _holdValue; - - public UnityEvent OnValueChangedEvent; - [SerializeField] - private LinkDataLWord _link; + private LinkDataLWord _link = new("FB_Reader"); + + public UnityEvent OnValueChangedEvent; private BoxCollider _collider; private Rigidbody _rigidbody; @@ -55,14 +53,6 @@ private void Start() Initialize(); } - public void Reset() - { - _link = new LinkDataLWord - { - Type = "FB_Reader" - }; - } - protected override void OnPayloadEnterAction(PayloadBase payloadBase) { if (payloadBase is not Payload payload) return; diff --git a/Runtime/Scripts/Components/Transport.cs b/Runtime/Scripts/Components/Transport.cs index 8165de9..31289bf 100644 --- a/Runtime/Scripts/Components/Transport.cs +++ b/Runtime/Scripts/Components/Transport.cs @@ -23,7 +23,6 @@ public Actor Actor [SerializeField] private Actor _actor; - [SerializeField] protected float _width = 0.3f; [SerializeField] diff --git a/Runtime/Scripts/Components/TransportCurved.cs b/Runtime/Scripts/Components/TransportCurved.cs index fdba9d8..ff3bb7e 100644 --- a/Runtime/Scripts/Components/TransportCurved.cs +++ b/Runtime/Scripts/Components/TransportCurved.cs @@ -16,7 +16,6 @@ public class TransportCurved : Transport private Vector3 _direction; private Vector3 _translationSurfaceDelta; private Quaternion _rotationSurfaceDelta; - private float _arcLength; private float _angularSpeedFactor; private float _angularDeltaSpeed; diff --git a/Runtime/Scripts/Interactions/Button.cs b/Runtime/Scripts/Interactions/Button.cs index e17affd..7fba8c2 100644 --- a/Runtime/Scripts/Interactions/Button.cs +++ b/Runtime/Scripts/Interactions/Button.cs @@ -11,8 +11,9 @@ namespace OC.Interactions [AddComponentMenu("Open Commissioning/Actor/Button")] [SelectionBase] [DisallowMultipleComponent] - public class Button : Device, ICustomInspector + public class Button : SampleDevice, ICustomInspector { + public override Link Link => _link; public override int AllocatedBitLength => 1; public Property Pressed => _pressed; public Property Feedback => _feedback; @@ -24,7 +25,6 @@ public class Button : Device, ICustomInspector protected Property _pressed = new (false); [SerializeField] protected Property _feedback = new (false); - [SerializeField] protected bool _localFeedback; [SerializeField] @@ -35,6 +35,9 @@ public class Button : Device, ICustomInspector protected Property _color = new (UnityEngine.Color.cyan); [SerializeField] protected List _colorChangers = new (); + + [SerializeField] + protected Link _link = new ("FB_Button"); public UnityEvent OnClickEvent; public UnityEvent OnPressedChanged; @@ -42,9 +45,9 @@ public class Button : Device, ICustomInspector private const float CLICK_DURATION = 0.1f; - private new void Start() + private void Start() { - base.Start(); + _link.Initialize(this); _pressed.OnValueChanged += PressedOnOnValueChanged; _feedback.OnValueChanged += FeedbackOnOnValueChanged; } @@ -69,14 +72,6 @@ private void OnValidate() } } - public override void Reset() - { - _link = new Link - { - Type = "FB_Button" - }; - } - public void Click() { if (!Application.isPlaying) return; diff --git a/Runtime/Scripts/Interactions/Lamp.cs b/Runtime/Scripts/Interactions/Lamp.cs index f358a09..81b67f7 100644 --- a/Runtime/Scripts/Interactions/Lamp.cs +++ b/Runtime/Scripts/Interactions/Lamp.cs @@ -9,8 +9,10 @@ namespace OC.Interactions [AddComponentMenu("Open Commissioning/Interactions/Lamp")] [SelectionBase] [DisallowMultipleComponent] - public class Lamp : Device, ICustomInspector + public class Lamp : SampleDevice, ICustomInspector { + public override Link Link => _link; + public bool Signal { get => _value.Value; @@ -27,12 +29,15 @@ public bool Signal private Property _color = new(UnityEngine.Color.cyan); [SerializeField] protected List _colorChangers = new(); + + [SerializeField] + protected new Link _link = new ("FB_Lamp"); public UnityEvent OnValueChanged; - private new void Start() + private void Start() { - base.Start(); + _link.Initialize(this); _value.OnValueChanged += OnOnValueChangedAction; } @@ -41,14 +46,6 @@ private void OnDestroy() _value.OnValueChanged -= OnOnValueChangedAction; } - public override void Reset() - { - _link = new Link - { - Type = "FB_Lamp" - }; - } - private void LateUpdate() { if (!_override && _link.Connected) _value.Value = _link.Control.GetBit(0); diff --git a/Runtime/Scripts/Interactions/Lock.cs b/Runtime/Scripts/Interactions/Lock.cs index 25c63bf..473eb5f 100644 --- a/Runtime/Scripts/Interactions/Lock.cs +++ b/Runtime/Scripts/Interactions/Lock.cs @@ -30,14 +30,14 @@ public class Lock : MonoComponent, IDevice, ICustomInspector, IInteractable [SerializeField] private List _doors = new (); [SerializeField] - private List _buttons = new (); + private List _buttons = new (); public UnityEvent OnLockChanged; public UnityEvent OnClosedChanged; public UnityEvent OnLockedChanged; [SerializeField] - protected LinkDataByte _link; + protected LinkDataByte _link = new ("FB_Lock"); private void OnEnable() { @@ -57,14 +57,6 @@ protected void Start() { _link.Initialize(this); } - - public void Reset() - { - _link = new LinkDataByte - { - Type = "FB_Lock" - }; - } private void OnValidate() { diff --git a/Runtime/Scripts/Interactions/PanelSampler.cs b/Runtime/Scripts/Interactions/PanelSampler.cs index 5d35616..d3e8eec 100644 --- a/Runtime/Scripts/Interactions/PanelSampler.cs +++ b/Runtime/Scripts/Interactions/PanelSampler.cs @@ -14,16 +14,16 @@ public class PanelSampler : MonoComponent, IIndustrialPanel, ICustomInspector { public Link Link => _link; public IProperty Override => _override; - public List Components => _components; + public List Components => _components; [SerializeField] private string _name; [SerializeField] - private List _components = new (); + private List _components = new (); [SerializeField] protected Property _override = new (false); [SerializeField] - private LinkDataDWord _link; + private LinkDataDWord _link = new("FB_Panel"); private int _bitLength; private bool _isValid; @@ -35,14 +35,6 @@ private void Start() _link.Initialize(this); CheckSlots(); } - - public void Reset() - { - _link = new LinkDataDWord - { - Type = "FB_Panel" - }; - } private void LateUpdate() { diff --git a/Runtime/Scripts/Interactions/Switch.cs b/Runtime/Scripts/Interactions/Switch.cs index 68d87fe..50703f8 100644 --- a/Runtime/Scripts/Interactions/Switch.cs +++ b/Runtime/Scripts/Interactions/Switch.cs @@ -5,9 +5,11 @@ namespace OC.Interactions { - public class Switch : Device + public class Switch : SampleDevice { - public override int AllocatedBitLength => Mathf.Max(0,_stateCount - 1); + public override Link Link => _link; + + public override int AllocatedBitLength => Mathf.Max(0, _stateCount - 1); public IProperty Index => _index; @@ -16,9 +18,17 @@ public class Switch : Device protected Property _index = new (0); [SerializeField] protected int _stateCount = 2; + + [SerializeField] + protected Link _link = new ("FB_Switch"); public UnityEvent OnIndexChanged; + private void Start() + { + _link.Initialize(this); + } + protected void OnEnable() { _index.OnValueChanged += IndexChanged; @@ -28,15 +38,6 @@ protected void OnDisable() { _index.OnValueChanged -= IndexChanged; } - - public override void Reset() - { - _link = new Link - { - Type = "FB_Switch" - }; - - } protected void OnValidate() { diff --git a/Runtime/Scripts/Interactions/VisualElements/Factory.cs b/Runtime/Scripts/Interactions/VisualElements/Factory.cs index 6ae9290..20ab0c5 100644 --- a/Runtime/Scripts/Interactions/VisualElements/Factory.cs +++ b/Runtime/Scripts/Interactions/VisualElements/Factory.cs @@ -5,11 +5,11 @@ namespace OC.Interactions.UIElements { public static class Factory { - public static VisualElement Create(Device interactionDevice) + public static VisualElement Create(SampleDevice interactionSampleDevice) { - if (interactionDevice == null) return null; + if (interactionSampleDevice == null) return null; - switch (interactionDevice) + switch (interactionSampleDevice) { case Interactions.Button target: { diff --git a/Samples/Demo/0.1 Devices.unity b/Samples/Demo/0.1 Devices.unity index eb7f5d4..2b039e3 100644 --- a/Samples/Demo/0.1 Devices.unity +++ b/Samples/Demo/0.1 Devices.unity @@ -1256,6 +1256,37 @@ Rigidbody: m_Interpolate: 0 m_Constraints: 0 m_CollisionDetection: 0 +--- !u!1 &462606871 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 462606872} + m_Layer: 0 + m_Name: GameObject + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &462606872 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 462606871} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0.25193372, y: 1.840461, z: 1.1851037} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &475519412 GameObject: m_ObjectHideFlags: 0 @@ -6510,6 +6541,11 @@ MonoBehaviour: m_EditorClassIdentifier: _override: _value: 0 + _value: + _value: 0 + _color: + _value: {r: 0, g: 1, b: 1, a: 1} + _colorChangers: [] _link: Control: 0 Status: 0 @@ -6523,11 +6559,6 @@ MonoBehaviour: _parent: {fileID: 0} _attributes: [] _variablesDescription: [] - _value: - _value: 0 - _color: - _value: {r: 0, g: 1, b: 1, a: 1} - _colorChangers: [] OnValueChanged: m_PersistentCalls: m_Calls: @@ -6970,6 +7001,9 @@ MonoBehaviour: m_EditorClassIdentifier: _override: _value: 0 + _index: + _value: 0 + _stateCount: 2 _link: Control: 0 Status: 0 @@ -6983,9 +7017,6 @@ MonoBehaviour: _parent: {fileID: 0} _attributes: [] _variablesDescription: [] - _index: - _value: 0 - _stateCount: 2 OnIndexChanged: m_PersistentCalls: m_Calls: [] @@ -7005,3 +7036,4 @@ SceneRoots: - {fileID: 1925809918} - {fileID: 1569426196} - {fileID: 1982148124} + - {fileID: 462606872} diff --git a/Samples/Demo/Prefabs/Button.prefab b/Samples/Demo/Prefabs/Button.prefab index 4126ae6..25e22f2 100644 --- a/Samples/Demo/Prefabs/Button.prefab +++ b/Samples/Demo/Prefabs/Button.prefab @@ -248,6 +248,17 @@ MonoBehaviour: m_EditorClassIdentifier: _override: _value: 0 + _pressed: + _value: 0 + _feedback: + _value: 0 + _localFeedback: 0 + _type: 0 + _visualStyle: + _value: 0 + _color: + _value: {r: 0, g: 1, b: 1, a: 1} + _colorChangers: [] _link: Control: 0 Status: 0 @@ -261,17 +272,6 @@ MonoBehaviour: _parent: {fileID: 0} _attributes: [] _variablesDescription: [] - _pressed: - _value: 0 - _feedback: - _value: 0 - _localFeedback: 0 - _type: 0 - _visualStyle: - _value: 0 - _color: - _value: {r: 0, g: 1, b: 1, a: 1} - _colorChangers: [] OnClickEvent: m_PersistentCalls: m_Calls: [] diff --git a/Tests/Runtime/Components/TestCylinder.cs b/Tests/Runtime/Components/TestCylinder.cs index d66585f..4208165 100644 --- a/Tests/Runtime/Components/TestCylinder.cs +++ b/Tests/Runtime/Components/TestCylinder.cs @@ -4,7 +4,6 @@ using System.Collections; using System.Collections.Generic; using NUnit.Framework; -using OC.Tests; using Assert = UnityEngine.Assertions.Assert; namespace OC.Tests.Runtime.Components @@ -17,7 +16,6 @@ public class TestCylinder public IEnumerator UnitySetUp() { _cylinder = new GameObject().AddComponent(); - _cylinder.Reset(); yield return null; }