diff --git a/CHANGELOG.md b/CHANGELOG.md index f091d2e..53819c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## [1.2.7](https://github.com/OpenCommissioning/OC_Unity_Core/compare/v1.2.6...v1.2.7) (2025-06-30) + + +### Bug Fixes + +* ads variable compatibility ([ae3e410](https://github.com/OpenCommissioning/OC_Unity_Core/commit/ae3e4108dd7289a5ce79a1acdf737fbe4829d1f0)) +* client path ([6fa523d](https://github.com/OpenCommissioning/OC_Unity_Core/commit/6fa523d4350fb796df4c3878c3c4267f21d7b9ab)) +* **Link:** link type initialization ([a250b4c](https://github.com/OpenCommissioning/OC_Unity_Core/commit/a250b4cb575e646308d76b15a1c3348198e648df)) +* **link:** merge connector to link ([3ed0350](https://github.com/OpenCommissioning/OC_Unity_Core/commit/3ed03506ba0186384be3723af5340bba65d22956)) +* **Metarial Flow:** detector merge ([3fe2a17](https://github.com/OpenCommissioning/OC_Unity_Core/commit/3fe2a170f09901e912c4f0fa236cdf8259e89e0c)) +* override property ([351206f](https://github.com/OpenCommissioning/OC_Unity_Core/commit/351206fa8c7f4ce14d414a0f9f196a045381f683)) +* reset hotfix ([721110c](https://github.com/OpenCommissioning/OC_Unity_Core/commit/721110c3aa8e78c61134f256c77e57a36dab962c)) +* sample scene cleanup ([4532364](https://github.com/OpenCommissioning/OC_Unity_Core/commit/4532364b6ca762d8c6fa1703aab83ce6be2745ca)) + ## [1.2.6](https://github.com/OpenCommissioning/OC_Unity_Core/compare/v1.2.5...v1.2.6) (2025-05-28) diff --git a/Editor/Scripts/Hierarchy/ProjectInspectorWindow.cs b/Editor/Scripts/Hierarchy/ProjectInspectorWindow.cs index e3d88a6..0d6ac11 100644 --- a/Editor/Scripts/Hierarchy/ProjectInspectorWindow.cs +++ b/Editor/Scripts/Hierarchy/ProjectInspectorWindow.cs @@ -95,7 +95,7 @@ private MultiColumnTreeView CreateMultiColumnTreeView() { label.style.display = DisplayStyle.Flex; if (item.Component is not IDevice device) return; - label.text = device.Link.Path; + label.text = device.Link.ScenePath; } } }; diff --git a/Editor/Scripts/Inspector/Cylinder.cs b/Editor/Scripts/Inspector/Cylinder.cs index 763962a..873c92a 100644 --- a/Editor/Scripts/Inspector/Cylinder.cs +++ b/Editor/Scripts/Inspector/Cylinder.cs @@ -16,7 +16,7 @@ public override VisualElement CreateInspectorGUI() var container = new VisualElement(); var groupControl = new PropertyGroup("Control"); - groupControl.AddLinkOverride(serializedObject); + groupControl.AddOverride(serializedObject); var hStack = new StackHorizontal(); hStack.Add(new PushButton("Minus").BindProperty(component.Minus)); hStack.Add(new PushButton("Plus").BindProperty(component.Plus)); diff --git a/Editor/Scripts/Inspector/DrivePosition.cs b/Editor/Scripts/Inspector/DrivePosition.cs index e0c9ad7..d2a6429 100644 --- a/Editor/Scripts/Inspector/DrivePosition.cs +++ b/Editor/Scripts/Inspector/DrivePosition.cs @@ -17,7 +17,7 @@ public override VisualElement CreateInspectorGUI() var container = new VisualElement(); var groupControl = new PropertyGroup("Control"); - groupControl.AddLinkOverride(serializedObject); + groupControl.AddOverride(serializedObject); groupControl.Add(new FloatField("Target").BindProperty(component.Target).AlignedField()); var groupStatus = new PropertyGroup("Status"); diff --git a/Editor/Scripts/Inspector/DriveSimple.cs b/Editor/Scripts/Inspector/DriveSimple.cs index d4b6747..4be2636 100644 --- a/Editor/Scripts/Inspector/DriveSimple.cs +++ b/Editor/Scripts/Inspector/DriveSimple.cs @@ -17,7 +17,7 @@ public override VisualElement CreateInspectorGUI() var container = new VisualElement(); var groupControl = new PropertyGroup("Control"); - groupControl.AddLinkOverride(serializedObject); + groupControl.AddOverride(serializedObject); var hStack = new StackHorizontal(); hStack.Add(new ToggleButton("Backward").BindProperty(component.Backward)); hStack.Add(new ToggleButton("Forward").BindProperty(component.Forward)); diff --git a/Editor/Scripts/Inspector/DriveSpeed.cs b/Editor/Scripts/Inspector/DriveSpeed.cs index 3b30812..323bb83 100644 --- a/Editor/Scripts/Inspector/DriveSpeed.cs +++ b/Editor/Scripts/Inspector/DriveSpeed.cs @@ -17,7 +17,7 @@ public override VisualElement CreateInspectorGUI() var container = new VisualElement(); var groupControl = new PropertyGroup("Control"); - groupControl.AddLinkOverride(serializedObject); + groupControl.AddOverride(serializedObject); groupControl.Add(new FloatField("Target").BindProperty(component.Target).AlignedField()); var groupStatus = new PropertyGroup("Status"); diff --git a/Editor/Scripts/Inspector/Lamp.cs b/Editor/Scripts/Inspector/Lamp.cs index 3310110..268d38c 100644 --- a/Editor/Scripts/Inspector/Lamp.cs +++ b/Editor/Scripts/Inspector/Lamp.cs @@ -18,7 +18,7 @@ public override VisualElement CreateInspectorGUI() var container = new VisualElement(); var groupControl = new PropertyGroup("Control"); - groupControl.AddLinkOverride(serializedObject); + groupControl.AddOverride(serializedObject); groupControl.Add(new ToggleButton("Signal").BindProperty(component.Value).AlignedField()); var groupStatus = new PropertyGroup("Status"); diff --git a/Editor/Scripts/Inspector/Lock.cs b/Editor/Scripts/Inspector/Lock.cs index f49b305..3dd5f77 100644 --- a/Editor/Scripts/Inspector/Lock.cs +++ b/Editor/Scripts/Inspector/Lock.cs @@ -17,7 +17,7 @@ public override VisualElement CreateInspectorGUI() var container = new VisualElement(); var groupControl = new PropertyGroup("Control"); - groupControl.AddLinkOverride(serializedObject); + groupControl.AddOverride(serializedObject); groupControl.Add(new ToggleButton("Lock").BindProperty(component.LockSignal)); var groupStatus = new PropertyGroup("Status"); diff --git a/Editor/Scripts/Inspector/LinkOverrideController.cs b/Editor/Scripts/Inspector/OverrideController.cs similarity index 75% rename from Editor/Scripts/Inspector/LinkOverrideController.cs rename to Editor/Scripts/Inspector/OverrideController.cs index db22328..88d428e 100644 --- a/Editor/Scripts/Inspector/LinkOverrideController.cs +++ b/Editor/Scripts/Inspector/OverrideController.cs @@ -5,11 +5,11 @@ namespace OC.Editor { - public class LinkOverrideController : ToggleButton + public class OverrideController : ToggleButton { - private const string PROPERTY_PATH = "_link._override._value"; + private const string PROPERTY_PATH = "_override._value"; - public LinkOverrideController(SerializedObject serializedObject, VisualElement target) + public OverrideController(SerializedObject serializedObject, VisualElement target) { label = "Override"; diff --git a/Editor/Scripts/Inspector/LinkOverrideController.cs.meta b/Editor/Scripts/Inspector/OverrideController.cs.meta similarity index 100% rename from Editor/Scripts/Inspector/LinkOverrideController.cs.meta rename to Editor/Scripts/Inspector/OverrideController.cs.meta diff --git a/Editor/Scripts/Inspector/SensorAnalog.cs b/Editor/Scripts/Inspector/SensorAnalog.cs index 0d7b936..41bc582 100644 --- a/Editor/Scripts/Inspector/SensorAnalog.cs +++ b/Editor/Scripts/Inspector/SensorAnalog.cs @@ -16,7 +16,7 @@ public override VisualElement CreateInspectorGUI() var container = new VisualElement(); var groupControl = new PropertyGroup("Control"); - groupControl.AddLinkOverride(serializedObject); + groupControl.AddOverride(serializedObject); groupControl.Add(new FloatField("Value").BindProperty(component.Value).AlignedField()); var groupStatus = new PropertyGroup("Status"); diff --git a/Editor/Scripts/Inspector/SensorBinary.cs b/Editor/Scripts/Inspector/SensorBinary.cs index 81805be..35eb24c 100644 --- a/Editor/Scripts/Inspector/SensorBinary.cs +++ b/Editor/Scripts/Inspector/SensorBinary.cs @@ -18,7 +18,7 @@ public override VisualElement CreateInspectorGUI() var container = new VisualElement(); var groupControl = new PropertyGroup("Control"); - groupControl.AddLinkOverride(serializedObject); + groupControl.AddOverride(serializedObject); groupControl.Add(new ToggleButton("Collision").BindProperty(component.State).AlignedField()); var groupStatus = new PropertyGroup("Status"); diff --git a/Editor/Scripts/Inspector/SignalBinary.cs b/Editor/Scripts/Inspector/SignalBinary.cs index 655afc0..614f47c 100644 --- a/Editor/Scripts/Inspector/SignalBinary.cs +++ b/Editor/Scripts/Inspector/SignalBinary.cs @@ -17,7 +17,7 @@ public override VisualElement CreateInspectorGUI() var container = new VisualElement(); var groupControl = new PropertyGroup("Control"); - groupControl.AddLinkOverride(serializedObject); + groupControl.AddOverride(serializedObject); groupControl.Add(new ToggleButton("Signal").BindProperty(component.Signal).AlignedField()); var groupStatus = new PropertyGroup("Status"); diff --git a/Editor/Scripts/Inspector/TagReader.cs b/Editor/Scripts/Inspector/TagReader.cs index 785690c..fed2cad 100644 --- a/Editor/Scripts/Inspector/TagReader.cs +++ b/Editor/Scripts/Inspector/TagReader.cs @@ -17,7 +17,7 @@ public override VisualElement CreateInspectorGUI() var container = new VisualElement(); var groupControl = new PropertyGroup("Control"); - groupControl.AddLinkOverride(serializedObject); + groupControl.AddOverride(serializedObject); groupControl.Add(new UnsignedLongField("Value").BindProperty(component.Value).AlignedField()); var groupStatus = new PropertyGroup("Status"); diff --git a/Editor/Scripts/ProductData/ProductDataViewer.cs b/Editor/Scripts/ProductData/ProductDataViewer.cs index 9a45659..c01cacb 100644 --- a/Editor/Scripts/ProductData/ProductDataViewer.cs +++ b/Editor/Scripts/ProductData/ProductDataViewer.cs @@ -91,7 +91,7 @@ private void OnSelectionChange() private void GetPayloadTagData(PayloadTag payloadTag) { _payloadTag = payloadTag; - _directories = ProductDataDirectoryManager.Instance.GetValidDataDirectories(payloadTag.DirecotryId); + _directories = ProductDataDirectoryManager.Instance.GetValidDataDirectories(payloadTag.DirectoryId); if (_directories.Count == 0) return; _dropdownFieldDirectory.choices = _directories.Select(directory => directory.Name).ToList(); _dropdownFieldDirectory.value = _directories[0].Name; diff --git a/Editor/Scripts/PropertyDrawer/PropertyDrawerLink.cs b/Editor/Scripts/PropertyDrawer/PropertyDrawerLink.cs index 4038e1f..431c959 100644 --- a/Editor/Scripts/PropertyDrawer/PropertyDrawerLink.cs +++ b/Editor/Scripts/PropertyDrawer/PropertyDrawerLink.cs @@ -6,7 +6,7 @@ namespace OC.Editor { - [CustomPropertyDrawer(typeof(Link))] + [CustomPropertyDrawer(typeof(Link), true)] public class PropertyDrawerLink : PropertyDrawer { public override VisualElement CreatePropertyGUI(SerializedProperty property) @@ -14,7 +14,6 @@ public override VisualElement CreatePropertyGUI(SerializedProperty property) var container = new PropertyGroup("Communication"); container.AddHeaderElement(new LampField{bindingPath = "_isConnected._value", LampShape = LampField.InspectorLampShape.Round}); container.Add(new Toggle("Is Enabled"){bindingPath = "_enable"}.AlignedField()); - container.Add(new Toggle("Override") {bindingPath = "_override._value"}.AlignedField()); container.Add(new TextField("Path"){bindingPath = "_path", isReadOnly = true}.AlignedField()); container.Add(new TextField("Type"){bindingPath = "_type"}.AlignedField()); container.Add(new ObjectField("Parent"){bindingPath = "_parent", objectType = typeof(Hierarchy)}.AlignedField()); diff --git a/Editor/Scripts/VisualElements/PropertyGroup.cs b/Editor/Scripts/VisualElements/PropertyGroup.cs index 9d3c791..1a7e56a 100644 --- a/Editor/Scripts/VisualElements/PropertyGroup.cs +++ b/Editor/Scripts/VisualElements/PropertyGroup.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using OC.Components; using UnityEditor; using UnityEngine; using UnityEngine.UIElements; @@ -35,7 +36,7 @@ public string Label private readonly Label _labelElement; private readonly VisualElement _options; private readonly VisualElement _content; - private LinkOverrideController _linkOverrideController; + private OverrideController _overrideController; private const string USS = "StyleSheet/oc-inspector"; private const string USS_CLASS_NAME = "property-group"; @@ -85,10 +86,11 @@ public void AddHeaderElement(VisualElement visualElement) _options.Add(visualElement); } - public void AddLinkOverride(SerializedObject serializedObject) + public void AddOverride(SerializedObject serializedObject) { - var linkOverrideController = new LinkOverrideController(serializedObject, _content); - _options.Add(linkOverrideController); + if (serializedObject.targetObject is not IOverride) return; + var overrideController = new OverrideController(serializedObject, _content); + _options.Add(overrideController); } } } diff --git a/Runtime/Scripts/Communication/Client/Client.cs b/Runtime/Scripts/Communication/Client/Client.cs index 83d47d0..3a691b6 100644 --- a/Runtime/Scripts/Communication/Client/Client.cs +++ b/Runtime/Scripts/Communication/Client/Client.cs @@ -1,10 +1,8 @@ -using System; using System.Collections.Generic; using System.Xml.Linq; using OC.PlayerLoop; using OC.Project; using UnityEngine; -using Object = UnityEngine.Object; namespace OC.Communication { @@ -18,8 +16,8 @@ public abstract class Client : MonoBehaviour, IClient, IConfigAsset, IAfterFixed public float TimeScale { - get => _connector.TimeScale; - set => _connector.TimeScale = value; + get => _link.TimeScale; + set => _link.TimeScale = value; } [SerializeField] @@ -31,10 +29,7 @@ public float TimeScale [HideInInspector] [SerializeField] - private Link _link; - [HideInInspector] - [SerializeField] - private ConnectorClient _connector; + private LinkDataSystem _link; private List _links; @@ -54,20 +49,27 @@ protected void OnDisable() protected void Start() { - _link = new Link(this, "fbSystem", $"{_rootName}.fbSystem"); - _connector = new ConnectorClient(_link) - { - TimeScale = Time.timeScale - }; + _link.ScenePath = $"{_rootName}.fbSystem"; + _link.ClientPath = _link.ScenePath.GetClientCompatiblePath(); + _link.TimeScale = Time.timeScale; _links = new List { _link }; - foreach (var component in GetComponentsInChildren()) + foreach (var component in GetComponentsInChildren()) { if (!component.Link.Enable) continue; _links.Add(component.Link); } } + + private void Reset() + { + _link = new LinkDataSystem + { + Name = "fbSystem", + Component = this + }; + } public virtual void BeforeFixedUpdate() { @@ -92,45 +94,11 @@ public virtual void AfterFixedUpdate() public abstract void Connect(); public abstract void Disconnect(); - private bool TryFindVariable(ClientVariableDescription discription, Object target, out ClientVariable variable) - { - try - { - var adsVariable = discription.Direction == ClientVariableDirection.Input ? - Buffer.InputVariables.Find(x => x.Name == discription.Name) : - Buffer.OutputVariables.Find(x => x.Name == discription.Name); - - variable = adsVariable ?? throw new Exception($"{discription.Name} can't be found in client!"); - if (variable.Reserved) throw new Exception($"{discription.Name} already reserved!"); - variable.Reserved = true; - return true; - } - catch (Exception exception) - { - Logging.Logger.Log(LogType.Warning, exception.Message, target); - variable = null; - return false; - } - } - - public bool TryGetVariables(List list, Link link, out List variables) + public ClientVariable GetClientVariable(ClientVariableDescription description) { - var valid = true; - variables = new List(); - - foreach (var discription in list) - { - if (TryFindVariable(discription, link.Component, out var variable)) - { - variables.Add(variable); - } - else - { - valid = false; - } - } - - return valid; + return description.Direction == ClientVariableDirection.Input ? + Buffer.InputVariables.Find(x => x.Name == description.Path) : + Buffer.OutputVariables.Find(x => x.Name == description.Path); } private void OnConnectionChanged(bool isConnected) diff --git a/Runtime/Scripts/Communication/Client/ClientVariable.cs b/Runtime/Scripts/Communication/Client/ClientVariable.cs index ddca79a..ccca1ec 100644 --- a/Runtime/Scripts/Communication/Client/ClientVariable.cs +++ b/Runtime/Scripts/Communication/Client/ClientVariable.cs @@ -11,7 +11,7 @@ public class ClientVariable private readonly int _length; private readonly int _offset; - public ClientVariable(byte[] buffer, string name, int length, int offset) + public ClientVariable(string name, byte[] buffer, int length, int offset) { Name = name; _buffer = buffer; diff --git a/Runtime/Scripts/Communication/Client/ClientVariableDescription.cs b/Runtime/Scripts/Communication/Client/ClientVariableDescription.cs index 43d10e5..bf88aa9 100644 --- a/Runtime/Scripts/Communication/Client/ClientVariableDescription.cs +++ b/Runtime/Scripts/Communication/Client/ClientVariableDescription.cs @@ -1,8 +1,11 @@ +using System; + namespace OC.Communication { + [Serializable] public struct ClientVariableDescription { - public string Name; + public string Path; public ClientVariableDirection Direction; } } \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Client/ClientVariableExtension.cs b/Runtime/Scripts/Communication/Client/ClientVariableExtension.cs index 42e08fd..2ba990e 100644 --- a/Runtime/Scripts/Communication/Client/ClientVariableExtension.cs +++ b/Runtime/Scripts/Communication/Client/ClientVariableExtension.cs @@ -1,11 +1,26 @@ -using System.Text.RegularExpressions; -using UnityEngine; - namespace OC.Communication { public static class ClientVariableExtension { - private static readonly Regex InvalidChars = new ("[^A-Za-z0-9_]", RegexOptions.Compiled); + /// + /// Returns a path with each segment wrapped in backticks if it contains invalid characters. + /// + public static string GetClientCompatiblePath(this string path) + { + if (string.IsNullOrWhiteSpace(path)) return string.Empty; + + var parts = path.Split('.'); + + for (var i = 0; i < parts.Length; i++) + { + if (!IsVariableNameValid(parts[i])) + { + parts[i] = $"`{parts[i]}`"; + } + } + + return string.Join(".", parts); + } /// /// Returns true if: @@ -26,26 +41,5 @@ public static bool IsVariableNameValid(string name) return true; } - - /// - /// Replace spaces and hyphens with underscore - /// Remove any other invalid characters - /// Ensure it starts with a letter by prefixing 'A' if needed - /// - public static string CorrectVariableName(string input) - { - if (string.IsNullOrEmpty(input)) return input; - - var withUnderscores = Regex.Replace(input, @"[\s-]+", "_"); - var cleaned = InvalidChars.Replace(withUnderscores, ""); - - if (char.IsLetter(cleaned[0])) return cleaned; - - var name = "A" + cleaned; - - cleaned = name; - - return cleaned; - } } } \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Client/ConnectorClient.cs b/Runtime/Scripts/Communication/Client/ConnectorClient.cs deleted file mode 100644 index bb3e91c..0000000 --- a/Runtime/Scripts/Communication/Client/ConnectorClient.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace OC.Communication -{ - [System.Serializable] - public class ConnectorClient : Connector - { - // ReSharper disable once InconsistentNaming - public float TimeScale; - - public ConnectorClient(Link link) : base(link) - { - - } - - protected override void CreateVariableDescription() - { - base.CreateVariableDescription(); - _variablesDescription.Add(new ClientVariableDescription { Name = _link.Path + ".TimeScaling", Direction = ClientVariableDirection.Output }); - } - - public override void Read() - { - base.Read(); - Status.SetBit(7, Control.GetBit(7)); - } - - public override void Write() - { - base.Write(); - _variables[2].Write(ref TimeScale); - } - } -} \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Client/ConnectorClient.cs.meta b/Runtime/Scripts/Communication/Client/ConnectorClient.cs.meta deleted file mode 100644 index e3726d6..0000000 --- a/Runtime/Scripts/Communication/Client/ConnectorClient.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 2a2d7a1db839423e9c29c029f0bc25e8 -timeCreated: 1677073457 \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Client/TwinCAT/TcAdsSumCommandBuffer.cs b/Runtime/Scripts/Communication/Client/TwinCAT/TcAdsSumCommandBuffer.cs index bef6a80..e3c378c 100644 --- a/Runtime/Scripts/Communication/Client/TwinCAT/TcAdsSumCommandBuffer.cs +++ b/Runtime/Scripts/Communication/Client/TwinCAT/TcAdsSumCommandBuffer.cs @@ -151,7 +151,7 @@ private void InitializeSumCommandBuffer() _blockReadWrStream.Write(adsSymbol.IndexGroup); _blockReadWrStream.Write(adsSymbol.IndexOffset); _blockReadWrStream.Write(adsSymbol.ByteSize); - _inputVariables.Add(new ClientVariable(_blockReadRdStream.Buffer, adsSymbol.InstancePath, adsSymbol.Size, offset)); + _inputVariables.Add(new ClientVariable(adsSymbol.InstancePath, _blockReadRdStream.Buffer, adsSymbol.Size, offset)); offset += adsSymbol.ByteSize; } @@ -164,7 +164,7 @@ private void InitializeSumCommandBuffer() _blockWriteWrStream.Write(adsSymbol.IndexGroup); _blockWriteWrStream.Write(adsSymbol.IndexOffset); _blockWriteWrStream.Write(adsSymbol.ByteSize); - _outputVariables.Add(new ClientVariable(_blockWriteWrStream.Buffer, adsSymbol.InstancePath, adsSymbol.Size, offset)); + _outputVariables.Add(new ClientVariable(adsSymbol.InstancePath, _blockWriteWrStream.Buffer, adsSymbol.Size, offset)); offset += adsSymbol.ByteSize; } } diff --git a/Runtime/Scripts/Communication/Client/TwinCAT/TcAdsTaskBuffer.cs b/Runtime/Scripts/Communication/Client/TwinCAT/TcAdsTaskBuffer.cs index 7478ea4..2bd21d6 100644 --- a/Runtime/Scripts/Communication/Client/TwinCAT/TcAdsTaskBuffer.cs +++ b/Runtime/Scripts/Communication/Client/TwinCAT/TcAdsTaskBuffer.cs @@ -97,8 +97,8 @@ private void Initialize() _inputBuffer = new byte[_inputSymbols.Sum(item => item.ByteSize)]; _outputBuffer = new byte[_outputSymbols.Sum(item => item.ByteSize)]; - CreateVairables(_inputBuffer, _inputSymbols, _inputVariables); - CreateVairables(_outputBuffer, _outputSymbols, _outputVariables); + CreateVariables(_inputBuffer, _inputSymbols, _inputVariables); + CreateVariables(_outputBuffer, _outputSymbols, _outputVariables); _isConnected = true; Logging.Logger.Log(LogType.Log, $"TcAds Task Client {_inputBuffer.Length} byte inputs - {_outputBuffer.Length} byte outputs."); @@ -115,7 +115,7 @@ private void AddSymbols(ISymbolProvider adsSymbolLoader) _outputSymbols.Sort((x,y) => x.IndexOffset.CompareTo(y.IndexOffset)); } - private void CreateVairables(byte[] buffer, List symbols, List variables) + private void CreateVariables(byte[] buffer, List symbols, List variables) { var offset = 0; @@ -126,7 +126,7 @@ private void CreateVairables(byte[] buffer, List symbols, List _variables = new(); - protected List _variablesDescription = new(); - - public Connector(Link link) - { - _link = link; - _link.Add(this); - } - - public void Connect(Client client) - { - IsConnected = false; - _variablesDescription = new List(); - CreateVariableDescription(); - - _variables = new List(); - IsConnected = client.TryGetVariables(_variablesDescription, _link, out _variables); - } - - protected virtual void CreateVariableDescription() - { - _variablesDescription.Add(new ClientVariableDescription { Name = _link.Path + ".Control", Direction = ClientVariableDirection.Input }); - _variablesDescription.Add(new ClientVariableDescription { Name = _link.Path + ".Status", Direction = ClientVariableDirection.Output }); - } - - public virtual void Read() - { - _variables[0].Read(ref Control); - } - - public virtual void Write() - { - _variables[1].Write(Status); - } - } -} diff --git a/Runtime/Scripts/Communication/Connector/Connector.cs.meta b/Runtime/Scripts/Communication/Connector/Connector.cs.meta deleted file mode 100644 index 4383adb..0000000 --- a/Runtime/Scripts/Communication/Connector/Connector.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 3fab2055f7b54509a1ebc87ad697b85f -timeCreated: 1675936729 \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Connector/ConnectorDataByte.cs b/Runtime/Scripts/Communication/Connector/ConnectorDataByte.cs deleted file mode 100644 index dcc1249..0000000 --- a/Runtime/Scripts/Communication/Connector/ConnectorDataByte.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace OC.Communication -{ - [System.Serializable] - public class ConnectorDataByte : Connector - { - public byte ControlData; - public byte StatusData; - - public ConnectorDataByte(Link link) : base(link) - { - - } - - protected override void CreateVariableDescription() - { - base.CreateVariableDescription(); - _variablesDescription.Add(new ClientVariableDescription { Name = _link.Path + ".ControlData", Direction = ClientVariableDirection.Input }); - _variablesDescription.Add(new ClientVariableDescription { Name = _link.Path + ".StatusData", Direction = ClientVariableDirection.Output }); - } - - public override void Read() - { - base.Read(); - _variables[2].Read(ref ControlData); - } - - public override void Write() - { - base.Write(); - _variables[3].Write(StatusData); - } - } -} diff --git a/Runtime/Scripts/Communication/Connector/ConnectorDataByte.cs.meta b/Runtime/Scripts/Communication/Connector/ConnectorDataByte.cs.meta deleted file mode 100644 index 267c068..0000000 --- a/Runtime/Scripts/Communication/Connector/ConnectorDataByte.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 6208453c63f9aab45b9270dac739e0a0 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Scripts/Communication/Connector/ConnectorDataDWord.cs b/Runtime/Scripts/Communication/Connector/ConnectorDataDWord.cs deleted file mode 100644 index 9f3e35e..0000000 --- a/Runtime/Scripts/Communication/Connector/ConnectorDataDWord.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace OC.Communication -{ - [System.Serializable] - public class ConnectorDataDWord : Connector - { - public uint ControlData; - public uint StatusData; - - public ConnectorDataDWord(Link link) : base(link) - { - - } - - protected override void CreateVariableDescription() - { - base.CreateVariableDescription(); - _variablesDescription.Add(new ClientVariableDescription { Name = _link.Path + ".ControlData", Direction = ClientVariableDirection.Input }); - _variablesDescription.Add(new ClientVariableDescription { Name = _link.Path + ".StatusData", Direction = ClientVariableDirection.Output }); - } - - public override void Read() - { - base.Read(); - _variables[2].Read(ref ControlData); - } - - public override void Write() - { - base.Write(); - _variables[3].Write(StatusData); - } - } -} diff --git a/Runtime/Scripts/Communication/Connector/ConnectorDataDWord.cs.meta b/Runtime/Scripts/Communication/Connector/ConnectorDataDWord.cs.meta deleted file mode 100644 index b13d9c6..0000000 --- a/Runtime/Scripts/Communication/Connector/ConnectorDataDWord.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 6bf90ff223703d74bbc528207d05ffaf -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Scripts/Communication/Connector/ConnectorDataFloat.cs b/Runtime/Scripts/Communication/Connector/ConnectorDataFloat.cs deleted file mode 100644 index 45a3a95..0000000 --- a/Runtime/Scripts/Communication/Connector/ConnectorDataFloat.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace OC.Communication -{ - [System.Serializable] - public class ConnectorDataFloat : Connector - { - public float ControlData; - public float StatusData; - - public ConnectorDataFloat(Link link) : base(link) - { - - } - - protected override void CreateVariableDescription() - { - base.CreateVariableDescription(); - _variablesDescription.Add(new ClientVariableDescription { Name = _link.Path + ".ControlData", Direction = ClientVariableDirection.Input }); - _variablesDescription.Add(new ClientVariableDescription { Name = _link.Path + ".StatusData", Direction = ClientVariableDirection.Output }); - } - - public override void Read() - { - base.Read(); - _variables[2].Read(ref ControlData); - } - - public override void Write() - { - base.Write(); - _variables[3].Write(ref StatusData); - } - } -} diff --git a/Runtime/Scripts/Communication/Connector/ConnectorDataFloat.cs.meta b/Runtime/Scripts/Communication/Connector/ConnectorDataFloat.cs.meta deleted file mode 100644 index 5a2a5e9..0000000 --- a/Runtime/Scripts/Communication/Connector/ConnectorDataFloat.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 3ef04ebfe0f699443b5a8222e19bb451 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Scripts/Communication/Connector/ConnectorDataLWord.cs b/Runtime/Scripts/Communication/Connector/ConnectorDataLWord.cs deleted file mode 100644 index a1c18f6..0000000 --- a/Runtime/Scripts/Communication/Connector/ConnectorDataLWord.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace OC.Communication -{ - [System.Serializable] - public class ConnectorDataLWord : Connector - { - public long ControlData; - public long StatusData; - - public ConnectorDataLWord(Link link) : base(link) - { - - } - - protected override void CreateVariableDescription() - { - base.CreateVariableDescription(); - _variablesDescription.Add(new ClientVariableDescription { Name = _link.Path + ".ControlData", Direction = ClientVariableDirection.Input }); - _variablesDescription.Add(new ClientVariableDescription { Name = _link.Path + ".StatusData", Direction = ClientVariableDirection.Output }); - } - - public override void Read() - { - base.Read(); - _variables[2].Read(ref ControlData); - } - - public override void Write() - { - base.Write(); - _variables[3].Write(StatusData); - } - } -} diff --git a/Runtime/Scripts/Communication/Connector/ConnectorDataLWord.cs.meta b/Runtime/Scripts/Communication/Connector/ConnectorDataLWord.cs.meta deleted file mode 100644 index 1b54d61..0000000 --- a/Runtime/Scripts/Communication/Connector/ConnectorDataLWord.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 880f13ab6f5a25b41b275303cf020eee -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Scripts/Communication/Connector/ConnectorDataRobot.cs b/Runtime/Scripts/Communication/Connector/ConnectorDataRobot.cs deleted file mode 100644 index 2c7b434..0000000 --- a/Runtime/Scripts/Communication/Connector/ConnectorDataRobot.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace OC.Communication -{ - [System.Serializable] - public class ConnectorDataRobot : Connector - { - public float[] JointTarget = new float[12]; - public float[] JointStatus = new float[12]; - - public ConnectorDataRobot(Link link) : base(link) - { - - } - - protected override void CreateVariableDescription() - { - base.CreateVariableDescription(); - _variablesDescription.Add(new ClientVariableDescription { Name = _link.Path + ".JointTarget", Direction = ClientVariableDirection.Input }); - _variablesDescription.Add(new ClientVariableDescription { Name = _link.Path + ".JointStatus", Direction = ClientVariableDirection.Output }); - } - - public override void Read() - { - base.Read(); - _variables[2].Read(ref JointTarget); - } - - public override void Write() - { - base.Write(); - _variables[3].Write(ref JointStatus); - } - } -} diff --git a/Runtime/Scripts/Communication/Connector/ConnectorDataRobot.cs.meta b/Runtime/Scripts/Communication/Connector/ConnectorDataRobot.cs.meta deleted file mode 100644 index 5a1e8c7..0000000 --- a/Runtime/Scripts/Communication/Connector/ConnectorDataRobot.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: f9d423b3a824c30468dfb3973481e04e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Scripts/Communication/Connector/ConnectorDataWord.cs b/Runtime/Scripts/Communication/Connector/ConnectorDataWord.cs deleted file mode 100644 index 917dcc7..0000000 --- a/Runtime/Scripts/Communication/Connector/ConnectorDataWord.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace OC.Communication -{ - [System.Serializable] - public class ConnectorDataWord : Connector - { - public short ControlData; - public short StatusData; - - public ConnectorDataWord(Link link) : base(link) - { - - } - - protected override void CreateVariableDescription() - { - base.CreateVariableDescription(); - _variablesDescription.Add(new ClientVariableDescription { Name = _link.Path + ".ControlData", Direction = ClientVariableDirection.Input }); - _variablesDescription.Add(new ClientVariableDescription { Name = _link.Path + ".StatusData", Direction = ClientVariableDirection.Output }); - } - - public override void Read() - { - base.Read(); - _variables[2].Read(ref ControlData); - } - - public override void Write() - { - base.Write(); - _variables[3].Write(StatusData); - } - } -} diff --git a/Runtime/Scripts/Communication/Connector/ConnectorDataWord.cs.meta b/Runtime/Scripts/Communication/Connector/ConnectorDataWord.cs.meta deleted file mode 100644 index 200529e..0000000 --- a/Runtime/Scripts/Communication/Connector/ConnectorDataWord.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 71e2a854c79f47249046d517bbb9c3ad -timeCreated: 1719488182 \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Connector/ConnectorUtils.cs b/Runtime/Scripts/Communication/Connector/ConnectorUtils.cs deleted file mode 100644 index 1a02739..0000000 --- a/Runtime/Scripts/Communication/Connector/ConnectorUtils.cs +++ /dev/null @@ -1,50 +0,0 @@ -namespace OC.Communication -{ - public static class ConnectorUtils - { - public static void SetBit(ref this byte self, int index, bool value) - { - index = Clamp(index, 0, 7); - var mask = (byte)(1 << index); - self = (byte)(value ? (self | mask) : (self & ~mask)); - } - - public static void SetBit(ref this ushort self, int index, bool value) - { - index = Clamp(index, 0, 15); - var mask = (ushort)(1 << index); - self = (ushort)(value ? (self | mask) : (self & ~mask)); - } - - public static void SetBit(ref this uint self, int index, bool value) - { - index = Clamp(index, 0, 31); - var mask = (uint)(1 << index); - self = value ? (self | mask) : (self & ~mask); - } - - public static bool GetBit(this byte self, int index) - { - index = Clamp(index, 0, 7); - return (self & (1 << index)) != 0; - } - - public static bool GetBit(this ushort self, int index) - { - index = Clamp(index, 0, 15); - return (self & (1 << index)) != 0; - } - - public static bool GetBit(this uint self, int index) - { - index = Clamp(index, 0, 31); - return (self & (1 << index)) != 0; - } - - private static int Clamp(int value, int min, int max) - { - if (value < min) return min; - return value > max ? max : value; - } - } -} \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Connector/ConnectorUtils.cs.meta b/Runtime/Scripts/Communication/Connector/ConnectorUtils.cs.meta deleted file mode 100644 index 96402f1..0000000 --- a/Runtime/Scripts/Communication/Connector/ConnectorUtils.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 73efdb4460f743cf9c728f0151833f9c -timeCreated: 1692349287 \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Link/Hierarchy.cs b/Runtime/Scripts/Communication/Link/Hierarchy.cs index 89375b4..1e37d47 100644 --- a/Runtime/Scripts/Communication/Link/Hierarchy.cs +++ b/Runtime/Scripts/Communication/Link/Hierarchy.cs @@ -1,7 +1,3 @@ -#if UNITY_EDITOR - using UnityEditor; -#endif - using UnityEngine; namespace OC.Communication @@ -21,34 +17,7 @@ public class Hierarchy : MonoBehaviour private string GetName() { - if (string.IsNullOrEmpty(_name)) - { - if (!ClientVariableExtension.IsVariableNameValid(transform.name)) - { - var validName = ClientVariableExtension.CorrectVariableName(transform.name); -#if UNITY_EDITOR - Debug.LogWarning($"Hierarchy GameObject name {transform.name} is invalid! The name is modified to {validName}", this); - transform.name = validName; - EditorUtility.SetDirty(this); -#endif - } - - return transform.name; - } - else - { - if (!ClientVariableExtension.IsVariableNameValid(_name)) - { - var validCustomName = ClientVariableExtension.CorrectVariableName(_name); -#if UNITY_EDITOR - Debug.LogWarning($"Hierarchy name {_name} is invalid! The name is modified to {validCustomName}"); - _name = validCustomName; - EditorUtility.SetDirty(this); -#endif - } - - return _name; - } + return string.IsNullOrEmpty(_name) ? transform.name : _name; } public Transform GetParent() diff --git a/Runtime/Scripts/Communication/Link/IConnectable.cs b/Runtime/Scripts/Communication/Link/IConnectable.cs deleted file mode 100644 index 5a9ed81..0000000 --- a/Runtime/Scripts/Communication/Link/IConnectable.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace OC.Communication -{ - public interface IConnectable - { - public Link Link { get; } - } -} diff --git a/Runtime/Scripts/Communication/Link/IDevice.cs b/Runtime/Scripts/Communication/Link/IDevice.cs index 5797cfe..5123724 100644 --- a/Runtime/Scripts/Communication/Link/IDevice.cs +++ b/Runtime/Scripts/Communication/Link/IDevice.cs @@ -1,6 +1,8 @@ +using OC.Components; + namespace OC.Communication { - public interface IDevice : IComponent, IConnectable + public interface IDevice : IComponent, ILink, IOverride { } diff --git a/Runtime/Scripts/Communication/Link/ILink.cs b/Runtime/Scripts/Communication/Link/ILink.cs new file mode 100644 index 0000000..0d09871 --- /dev/null +++ b/Runtime/Scripts/Communication/Link/ILink.cs @@ -0,0 +1,7 @@ +namespace OC.Communication +{ + public interface ILink + { + public Link Link { get; } + } +} diff --git a/Runtime/Scripts/Communication/Link/IConnectable.cs.meta b/Runtime/Scripts/Communication/Link/ILink.cs.meta similarity index 100% rename from Runtime/Scripts/Communication/Link/IConnectable.cs.meta rename to Runtime/Scripts/Communication/Link/ILink.cs.meta diff --git a/Runtime/Scripts/Communication/Link/Link.cs b/Runtime/Scripts/Communication/Link/Link.cs index 6951bf1..0c300c2 100644 --- a/Runtime/Scripts/Communication/Link/Link.cs +++ b/Runtime/Scripts/Communication/Link/Link.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using UnityEngine; namespace OC.Communication @@ -13,8 +12,31 @@ public bool Enable get => _enable; set => _enable = value; } - public string Name => _name; - public string Path => _path; + + public string Name + { + get => _name; + set => _name = value; + } + + public string ScenePath + { + get => _scenePath; + set => _scenePath = value; + } + + public string ClientPath + { + get => _clientPath; + set => _clientPath = value; + } + + public Component Component + { + get => _component; + set => _component = value; + } + public Hierarchy Parent => _parent; public Client Client => _client; public string Type @@ -22,89 +44,77 @@ public string Type get => _type; set => _type = value; } - - public bool IsActive => _connected.Value && !_override.Value; public Property Connected => _connected; - public Property Override => _override; - public Component Component => _component; + + public List Attributes => _attributes; + + public byte Control; + public byte Status; [SerializeField] private bool _enable = true; [SerializeField] - private Property _override = new (false); - [SerializeField] private Property _connected = new (false); [SerializeField] - private string _type; + private string _name; + [SerializeField] + private string _scenePath; + [SerializeField] + private string _clientPath; + [SerializeField] + private string _type = "FB_Device"; [SerializeField] private Hierarchy _parent; [SerializeField] private List _attributes = new (); - - [HideInInspector, SerializeField] - private string _name; - [HideInInspector, SerializeField] - private string _path; private Component _component; private Client _client; - private List _connectors; + + [SerializeField] + protected List _variablesDescription = new(); + + protected List _variables = new(); - public Link(Component component, string type) + public Link() { - Initialize(component); - _type = type; + } - public Link(Component component, string name, string path) - { - _component = component; - _name = name; - _path = path; - _connectors = new List(); - } - - public Link(Component component) + public Link(string type) { - Initialize(component); + _type = type; } public void Initialize(Component component) { _component = component; _name = this.GetHierarchyName(); - _path = this.GetHierarchyPath(); - _client = this.GetClient(); - _connectors = new List(); - } - - public Link Reset(Component component) - { - Initialize(component); - return this; + _scenePath = this.GetHierarchyPath(); + _clientPath = _scenePath.GetClientCompatiblePath(); } public void Connect(Client client) { - if (client is null) return; - - _client = client; - if (!_enable) { _connected.Value = false; return; } - foreach (var connector in _connectors) + if (client is null) { - connector.Connect(client); + _connected.Value = false; + return; } - - _connected.Value = _connectors.All(connector => connector.IsConnected); + + _client = client; + + _variablesDescription = GetClientVariableDescriptions(); + _connected.Value = TryGetVariables(_variablesDescription, out _variables); } public void Disconnect() @@ -116,29 +126,62 @@ public void Read() { if (!_connected.Value) return; if (!_enable) return; - - // ReSharper disable once ForCanBeConvertedToForeach - for (var i = 0; i < _connectors.Count; i++) - { - _connectors[i].Read(); - } + ReadClientVariables(); } public void Write() { if (!_connected.Value) return; if (!_enable) return; + WriteClientVariables(); + } - // ReSharper disable once ForCanBeConvertedToForeach - for (var i = 0; i < _connectors.Count; i++) + protected virtual List GetClientVariableDescriptions() + { + var descriptions = new List { - _connectors[i].Write(); - } + new() { Path = ClientPath + ".Control", Direction = ClientVariableDirection.Input }, + new() { Path = ClientPath + ".Status", Direction = ClientVariableDirection.Output } + }; + return descriptions; + } + + protected virtual void ReadClientVariables() + { + _variables[0].Read(ref Control); } - public void Add(Connector connector) + protected virtual void WriteClientVariables() { - _connectors.Add(connector); + _variables[1].Write(Status); + } + + private bool TryGetVariables(IReadOnlyList variableDescriptions, out List variables) + { + var result = true; + variables = new List(); + + foreach (var description in variableDescriptions) + { + var variable = _client.GetClientVariable(description); + if (variable == null) + { + Logging.Logger.Log(LogType.Warning, $"{description.Path} can't be found in client!", Component); + result = false; + continue; + } + + if (variable.Reserved) + { + Logging.Logger.Log(LogType.Warning, $"{description.Path} already reserved!", Component); + result = false; + continue; + } + + variable.Reserved = true; + variables.Add(variable); + } + return result; } } } diff --git a/Runtime/Scripts/Communication/Link/LinkDataByte.cs b/Runtime/Scripts/Communication/Link/LinkDataByte.cs new file mode 100644 index 0000000..f9fb671 --- /dev/null +++ b/Runtime/Scripts/Communication/Link/LinkDataByte.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; + +namespace OC.Communication +{ + [Serializable] + public class LinkDataByte : Link + { + public byte ControlData; + public byte StatusData; + + public LinkDataByte(string type) : base(type){} + + protected override List GetClientVariableDescriptions() + { + var descriptions = new List + { + new() { Path = ClientPath + ".Control", Direction = ClientVariableDirection.Input }, + new() { Path = ClientPath + ".Status", Direction = ClientVariableDirection.Output }, + new() { Path = ClientPath + ".ControlData", Direction = ClientVariableDirection.Input }, + new() { Path = ClientPath + ".StatusData", Direction = ClientVariableDirection.Output } + }; + return descriptions; + } + + protected override void ReadClientVariables() + { + _variables[0].Read(ref Control); + _variables[2].Read(ref ControlData); + } + + protected override void WriteClientVariables() + { + _variables[1].Write(Status); + _variables[3].Write(StatusData); + } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Link/LinkDataByte.cs.meta b/Runtime/Scripts/Communication/Link/LinkDataByte.cs.meta new file mode 100644 index 0000000..994f579 --- /dev/null +++ b/Runtime/Scripts/Communication/Link/LinkDataByte.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8ee622a2d85a48d8afc7bd182f515645 +timeCreated: 1750685915 \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Link/LinkDataDWord.cs b/Runtime/Scripts/Communication/Link/LinkDataDWord.cs new file mode 100644 index 0000000..e6fdbf7 --- /dev/null +++ b/Runtime/Scripts/Communication/Link/LinkDataDWord.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; + +namespace OC.Communication +{ + [Serializable] + public class LinkDataDWord : Link + { + public uint ControlData; + public uint StatusData; + + public LinkDataDWord(string type) : base(type){} + + protected override List GetClientVariableDescriptions() + { + var descriptions = new List + { + new() { Path = ClientPath + ".Control", Direction = ClientVariableDirection.Input }, + new() { Path = ClientPath + ".Status", Direction = ClientVariableDirection.Output }, + new() { Path = ClientPath + ".ControlData", Direction = ClientVariableDirection.Input }, + new() { Path = ClientPath + ".StatusData", Direction = ClientVariableDirection.Output } + }; + return descriptions; + } + + protected override void ReadClientVariables() + { + _variables[0].Read(ref Control); + _variables[2].Read(ref ControlData); + } + + protected override void WriteClientVariables() + { + _variables[1].Write(Status); + _variables[3].Write(StatusData); + } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Link/LinkDataDWord.cs.meta b/Runtime/Scripts/Communication/Link/LinkDataDWord.cs.meta new file mode 100644 index 0000000..6090a32 --- /dev/null +++ b/Runtime/Scripts/Communication/Link/LinkDataDWord.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f1f7cae4951b47298c44b4e8edda9cee +timeCreated: 1750686293 \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Link/LinkDataFloat.cs b/Runtime/Scripts/Communication/Link/LinkDataFloat.cs new file mode 100644 index 0000000..8972eca --- /dev/null +++ b/Runtime/Scripts/Communication/Link/LinkDataFloat.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; + +namespace OC.Communication +{ + [Serializable] + public class LinkDataFloat : Link + { + public float ControlData; + public float StatusData; + + public LinkDataFloat(string type) : base(type){} + + protected override List GetClientVariableDescriptions() + { + var descriptions = new List + { + new() { Path = ClientPath + ".Control", Direction = ClientVariableDirection.Input }, + new() { Path = ClientPath + ".Status", Direction = ClientVariableDirection.Output }, + new() { Path = ClientPath + ".ControlData", Direction = ClientVariableDirection.Input }, + new() { Path = ClientPath + ".StatusData", Direction = ClientVariableDirection.Output } + }; + return descriptions; + } + + protected override void ReadClientVariables() + { + _variables[0].Read(ref Control); + _variables[2].Read(ref ControlData); + } + + protected override void WriteClientVariables() + { + _variables[1].Write(Status); + _variables[3].Write(ref StatusData); + } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Link/LinkDataFloat.cs.meta b/Runtime/Scripts/Communication/Link/LinkDataFloat.cs.meta new file mode 100644 index 0000000..aa1765d --- /dev/null +++ b/Runtime/Scripts/Communication/Link/LinkDataFloat.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b734cac8f552415996b87ca47ace562e +timeCreated: 1750686359 \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Link/LinkDataLWord.cs b/Runtime/Scripts/Communication/Link/LinkDataLWord.cs new file mode 100644 index 0000000..7cf3db3 --- /dev/null +++ b/Runtime/Scripts/Communication/Link/LinkDataLWord.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; + +namespace OC.Communication +{ + [Serializable] + public class LinkDataLWord : Link + { + public long ControlData; + public long StatusData; + + public LinkDataLWord(string type) : base(type){} + + protected override List GetClientVariableDescriptions() + { + var descriptions = new List + { + new() { Path = ClientPath + ".Control", Direction = ClientVariableDirection.Input }, + new() { Path = ClientPath + ".Status", Direction = ClientVariableDirection.Output }, + new() { Path = ClientPath + ".ControlData", Direction = ClientVariableDirection.Input }, + new() { Path = ClientPath + ".StatusData", Direction = ClientVariableDirection.Output } + }; + return descriptions; + } + + protected override void ReadClientVariables() + { + _variables[0].Read(ref Control); + _variables[2].Read(ref ControlData); + } + + protected override void WriteClientVariables() + { + _variables[1].Write(Status); + _variables[3].Write(StatusData); + } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Link/LinkDataLWord.cs.meta b/Runtime/Scripts/Communication/Link/LinkDataLWord.cs.meta new file mode 100644 index 0000000..a0211bb --- /dev/null +++ b/Runtime/Scripts/Communication/Link/LinkDataLWord.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: eed3d22910af44cfa49bbf13a4dfe40c +timeCreated: 1750686323 \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Link/LinkDataRobot.cs b/Runtime/Scripts/Communication/Link/LinkDataRobot.cs new file mode 100644 index 0000000..b5e8ee6 --- /dev/null +++ b/Runtime/Scripts/Communication/Link/LinkDataRobot.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; + +namespace OC.Communication +{ + [Serializable] + 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 + { + new() { Path = ClientPath + ".Control", Direction = ClientVariableDirection.Input }, + new() { Path = ClientPath + ".Status", Direction = ClientVariableDirection.Output }, + new() { Path = ClientPath + ".JointTarget", Direction = ClientVariableDirection.Input }, + new() { Path = ClientPath + ".JointStatus", Direction = ClientVariableDirection.Output } + }; + return descriptions; + } + + protected override void ReadClientVariables() + { + _variables[0].Read(ref Control); + _variables[2].Read(ref JointTarget); + } + + protected override void WriteClientVariables() + { + _variables[1].Write(Status); + _variables[3].Write(ref JointStatus); + } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Link/LinkDataRobot.cs.meta b/Runtime/Scripts/Communication/Link/LinkDataRobot.cs.meta new file mode 100644 index 0000000..1feed84 --- /dev/null +++ b/Runtime/Scripts/Communication/Link/LinkDataRobot.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0a44f1de796847c5b3d71b78683f21d1 +timeCreated: 1750686444 \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Link/LinkDataSystem.cs b/Runtime/Scripts/Communication/Link/LinkDataSystem.cs new file mode 100644 index 0000000..beee480 --- /dev/null +++ b/Runtime/Scripts/Communication/Link/LinkDataSystem.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; + +namespace OC.Communication +{ + [Serializable] + public class LinkDataSystem : Link + { + public float TimeScale; + + protected override List GetClientVariableDescriptions() + { + var descriptions = new List + { + new() { Path = ClientPath + ".Control", Direction = ClientVariableDirection.Input }, + new() { Path = ClientPath + ".Status", Direction = ClientVariableDirection.Output }, + new() { Path = ClientPath + ".TimeScaling", Direction = ClientVariableDirection.Output } + }; + return descriptions; + } + + protected override void ReadClientVariables() + { + _variables[0].Read(ref Control); + Status.SetBit(7, Control.GetBit(7)); + } + + protected override void WriteClientVariables() + { + _variables[1].Write(Status); + _variables[2].Write(ref TimeScale); + } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Link/LinkDataSystem.cs.meta b/Runtime/Scripts/Communication/Link/LinkDataSystem.cs.meta new file mode 100644 index 0000000..dae33c5 --- /dev/null +++ b/Runtime/Scripts/Communication/Link/LinkDataSystem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2f2c2b86440e4d2a85ea5354c6fca672 +timeCreated: 1750688923 \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Link/LinkDataWord.cs b/Runtime/Scripts/Communication/Link/LinkDataWord.cs new file mode 100644 index 0000000..4d0b6e6 --- /dev/null +++ b/Runtime/Scripts/Communication/Link/LinkDataWord.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; + +namespace OC.Communication +{ + [Serializable] + public class LinkDataWord : Link + { + public short ControlData; + public short StatusData; + + public LinkDataWord(string type) : base(type){} + + protected override List GetClientVariableDescriptions() + { + var descriptions = new List + { + new() { Path = ClientPath + ".Control", Direction = ClientVariableDirection.Input }, + new() { Path = ClientPath + ".Status", Direction = ClientVariableDirection.Output }, + new() { Path = ClientPath + ".ControlData", Direction = ClientVariableDirection.Input }, + new() { Path = ClientPath + ".StatusData", Direction = ClientVariableDirection.Output } + }; + return descriptions; + } + + protected override void ReadClientVariables() + { + _variables[0].Read(ref Control); + _variables[2].Read(ref ControlData); + } + + protected override void WriteClientVariables() + { + _variables[1].Write(Status); + _variables[3].Write(StatusData); + } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Link/LinkDataWord.cs.meta b/Runtime/Scripts/Communication/Link/LinkDataWord.cs.meta new file mode 100644 index 0000000..9489382 --- /dev/null +++ b/Runtime/Scripts/Communication/Link/LinkDataWord.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6973e303c61d441dad55593955eb648f +timeCreated: 1750686174 \ No newline at end of file diff --git a/Runtime/Scripts/Communication/Link/LinkExtension.cs b/Runtime/Scripts/Communication/Link/LinkExtension.cs index 83fac44..014fc3e 100644 --- a/Runtime/Scripts/Communication/Link/LinkExtension.cs +++ b/Runtime/Scripts/Communication/Link/LinkExtension.cs @@ -1,7 +1,4 @@ using UnityEngine; -#if UNITY_EDITOR -using UnityEditor; -#endif namespace OC.Communication { @@ -16,20 +13,7 @@ public static class LinkExtension /// The (original) name of the GameObject. Note that the GameObject’s name is modified in-editor if it was invalid. public static string GetName(this Link link) { - var name = link.Component.gameObject.name; - - if (!ClientVariableExtension.IsVariableNameValid(name)) - { - var oldName = name; - name = ClientVariableExtension.CorrectVariableName(name); -#if UNITY_EDITOR - Debug.LogWarning($"Link component name {oldName} is invalid! The name is modified to {name}", link.Component); - link.Component.gameObject.name = name; - EditorUtility.SetDirty(link.Component); -#endif - } - - return name; + return link.Component.gameObject.name; } /// @@ -170,5 +154,50 @@ public static Client GetClient(this Link link) return null; } + + public static void SetBit(ref this byte self, int index, bool value) + { + index = Clamp(index, 0, 7); + var mask = (byte)(1 << index); + self = (byte)(value ? (self | mask) : (self & ~mask)); + } + + public static void SetBit(ref this ushort self, int index, bool value) + { + index = Clamp(index, 0, 15); + var mask = (ushort)(1 << index); + self = (ushort)(value ? (self | mask) : (self & ~mask)); + } + + public static void SetBit(ref this uint self, int index, bool value) + { + index = Clamp(index, 0, 31); + var mask = (uint)(1 << index); + self = value ? (self | mask) : (self & ~mask); + } + + public static bool GetBit(this byte self, int index) + { + index = Clamp(index, 0, 7); + return (self & (1 << index)) != 0; + } + + public static bool GetBit(this ushort self, int index) + { + index = Clamp(index, 0, 15); + return (self & (1 << index)) != 0; + } + + public static bool GetBit(this uint self, int index) + { + index = Clamp(index, 0, 31); + return (self & (1 << index)) != 0; + } + + private static int Clamp(int value, int min, int max) + { + if (value < min) return min; + return value > max ? max : value; + } } } diff --git a/Runtime/Scripts/Components/Cylinder.cs b/Runtime/Scripts/Components/Cylinder.cs index 3eaf82a..fb06ede 100644 --- a/Runtime/Scripts/Components/Cylinder.cs +++ b/Runtime/Scripts/Components/Cylinder.cs @@ -10,25 +10,25 @@ namespace OC.Components [DisallowMultipleComponent] public class Cylinder : Actor, IDevice, ICustomInspector, IInteractable { - public Link Link => _link ?? CreateLink(); - - #region Control + public Link Link => _link; + public IProperty Override => _override; public IProperty Minus => _minus; public IProperty Plus => _plus; - [SerializeField] - 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; + public IProperty Limits => _limits; + public IProperty Type => _type; + public IProperty TimeToMin => _timeToMin; + public IProperty TimeToMax => _timeToMax; + [SerializeField] + protected Property _override = new (false); + [SerializeField] + protected Property _minus = new (false); + [SerializeField] + protected Property _plus = new (false); [SerializeField] protected Property _progress = new (0); [SerializeField] @@ -37,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] @@ -57,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; @@ -79,17 +63,13 @@ public bool JogPlus set => _plus.Value = value; get => _plus; } - - [SerializeField] - protected Link _link; + [SerializeField] - private Connector _connector; + protected Link _link = new() { Type = "FB_Cylinder" }; private void Start() { - _link = Link; _link.Initialize(this); - _connector = new Connector(_link); _progress.OnValueChanged += OnProgressChanged; _isActive.OnValueChanged += value => OnActiveChanged?.Invoke(value); _onLimitMin.OnValueChanged += value => OnLimitMinEvent?.Invoke(value); @@ -103,28 +83,24 @@ private void OnValidate() _plus.OnValidate(); } - private void Reset() - { - _link = CreateLink(); - } - private void FixedUpdate() { - if (_link.IsActive) GetLinkData(); + GetLinkData(); Operation(Time.fixedDeltaTime); SetLinkData(); } private void GetLinkData() { - _minus.Value = _connector.Control.GetBit(0); - _plus.Value = _connector.Control.GetBit(1); + if (_override || !_link.Connected) return; + _minus.Value = _link.Control.GetBit(0); + _plus.Value = _link.Control.GetBit(1); } private void SetLinkData() { - _connector.Status.SetBit(0, _onLimitMin); - _connector.Status.SetBit(1, _onLimitMax); + _link.Status.SetBit(0, _onLimitMin); + _link.Status.SetBit(1, _onLimitMax); } private void Operation(float deltaTime) @@ -169,11 +145,6 @@ private void OnProgressChanged(float value) _onLimitMax.Value = Math.FastApproximately(_value, _limits.Value.y, 1e-3f); SetLinkData(); } - - private Link CreateLink() - { - return new Link(this, "FB_Cylinder"); - } } } diff --git a/Runtime/Scripts/Components/Device.cs b/Runtime/Scripts/Components/Device.cs deleted file mode 100644 index e86f643..0000000 --- a/Runtime/Scripts/Components/Device.cs +++ /dev/null @@ -1,27 +0,0 @@ -using OC.Communication; -using UnityEngine; - -namespace OC.Components -{ - public abstract class Device : MonoComponent, IDevice - { - public Link Link => _link; - public Connector Connector => _connector; - public abstract int AllocatedBitLength { get; } - - [SerializeField] - protected Link _link; - private Connector _connector; - - protected void Start() - { - _link.Initialize(this); - _connector = new Connector(Link); - } - - protected virtual void Reset() - { - _link = new Link(this, "FB_Device"); - } - } -} diff --git a/Runtime/Scripts/Components/DeviceDWord.cs b/Runtime/Scripts/Components/DeviceDWord.cs deleted file mode 100644 index ff2790c..0000000 --- a/Runtime/Scripts/Components/DeviceDWord.cs +++ /dev/null @@ -1,28 +0,0 @@ -using OC.Communication; -using UnityEngine; - -namespace OC.Components -{ - [DefaultExecutionOrder(100)] - public abstract class DeviceDWord : MonoComponent, IDevice - { - public Link Link => _link; - public ConnectorDataDWord ConnectorData => _connectorData; - public abstract int AllocatedBitLength { get; } - - [SerializeField] - protected Link _link; - private ConnectorDataDWord _connectorData; - - protected void Start() - { - _link.Initialize(this); - _connectorData = new ConnectorDataDWord(Link); - } - - private void Reset() - { - _link = new Link(this, "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 0a22c05..0000000 --- a/Runtime/Scripts/Components/DeviceWord.cs +++ /dev/null @@ -1,28 +0,0 @@ -using OC.Communication; -using UnityEngine; - -namespace OC.Components -{ - [DefaultExecutionOrder(100)] - public abstract class DeviceWord : MonoComponent, IDevice - { - public Link Link => _link; - public ConnectorDataWord Connector => _connector; - public abstract int AllocatedBitLength { get; } - - [SerializeField] - protected Link _link; - private ConnectorDataWord _connector; - - protected void Start() - { - _link.Initialize(this); - _connector = new ConnectorDataWord(Link); - } - - private void Reset() - { - _link = new Link(this, "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 c733283..d9a96bf 100644 --- a/Runtime/Scripts/Components/Drive.cs +++ b/Runtime/Scripts/Components/Drive.cs @@ -10,9 +10,10 @@ namespace OC.Components [AddComponentMenu("Open Commissioning/Actor/Drive")] [SelectionBase] [DisallowMultipleComponent] - public abstract class Drive : Actor, IDeviceMetadata, ICustomInspector, IInteractable + public abstract class Drive : Actor, IDevice, IMetadataAsset, ICustomInspector, IInteractable { public Link Link => _link; + public IProperty Override => _override; public int MetadataAssetLength => 1; public IPropertyReadOnly IsActive => _stateObserver.IsActive; @@ -21,9 +22,9 @@ public abstract class Drive : Actor, IDeviceMetadata, ICustomInspector, IInterac public UnityEvent OnActiveChanged; [SerializeField] - protected Link _link; + protected Property _override = new (false); [SerializeField] - protected ConnectorDataFloat _connectorData; + protected LinkDataFloat _link = new("FB_Drive"); [HideInInspector] [SerializeField] protected DriveStateObserver _stateObserver = new (); @@ -31,18 +32,12 @@ public abstract class Drive : Actor, IDeviceMetadata, ICustomInspector, IInterac private void Start() { _link.Initialize(this); - _connectorData = new ConnectorDataFloat(_link); _stateObserver.IsActive.OnValueChanged += value => OnActiveChanged?.Invoke(value); } - - protected void Reset() - { - _link = new Link(this, "FB_Drive"); - } private void FixedUpdate() { - if (_link.IsActive) GetLinkData(); + if (!_override && _link.Connected) GetLinkData(); Operation(Time.fixedDeltaTime); SetLinkData(); } @@ -74,16 +69,16 @@ public void SetAsset(MetadataAsset asset) private IEnumerator InitializeCoroutine(float value) { _value.Value = value; - if (!_link.IsActive) + if (!_link.Connected) { Logging.Logger.Log(LogType.Warning, "Device initialization sequence is cancelled! Simulation unit communication isn't active!", this); yield break; } - _connectorData.Status.SetBit(7, true); - _connectorData.StatusData = value; + _link.Status.SetBit(7, true); + _link.StatusData = value; yield return new WaitForSeconds(1); - _connectorData.Status.SetBit(7, false); + _link.Status.SetBit(7, false); } public enum DriveState diff --git a/Runtime/Scripts/Components/DrivePosition.cs b/Runtime/Scripts/Components/DrivePosition.cs index c642041..1ef53db 100644 --- a/Runtime/Scripts/Components/DrivePosition.cs +++ b/Runtime/Scripts/Components/DrivePosition.cs @@ -16,7 +16,7 @@ public class DrivePosition : Drive protected override void GetLinkData() { - _target.Value = _connectorData.ControlData; + _target.Value = _link.ControlData; } protected override void Operation(float deltaTime) @@ -35,8 +35,8 @@ protected override void Operation(float deltaTime) protected override void SetLinkData() { - _connectorData.StatusData = _value.Value; - _connectorData.Status.SetBit(6, _stateObserver.IsActive.Value); + _link.StatusData = _value.Value; + _link.Status.SetBit(6, _stateObserver.IsActive.Value); } } } \ No newline at end of file diff --git a/Runtime/Scripts/Components/DriveSimple.cs b/Runtime/Scripts/Components/DriveSimple.cs index 3f3d413..a1e2218 100644 --- a/Runtime/Scripts/Components/DriveSimple.cs +++ b/Runtime/Scripts/Components/DriveSimple.cs @@ -33,8 +33,8 @@ public bool JogBackward protected override void GetLinkData() { - _forward.Value = _connectorData.Control.GetBit(0); - _backward.Value = _connectorData.Control.GetBit(1); + _forward.Value = _link.Control.GetBit(0); + _backward.Value = _link.Control.GetBit(1); } protected override void Operation(float deltaTime) diff --git a/Runtime/Scripts/Components/DriveSpeed.cs b/Runtime/Scripts/Components/DriveSpeed.cs index 07420f6..9c5a978 100644 --- a/Runtime/Scripts/Components/DriveSpeed.cs +++ b/Runtime/Scripts/Components/DriveSpeed.cs @@ -15,7 +15,7 @@ public class DriveSpeed : Drive protected override void GetLinkData() { - _target.Value = _connectorData.ControlData; + _target.Value = _link.ControlData; } protected override void Operation(float deltaTime) @@ -26,8 +26,8 @@ protected override void Operation(float deltaTime) protected override void SetLinkData() { - _connectorData.StatusData = _value.Value; - _connectorData.Status.SetBit(6, _stateObserver.IsActive.Value); + _link.StatusData = _value.Value; + _link.Status.SetBit(6, _stateObserver.IsActive.Value); } } } diff --git a/Runtime/Scripts/Components/IOverride.cs b/Runtime/Scripts/Components/IOverride.cs new file mode 100644 index 0000000..cc2aff7 --- /dev/null +++ b/Runtime/Scripts/Components/IOverride.cs @@ -0,0 +1,7 @@ +namespace OC.Components +{ + public interface IOverride + { + public IProperty Override { get; } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/Components/IOverride.cs.meta b/Runtime/Scripts/Components/IOverride.cs.meta new file mode 100644 index 0000000..210c202 --- /dev/null +++ b/Runtime/Scripts/Components/IOverride.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: eab7505076ed419588d2c69d6fa402ee +timeCreated: 1751011207 \ No newline at end of file diff --git a/Runtime/Scripts/Components/IPropertyForce.cs b/Runtime/Scripts/Components/IPropertyForce.cs deleted file mode 100644 index 1e22295..0000000 --- a/Runtime/Scripts/Components/IPropertyForce.cs +++ /dev/null @@ -1,9 +0,0 @@ -using OC.Communication; - -namespace OC.Components -{ - public interface IPropertyForce: IConnectable - { - public IProperty Force { get; } - } -} diff --git a/Runtime/Scripts/Components/IPropertyForce.cs.meta b/Runtime/Scripts/Components/IPropertyForce.cs.meta deleted file mode 100644 index d606d33..0000000 --- a/Runtime/Scripts/Components/IPropertyForce.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: eb753080943fcc94ebe6bb7f1a76df66 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Scripts/Components/LinkByte.cs b/Runtime/Scripts/Components/LinkByte.cs index 7c97403..eab253c 100644 --- a/Runtime/Scripts/Components/LinkByte.cs +++ b/Runtime/Scripts/Components/LinkByte.cs @@ -6,12 +6,17 @@ namespace OC.Components { + [SelectionBase] + [DisallowMultipleComponent] [AddComponentMenu("Open Commissioning/Links/Link Byte")] public class LinkByte : MonoComponent, IDevice { public Link Link => _link; - public ConnectorDataByte ConnectorData => _connectorData; + public IProperty Override => _override; + [SerializeField] + protected Property _override = new (false); + [ReadOnly] [SerializeField] private byte _value; @@ -27,80 +32,73 @@ public class LinkByte : MonoComponent, IDevice public UnityEvent OnBit7Changed; [SerializeField] - private Link _link; - private ConnectorDataByte _connectorData; + private LinkDataByte _link = new("FB_DeviceByte"); private void Start() { Link.Initialize(this); - _connectorData = new ConnectorDataByte(Link); } - private void Reset() - { - _link = new Link(this, "FB_DeviceByte"); - } - private void Update() { - if (!_link.IsActive) return; - if (_connectorData.ControlData == _value) return; + if (!_link.Connected) return; + if (_link.ControlData == _value) return; - _value = _connectorData.ControlData; - OnBit0Changed.Invoke(_connectorData.ControlData.GetBit(0)); - OnBit1Changed.Invoke(_connectorData.ControlData.GetBit(1)); - OnBit2Changed.Invoke(_connectorData.ControlData.GetBit(2)); - OnBit3Changed.Invoke(_connectorData.ControlData.GetBit(3)); - OnBit4Changed.Invoke(_connectorData.ControlData.GetBit(4)); - OnBit5Changed.Invoke(_connectorData.ControlData.GetBit(5)); - OnBit6Changed.Invoke(_connectorData.ControlData.GetBit(6)); - OnBit7Changed.Invoke(_connectorData.ControlData.GetBit(7)); + _value = _link.ControlData; + OnBit0Changed.Invoke(_link.ControlData.GetBit(0)); + OnBit1Changed.Invoke(_link.ControlData.GetBit(1)); + OnBit2Changed.Invoke(_link.ControlData.GetBit(2)); + OnBit3Changed.Invoke(_link.ControlData.GetBit(3)); + OnBit4Changed.Invoke(_link.ControlData.GetBit(4)); + OnBit5Changed.Invoke(_link.ControlData.GetBit(5)); + OnBit6Changed.Invoke(_link.ControlData.GetBit(6)); + OnBit7Changed.Invoke(_link.ControlData.GetBit(7)); } public void SetDataBit(int index, bool value) { if (index is < 0 or > 7) throw new ArgumentOutOfRangeException(nameof(index)); - _connectorData.StatusData.SetBit(index, value); + _link.StatusData.SetBit(index, value); } public void SetDataBit0(bool value) { - _connectorData.StatusData.SetBit(0, value); + _link.StatusData.SetBit(0, value); } public void SetDataBit1(bool value) { - _connectorData.StatusData.SetBit(1, value); + _link.StatusData.SetBit(1, value); } public void SetDataBit2(bool value) { - _connectorData.StatusData.SetBit(2, value); + _link.StatusData.SetBit(2, value); } public void SetDataBit3(bool value) { - _connectorData.StatusData.SetBit(3, value); + _link.StatusData.SetBit(3, value); } public void SetDataBit4(bool value) { - _connectorData.StatusData.SetBit(4, value); + _link.StatusData.SetBit(4, value); } public void SetDataBit5(bool value) { - _connectorData.StatusData.SetBit(5, value); + _link.StatusData.SetBit(5, value); } public void SetDataBit6(bool value) { - _connectorData.StatusData.SetBit(6, value); + _link.StatusData.SetBit(6, value); } public void SetDataBit7(bool value) { - _connectorData.StatusData.SetBit(7, value); + _link.StatusData.SetBit(7, value); } } } diff --git a/Runtime/Scripts/Components/MeasurementEncoder.cs b/Runtime/Scripts/Components/MeasurementEncoder.cs index 01bb647..6e109a9 100644 --- a/Runtime/Scripts/Components/MeasurementEncoder.cs +++ b/Runtime/Scripts/Components/MeasurementEncoder.cs @@ -3,6 +3,8 @@ namespace OC.Components { + [SelectionBase] + [DisallowMultipleComponent] public class MeasurementEncoder : MonoBehaviour, IMeasurement { public IPropertyReadOnly Value => _value; diff --git a/Runtime/Scripts/Components/Robot6R.cs b/Runtime/Scripts/Components/Robot6R.cs index 9080e5d..7f94b60 100644 --- a/Runtime/Scripts/Components/Robot6R.cs +++ b/Runtime/Scripts/Components/Robot6R.cs @@ -4,10 +4,13 @@ namespace OC.Components { + [SelectionBase] + [DisallowMultipleComponent] [AddComponentMenu("Open Commissioning/Actor/Robot 6R")] public class Robot6R : MonoComponent, IDevice { public Link Link => _link; + public IProperty Override => _override; public float[] Target => _target; [Header("Control")] @@ -25,26 +28,20 @@ public class Robot6R : MonoComponent, IDevice private List _axes; [SerializeField] - private Link _link; + protected Property _override = new (false); [SerializeField] - private ConnectorDataRobot _connector; + private LinkDataRobot _link = new("FB_Robot"); private readonly float[] _value = new float[12]; private void Start() { _link.Initialize(this); - _connector = new ConnectorDataRobot(_link); - } - - private void Reset() - { - _link = new Link(this, "FB_Robot"); } private void FixedUpdate() { - if (_link.IsActive) _connector.JointTarget.CopyTo(_value, 0); + if (_link.Connected) _link.JointTarget.CopyTo(_value, 0); for (var i = 0; i < _value.Length; i++) { 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 2b5203c..0cc43ff 100644 --- a/Runtime/Scripts/Components/SensorAnalog.cs +++ b/Runtime/Scripts/Components/SensorAnalog.cs @@ -26,10 +26,9 @@ public class SensorAnalog : MonoComponent, IDevice, ICustomInspector, IInteracta public UnityEvent OnValueChangedEvent; [SerializeField] - private Link _link; + private LinkDataFloat _link = new("FB_SensorAnalog"); private bool _isDeviceValid; - private ConnectorDataFloat _connector; private IMeasurement _measurementDevice; private void OnEnable() @@ -45,16 +44,10 @@ private void OnDisable() private void Start() { _link.Initialize(this); - _connector = new ConnectorDataFloat(_link); GetValueSource(); OnValueChanged(_value.Value); } - private void Reset() - { - _link = new Link(this, "FB_SensorAnalog"); - } - public void OnValidate() { _value.OnValidate(); @@ -87,7 +80,7 @@ private void OnDeviceValueChanged(float value) private void OnValueChanged(float value) { - _connector.StatusData = _value.Value; + _link.StatusData = _value.Value; OnValueChangedEvent?.Invoke(_value.Value); } } diff --git a/Runtime/Scripts/Components/SensorBinary.cs b/Runtime/Scripts/Components/SensorBinary.cs index ab54a4e..20a43a3 100644 --- a/Runtime/Scripts/Components/SensorBinary.cs +++ b/Runtime/Scripts/Components/SensorBinary.cs @@ -17,6 +17,12 @@ public class SensorBinary : Detector, IDevice, IMeasurement, ISensorBeam, public IPropertyReadOnly Value => _value; public IProperty State => _state; public IPropertyReadOnly Length => _length; + + public bool Invert + { + get => _invert; + set => _invert = value; + } [SerializeField] protected Property _override = new (false); @@ -34,7 +40,6 @@ public class SensorBinary : Detector, IDevice, IMeasurement, ISensorBeam, public UnityEvent OnValueChangedEvent; private const float DIAMETER = 0.004f; - private Connector _connector; private BoxCollider _collider; private Rigidbody _rigidbody; @@ -45,32 +50,37 @@ public class SensorBinary : Detector, IDevice, IMeasurement, ISensorBeam, private new void OnEnable() { base.OnEnable(); - _state.OnValueChanged += OnStateChanged; - _value.OnValueChanged += OnValueChanged; + _state.Subscribe(OnStateChanged); + _value.Subscribe(OnValueChanged); + //_state.OnValueChanged += OnStateChanged; + //_value.OnValueChanged += OnValueChanged; } private new void OnDisable() { base.OnDisable(); - _state.OnValueChanged -= OnStateChanged; - _value.OnValueChanged -= OnValueChanged; + _state.Unsubscribe(OnStateChanged); + _value.Unsubscribe(OnValueChanged); + //_state.OnValueChanged -= OnStateChanged; + //_value.OnValueChanged -= OnValueChanged; } private void Start() { - _link.Initialize(this); - _connector = new Connector(_link); + Link.Initialize(this); Initialize(); } - private void Reset() + public void Reset() { - _link = new Link(this, "FB_SensorBinary"); + _link = new Link + { + Type = "FB_SensorBinary" + }; } - private new void OnValidate() + private void OnValidate() { - base.OnValidate(); Initialize(); OnStateChanged(_state.Value); _length.OnValidate(); @@ -99,7 +109,7 @@ private void OnStateChanged(bool value) private void OnValueChanged(bool value) { - _connector.Status.SetBit(0, value); + Link.Status.SetBit(0, value); OnValueChangedEvent?.Invoke(value); } diff --git a/Runtime/Scripts/Components/SignalBinary.cs b/Runtime/Scripts/Components/SignalBinary.cs index a80b893..82bb20b 100644 --- a/Runtime/Scripts/Components/SignalBinary.cs +++ b/Runtime/Scripts/Components/SignalBinary.cs @@ -26,8 +26,7 @@ public class SignalBinary : MonoComponent, IDevice, IMeasurement, ICustomI private Component _device; [SerializeField] private Link _link; - - private Connector _connector; + private bool _isMeasurementDeviceValid; private IMeasurement _measurementDevice; @@ -46,14 +45,16 @@ private void OnDisable() private void Start() { _link.Initialize(this); - _connector = new Connector(_link); GetMeasurementDevice(); OnValueChanged(_value.Value); } - private void Reset() + public void Reset() { - _link = new Link(this, "FB_SensorBinary"); + _link = new Link + { + Type = "FB_SensorBinary" + }; } private void OnSignalChanged(bool value) @@ -63,7 +64,7 @@ private void OnSignalChanged(bool value) private void OnValueChanged(bool value) { - _connector.Status.SetBit(0, value); + _link.Status.SetBit(0, value); OnValueChangedEvent?.Invoke(value); } diff --git a/Runtime/Scripts/Components/TagReader.cs b/Runtime/Scripts/Components/TagReader.cs index 5220bae..58739d0 100644 --- a/Runtime/Scripts/Components/TagReader.cs +++ b/Runtime/Scripts/Components/TagReader.cs @@ -20,15 +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 Link _link; - private ConnectorDataLWord _connectorData; + private LinkDataLWord _link = new("FB_Reader"); + + public UnityEvent OnValueChangedEvent; private BoxCollider _collider; private Rigidbody _rigidbody; @@ -53,15 +50,9 @@ private void Awake() private void Start() { _link.Initialize(this); - _connectorData = new ConnectorDataLWord(_link); Initialize(); } - private void Reset() - { - _link = new Link(this, "FB_Reader"); - } - protected override void OnPayloadEnterAction(PayloadBase payloadBase) { if (payloadBase is not Payload payload) return; @@ -82,7 +73,7 @@ protected override void OnPayloadExitAction(PayloadBase payloadBase) private void OnValueChanged(ulong value) { OnValueChangedEvent?.Invoke(value); - _connectorData.StatusData = (long)value; + _link.StatusData = (long)value; } private void Initialize() diff --git a/Runtime/Scripts/Components/Transport.cs b/Runtime/Scripts/Components/Transport.cs index d6d43a1..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] @@ -80,7 +79,7 @@ private void FixedUpdate() MoveSurface(_value.Value); } - protected void Reset() + public void Reset() { gameObject.layer = LayerMask.NameToLayer("Transport"); OnValidate(); 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/Data/DictionaryItem.cs b/Runtime/Scripts/Data/DictionaryItem.cs index 0175576..2c327a4 100644 --- a/Runtime/Scripts/Data/DictionaryItem.cs +++ b/Runtime/Scripts/Data/DictionaryItem.cs @@ -31,8 +31,8 @@ public DictionaryItem(string key, string value) public void Set(DictionaryItem other) { - _key = other._key; - _value = other._value; + _key = other.Key; + _value = other.Value; } } } \ No newline at end of file diff --git a/Runtime/Scripts/Data/ProductDataFactory.cs b/Runtime/Scripts/Data/ProductDataFactory.cs index 73ccba7..b7aa480 100644 --- a/Runtime/Scripts/Data/ProductDataFactory.cs +++ b/Runtime/Scripts/Data/ProductDataFactory.cs @@ -21,7 +21,7 @@ public static void CreateProductData(this PayloadTag payloadTag, Dictionary _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,11 +72,6 @@ private void OnValidate() } } - protected override void Reset() - { - _link = new Link(this, "FB_Button"); - } - public void Click() { if (!Application.isPlaying) return; @@ -110,12 +108,12 @@ public void Release() private void LateUpdate() { - if (!_localFeedback) _feedback.Value = Connector.Control.GetBit(0); + if (!_localFeedback) _feedback.Value = _link.Control.GetBit(0); } private void PressedOnOnValueChanged(bool value) { - Connector.Status.SetBit(0, value); + _link.Status.SetBit(0, value); OnPressedChanged?.Invoke(value); if (value) OnClickEvent?.Invoke(); if (_localFeedback) _feedback.Value = value; diff --git a/Runtime/Scripts/Interactions/Interaction.cs b/Runtime/Scripts/Interactions/Interaction.cs index df93b5e..3a1c500 100644 --- a/Runtime/Scripts/Interactions/Interaction.cs +++ b/Runtime/Scripts/Interactions/Interaction.cs @@ -61,7 +61,7 @@ protected void OnDestroy() OnDestroyAction?.Invoke(); } - private void Reset() + public void Reset() { BoundBoxColliderSize(); gameObject.layer = (int)DefaultLayers.Interactions; diff --git a/Runtime/Scripts/Interactions/Lamp.cs b/Runtime/Scripts/Interactions/Lamp.cs index 902e445..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; @@ -18,24 +20,24 @@ public bool Signal } public override int AllocatedBitLength => 1; - public IProperty Override => _override; public IProperty Value => _value; public IPropertyReadOnly Color => _color; - - [SerializeField] - protected Property _override = new(false); + [SerializeField] private Property _value = new(false); [SerializeField] 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; } @@ -44,14 +46,9 @@ private void OnDestroy() _value.OnValueChanged -= OnOnValueChangedAction; } - protected override void Reset() - { - _link = new Link(this, "FB_Lamp"); - } - private void LateUpdate() { - if (!_override) _value.Value = Connector.Control.GetBit(0); + if (!_override && _link.Connected) _value.Value = _link.Control.GetBit(0); } private void OnValidate() diff --git a/Runtime/Scripts/Interactions/Lock.cs b/Runtime/Scripts/Interactions/Lock.cs index 168a9ea..473eb5f 100644 --- a/Runtime/Scripts/Interactions/Lock.cs +++ b/Runtime/Scripts/Interactions/Lock.cs @@ -30,19 +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 Link _link; - private ConnectorDataByte _connector; - - private bool _lastClosed; - private bool _lastLock; - private bool _isValid; + protected LinkDataByte _link = new ("FB_Lock"); private void OnEnable() { @@ -61,12 +56,6 @@ private void OnDisable() protected void Start() { _link.Initialize(this); - _connector = new ConnectorDataByte(Link); - } - - protected void Reset() - { - _link = new Link(this, "FB_Lock"); } private void OnValidate() @@ -110,7 +99,7 @@ private void LockedCallback(bool value) private void LateUpdate() { - if (_link.IsActive) _lock.Value = _connector.Control.GetBit(0); + if (!_override && _link.Connected) _lock.Value = _link.Control.GetBit(0); UpdateButtons(); if (_doors.Count > 0) @@ -119,8 +108,8 @@ private void LateUpdate() _locked.Value = _doors.All(door => door.Locked.Value); } - _connector.Status.SetBit(0, _closed); - _connector.Status.SetBit(1, _locked); + _link.Status.SetBit(0, _closed); + _link.Status.SetBit(1, _locked); } private void UpdateButtons() @@ -130,8 +119,8 @@ private void UpdateButtons() { for (var j = 0; j < item.AllocatedBitLength; j++) { - _connector.StatusData.SetBit(index,item.Connector.Status.GetBit(j)); - item.Connector.Control.SetBit(j,_connector.ControlData.GetBit(index)); + _link.StatusData.SetBit(index, item.Link.Status.GetBit(j)); + item.Link.Control.SetBit(j,_link.ControlData.GetBit(index)); index++; } } diff --git a/Runtime/Scripts/Interactions/PanelSampler.cs b/Runtime/Scripts/Interactions/PanelSampler.cs index 44122ab..d3e8eec 100644 --- a/Runtime/Scripts/Interactions/PanelSampler.cs +++ b/Runtime/Scripts/Interactions/PanelSampler.cs @@ -13,30 +13,28 @@ namespace OC.Interactions public class PanelSampler : MonoComponent, IIndustrialPanel, ICustomInspector { public Link Link => _link; - public List Components => _components; + public IProperty Override => _override; + public List Components => _components; [SerializeField] private string _name; [SerializeField] - private List _components = new (); + private List _components = new (); [SerializeField] - private Link _link; - - private ConnectorDataDWord _connectorDataDWord; + protected Property _override = new (false); + [SerializeField] + private LinkDataDWord _link = new("FB_Panel"); + private int _bitLength; - private int _bitLengthMax; private bool _isValid; + + private const int BIT_LENGTH_MAX = 32; private void Start() { - InitializeLink(); + _link.Initialize(this); CheckSlots(); } - - private void Reset() - { - _link = new Link(this, "FB_Panel"); - } private void LateUpdate() { @@ -48,8 +46,8 @@ private void LateUpdate() { for (var j = 0; j < item.AllocatedBitLength; j++) { - _connectorDataDWord.StatusData.SetBit(index,item.Connector.Status.GetBit(j)); - item.Connector.Control.SetBit(j,_connectorDataDWord.ControlData.GetBit(index)); + _link.StatusData.SetBit(index, item.Link.Status.GetBit(j)); + item.Link.Control.SetBit(j, _link.ControlData.GetBit(index)); index++; } } @@ -73,9 +71,9 @@ private void CheckSlots() if (_components.Count <= 0) return; _bitLength = _components.Sum(item => item.AllocatedBitLength); - if (_bitLength > _bitLengthMax) + if (_bitLength > BIT_LENGTH_MAX) { - Logging.Logger.Log(LogType.Error, $"Interface length {_bitLength} [bit] is out of the range [0..{_bitLengthMax}]!", this); + Logging.Logger.Log(LogType.Error, $"Interface length {_bitLength} [bit] is out of the range [0..{BIT_LENGTH_MAX}]!", this); return; } @@ -89,12 +87,5 @@ private void CheckSlots() Logging.Logger.Log(LogType.Warning, $"Panel {name} override {device.name} link state to disable", device); } } - - private void InitializeLink() - { - _link.Initialize(this); - _connectorDataDWord = new ConnectorDataDWord(_link); - _bitLengthMax = sizeof(uint) * 8; - } } } diff --git a/Runtime/Scripts/Interactions/Switch.cs b/Runtime/Scripts/Interactions/Switch.cs index 874ecab..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,11 +38,6 @@ protected void OnDisable() { _index.OnValueChanged -= IndexChanged; } - - protected override void Reset() - { - _link = new Link(this, "FB_Switch"); - } protected void OnValidate() { @@ -42,7 +47,7 @@ protected void OnValidate() private void IndexChanged(int index) { index %= _stateCount; - Connector.Status = index > 0 ? (byte)Mathf.Pow(2, index - 1) : (byte)0; + Link.Status = index > 0 ? (byte)Mathf.Pow(2, index - 1) : (byte)0; OnIndexChanged?.Invoke(index); } 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/Runtime/Scripts/MaterialFlow/CollisionDetector.cs b/Runtime/Scripts/MaterialFlow/CollisionDetector.cs deleted file mode 100644 index 49c5a2d..0000000 --- a/Runtime/Scripts/MaterialFlow/CollisionDetector.cs +++ /dev/null @@ -1,162 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; -using Object = UnityEngine.Object; - -namespace OC.MaterialFlow -{ - [Serializable] - public class CollisionDetector - { - public CollisionFilter Filter - { - get => _filter; - set => _filter = value; - } - - public int GroupId - { - get => _groupId; - set => _groupId = value; - } - - public List Buffer => _buffer; - - public Property Collision => _collision; - - [SerializeField] - private CollisionFilter _filter; - [SerializeField] - private int _groupId; - - private Property _collision = new (false); - private List _buffer = new (); - - public Action PayloadEnterAction; - public Action PayloadExitAction; - - public CollisionDetector(){} - - public CollisionDetector(CollisionFilter filter, int groupId) - { - _filter = filter; - _groupId = groupId; - } - - public bool Add(GameObject gameObject) - { - return gameObject.TryGetComponent(out PayloadBase payloadObject) && Add(payloadObject); - } - - public bool Add(PayloadBase payloadBase) - { - if (!IsTypeValid(payloadBase, _filter)) return false; - if (!IsGroupValid(payloadBase.GroupId, _groupId)) return false; - if (_buffer.Contains(payloadBase)) return false; - - payloadBase.OnDestroyAction += () => Remove(payloadBase); - payloadBase.OnDisableAction += () => Remove(payloadBase); - _buffer.Add(payloadBase); - - PayloadEnterAction?.Invoke(payloadBase); - Refresh(); - return true; - } - - public bool Remove(PayloadBase payloadBase) - { - if (!IsTypeValid(payloadBase, _filter) || !IsGroupValid(payloadBase.GroupId, _groupId)) return false; - if (!_buffer.Contains(payloadBase)) return false; - _buffer.Remove(payloadBase); - PayloadExitAction?.Invoke(payloadBase); - Refresh(); - return true; - } - - public bool Remove(GameObject gameObject) - { - return gameObject.TryGetComponent(out PayloadBase payloadObject) && Remove(payloadObject); - } - - public void ClearAll() - { - _buffer.Clear(); - Refresh(); - } - - public void DestroyAll() - { - var destroyList = new List(_buffer); - - foreach (var payload in destroyList) - { - if (!Application.isPlaying) - { - Object.DestroyImmediate(payload.gameObject); - } - else - { - Object.Destroy(payload.gameObject); - } - } - ClearAll(); - } - - public static bool IsTypeValid(PayloadBase payloadBase, CollisionFilter filter) - { - return payloadBase switch - { - PayloadStorage => filter.HasFlag(CollisionFilter.Storage), - StaticCollider => filter.HasFlag(CollisionFilter.Static), - Payload payload => ((int)filter & 2.Pow((int)payload.Category)) != 0, - _ => false - }; - } - - public static bool IsGroupValid(int groupId, int requiredGroupId) - { - if (requiredGroupId == 0) return true; - return requiredGroupId == groupId; - } - - private void Refresh() - { - _collision.Value = _buffer.Count > 0; - } - - public PayloadStorage GetLastPayloadStorage() - { - for (var i = _buffer.Count - 1; i >= 0; i--) - { - if (_buffer[i] is not PayloadStorage e) continue; - return e; - } - return null; - } - - public Payload GetLastByType(Payload.PayloadCategory type) - { - for (var i = _buffer.Count - 1; i >= 0; i--) - { - if (_buffer[i] is not Payload e) continue; - if (e.Category == type) - { - return e; - } - } - return null; - } - } - - [Flags] - public enum CollisionFilter - { - None = 0, - Part = 1, - Assembly = 2, - Transport = 4, - Static = 8, - Storage = 16, - All = ~0 - } -} diff --git a/Runtime/Scripts/MaterialFlow/CollisionDetector.cs.meta b/Runtime/Scripts/MaterialFlow/CollisionDetector.cs.meta deleted file mode 100644 index 18ff372..0000000 --- a/Runtime/Scripts/MaterialFlow/CollisionDetector.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 50228e3caee470d45837ed2a79ec7124 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Scripts/MaterialFlow/CollisionFilter.cs b/Runtime/Scripts/MaterialFlow/CollisionFilter.cs new file mode 100644 index 0000000..ea1cccf --- /dev/null +++ b/Runtime/Scripts/MaterialFlow/CollisionFilter.cs @@ -0,0 +1,16 @@ +using System; + +namespace OC.MaterialFlow +{ + [Flags] + public enum CollisionFilter + { + None = 0, + Part = 1, + Assembly = 2, + Transport = 4, + Static = 8, + Storage = 16, + All = ~0 + } +} \ No newline at end of file diff --git a/Runtime/Scripts/MaterialFlow/CollisionFilter.cs.meta b/Runtime/Scripts/MaterialFlow/CollisionFilter.cs.meta new file mode 100644 index 0000000..d90ab07 --- /dev/null +++ b/Runtime/Scripts/MaterialFlow/CollisionFilter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b8d9521731444dc589d3dbe97047b2d6 +timeCreated: 1750774554 \ No newline at end of file diff --git a/Runtime/Scripts/MaterialFlow/Detector.cs b/Runtime/Scripts/MaterialFlow/Detector.cs index 09a3c8e..6a8ad4e 100644 --- a/Runtime/Scripts/MaterialFlow/Detector.cs +++ b/Runtime/Scripts/MaterialFlow/Detector.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using OC.Components; using UnityEngine; @@ -6,58 +7,57 @@ namespace OC.MaterialFlow { [DisallowMultipleComponent] - public abstract class Detector : MonoComponent + public class Detector : MonoComponent { - public IPropertyReadOnly Collision => _collision; + public IProperty Collision => _collision; + + public IList CollisionBuffer => _collisionBuffer; + + public CollisionFilter CollisionFilter + { + get => _collisionFilter; + set => _collisionFilter = value; + } + + public int GroupId + { + get => _groupId; + set => _groupId = value; + } [SerializeField] protected Property _collision = new (false); - [SerializeField] protected int _groupId; [SerializeField] protected CollisionFilter _collisionFilter = CollisionFilter.All; - protected readonly CollisionDetector _collisionDetector = new(CollisionFilter.All, 0); - + private readonly List _collisionBuffer = new (); + public UnityEvent OnCollisionEvent; public UnityEvent OnPayloadEnterEvent; public UnityEvent OnPayloadExitEvent; - + public Action PayloadEnterAction; + public Action PayloadExitAction; + protected void OnEnable() { - _collisionDetector.Filter = _collisionFilter; - _collisionDetector.GroupId = _groupId; - _collisionDetector.Collision.OnValueChanged += OnCollisionChangedAction; - _collisionDetector.PayloadEnterAction += OnPayloadEnterAction; - _collisionDetector.PayloadExitAction += OnPayloadExitAction; + _collision.OnValueChanged += OnCollisionChangedAction; } - + protected void OnDisable() { - _collisionDetector.Collision.OnValueChanged -= OnCollisionChangedAction; - _collisionDetector.PayloadEnterAction -= OnPayloadEnterAction; - _collisionDetector.PayloadExitAction -= OnPayloadExitAction; + _collision.OnValueChanged -= OnCollisionChangedAction; } - - protected void OnValidate() - { - _collisionDetector.Filter = _collisionFilter; - _collisionDetector.GroupId = _groupId; - } - + protected void OnTriggerEnter(Collider other) { - _collisionDetector.Add(other.attachedRigidbody == null - ? other.gameObject - : other.attachedRigidbody.gameObject); + Add(other.attachedRigidbody == null ? other.gameObject : other.attachedRigidbody.gameObject); } protected void OnTriggerExit(Collider other) { - _collisionDetector.Remove(other.attachedRigidbody == null - ? other.gameObject - : other.attachedRigidbody.gameObject); + Remove(other.attachedRigidbody == null ? other.gameObject : other.attachedRigidbody.gameObject); } protected virtual void OnCollisionChangedAction(bool value) @@ -66,17 +66,7 @@ protected virtual void OnCollisionChangedAction(bool value) OnCollisionEvent?.Invoke(value); } - protected virtual void OnPayloadEnterAction(PayloadBase payloadBase) - { - OnPayloadEnterEvent?.Invoke(payloadBase); - } - - protected virtual void OnPayloadExitAction(PayloadBase payloadBase) - { - OnPayloadExitEvent?.Invoke(payloadBase); - } - - public static readonly List Filter = new List() + public static readonly List Filter = new () { "Part", "Assembly", @@ -90,5 +80,84 @@ public void BoundBoxColliderSize() { Utils.TryBoundBoxColliderSize(gameObject, out _); } + + public void Add(GameObject target) + { + if (target.TryGetComponent(out PayloadBase payloadObject)) + { + Add(payloadObject); + } + } + + public void Add(PayloadBase payloadBase) + { + if (!PayloadUtils.IsTypeValid(payloadBase, _collisionFilter)) return; + if (!PayloadUtils.IsGroupValid(payloadBase.GroupId, _groupId)) return; + if (_collisionBuffer.Contains(payloadBase)) return; + + payloadBase.OnDestroyAction += () => Remove(payloadBase); + payloadBase.OnDisableAction += () => Remove(payloadBase); + _collisionBuffer.Add(payloadBase); + OnPayloadEnterAction(payloadBase); + Refresh(); + } + + public void Remove(GameObject target) + { + if (target.TryGetComponent(out PayloadBase payloadObject)) + { + Remove(payloadObject); + } + } + + public void Remove(PayloadBase payloadBase) + { + if (!PayloadUtils.IsTypeValid(payloadBase, _collisionFilter) || !PayloadUtils.IsGroupValid(payloadBase.GroupId, _groupId)) return; + if (!_collisionBuffer.Contains(payloadBase)) return; + _collisionBuffer.Remove(payloadBase); + OnPayloadExitAction(payloadBase); + Refresh(); + } + + public void ClearAll() + { + _collisionBuffer.Clear(); + Refresh(); + } + + public void DestroyAll() + { + var destroyList = new List(_collisionBuffer); + + foreach (var payload in destroyList) + { + if (!Application.isPlaying) + { + DestroyImmediate(payload.gameObject); + } + else + { + Destroy(payload.gameObject); + } + } + ClearAll(); + } + + protected virtual void OnPayloadEnterAction(PayloadBase payloadBase) + { + PayloadEnterAction?.Invoke(payloadBase); + OnPayloadEnterEvent?.Invoke(payloadBase); + } + + protected virtual void OnPayloadExitAction(PayloadBase payloadBase) + { + PayloadExitAction?.Invoke(payloadBase); + OnPayloadExitEvent?.Invoke(payloadBase); + } + + private void Refresh() + { + _collision.Value = _collisionBuffer.Count > 0; + } } } \ No newline at end of file diff --git a/Runtime/Scripts/MaterialFlow/GripperBase.cs b/Runtime/Scripts/MaterialFlow/GripperBase.cs index 8239453..b09b38e 100644 --- a/Runtime/Scripts/MaterialFlow/GripperBase.cs +++ b/Runtime/Scripts/MaterialFlow/GripperBase.cs @@ -14,7 +14,7 @@ public abstract class GripperBase : Detector, IPayloadBuffer, ICustomInspector public IPropertyReadOnly IsActive => _isActive; public IPropertyReadOnly IsPicked => _isPicked; - public IReadOnlyList Entites => _buffer; + public IReadOnlyList Buffer => _buffer; [SerializeField] private Property _isActive = new (false); @@ -45,7 +45,7 @@ public Payload.PayloadCategory PickType private BoxCollider _collider; [SerializeField] - private List _buffer = new List(); + private List _buffer = new (); private new void OnEnable() { @@ -73,9 +73,9 @@ public void Pick() if (_isActive.Value) return; _isActive.Value = true; - foreach (var payloadObject in _collisionDetector.Buffer) + foreach (var payloadBase in CollisionBuffer) { - if (payloadObject is not Payload e) continue; + if (payloadBase is not Payload e) continue; if (e.Category != _pickType) continue; _buffer.Add(e); } @@ -113,7 +113,7 @@ public void Remove(Payload payload) public void DeleteAll() { - _collisionDetector.DestroyAll(); + DestroyAll(); _buffer.Clear(); _isPicked.Value = _buffer.Count > 0; } @@ -133,18 +133,17 @@ private void OnIsPickedChanged(bool value) } private PayloadBase GetTargetPayload() { - var storage = _collisionDetector.GetLastPayloadStorage(); + var storage = CollisionBuffer.GetLastPayloadStorage(); if (storage != null) return storage; switch (_pickType) { case Payload.PayloadCategory.Part: - var payload = _collisionDetector.GetLastByType(Payload.PayloadCategory.Assembly); - return payload != null ? payload : _collisionDetector.GetLastByType(Payload.PayloadCategory.Transport); + var payload = CollisionBuffer.GetLastByType(Payload.PayloadCategory.Assembly); + return payload != null ? payload : CollisionBuffer.GetLastByType(Payload.PayloadCategory.Transport); case Payload.PayloadCategory.Assembly: - return _collisionDetector.GetLastByType(Payload.PayloadCategory.Transport); + return CollisionBuffer.GetLastByType(Payload.PayloadCategory.Transport); case Payload.PayloadCategory.Transport: - return null; default: return null; } diff --git a/Runtime/Scripts/MaterialFlow/PayloadTag.cs b/Runtime/Scripts/MaterialFlow/PayloadTag.cs index 8c55497..716c3c1 100644 --- a/Runtime/Scripts/MaterialFlow/PayloadTag.cs +++ b/Runtime/Scripts/MaterialFlow/PayloadTag.cs @@ -10,7 +10,7 @@ namespace OC.MaterialFlow public class PayloadTag : MonoBehaviour { public Payload Payload => _payload; - public List DirecotryId => _directoryId; + public List DirectoryId => _directoryId; [SerializeField] private List _directoryId = new(); diff --git a/Runtime/Scripts/MaterialFlow/PayloadUtils.cs b/Runtime/Scripts/MaterialFlow/PayloadUtils.cs new file mode 100644 index 0000000..6c1cbd4 --- /dev/null +++ b/Runtime/Scripts/MaterialFlow/PayloadUtils.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; + +namespace OC.MaterialFlow +{ + public static class PayloadUtils + { + public static bool IsTypeValid(PayloadBase payloadBase, CollisionFilter filter) + { + return payloadBase switch + { + PayloadStorage => filter.HasFlag(CollisionFilter.Storage), + StaticCollider => filter.HasFlag(CollisionFilter.Static), + Payload payload => ((int)filter & 2.Pow((int)payload.Category)) != 0, + _ => false + }; + } + + public static bool IsGroupValid(int groupId, int requiredGroupId) + { + if (requiredGroupId == 0) return true; + return requiredGroupId == groupId; + } + + public static PayloadStorage GetLastPayloadStorage(this IList payloads) + { + for (var i = payloads.Count - 1; i >= 0; i--) + { + if (payloads[i] is not PayloadStorage e) continue; + return e; + } + return null; + } + + public static Payload GetLastByType(this IList payloads, Payload.PayloadCategory type) + { + for (var i = payloads.Count - 1; i >= 0; i--) + { + if (payloads[i] is not Payload e) continue; + if (e.Category == type) + { + return e; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/MaterialFlow/PayloadUtils.cs.meta b/Runtime/Scripts/MaterialFlow/PayloadUtils.cs.meta new file mode 100644 index 0000000..3cc7838 --- /dev/null +++ b/Runtime/Scripts/MaterialFlow/PayloadUtils.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0b90a06ee1924f7d962594bdedc2dc22 +timeCreated: 1750771910 \ No newline at end of file diff --git a/Runtime/Scripts/MaterialFlow/Sink.cs b/Runtime/Scripts/MaterialFlow/Sink.cs index 1726d78..a9df81d 100644 --- a/Runtime/Scripts/MaterialFlow/Sink.cs +++ b/Runtime/Scripts/MaterialFlow/Sink.cs @@ -20,9 +20,8 @@ public class Sink : Detector, ICustomInspector, IInteractable GetComponent().isTrigger = true; } - private new void OnValidate() + private void OnValidate() { - base.OnValidate(); _auto.OnValidate(); } @@ -30,10 +29,7 @@ private void FixedUpdate() { if (_auto) Delete(); } - - public void Delete() - { - _collisionDetector.DestroyAll(); - } + + public void Delete() => DestroyAll(); } } diff --git a/Runtime/Scripts/MaterialFlow/Source.cs b/Runtime/Scripts/MaterialFlow/Source.cs index 23f6133..6340ad7 100644 --- a/Runtime/Scripts/MaterialFlow/Source.cs +++ b/Runtime/Scripts/MaterialFlow/Source.cs @@ -35,9 +35,8 @@ public class Source : Detector, ISource, ICustomInspector, IInteractable GetComponent().isTrigger = true; } - private new void OnValidate() + private void OnValidate() { - base.OnValidate(); _typeId.OnValidate(); } @@ -54,7 +53,7 @@ private int TypeIdValidate(int value) public virtual void Create() { - if (_collisionDetector.Collision) return; + if (Collision.Value) return; try { @@ -69,9 +68,6 @@ public virtual void Create() } } - public virtual void Delete() - { - _collisionDetector.DestroyAll(); - } + public virtual void Delete() => DestroyAll(); } } diff --git a/Runtime/Scripts/System/ConfigurationManager.cs b/Runtime/Scripts/System/ConfigurationManager.cs index 24e8588..e3f3629 100644 --- a/Runtime/Scripts/System/ConfigurationManager.cs +++ b/Runtime/Scripts/System/ConfigurationManager.cs @@ -70,18 +70,18 @@ public void ReconnectClients() public void ResetForce() { - foreach (var item in _devices.Where(item => item.Link.Override.Value)) + foreach (var item in _devices.Where(item => item.Override.Value)) { - item.Link.Override.Value = false; - Logging.Logger.Log(LogType.Log, $"Link Override is DISABLED: {item.Link.Path}"); + item.Override.Value = false; + Logging.Logger.Log(LogType.Log, $"Link Override is DISABLED: {item.Link.ScenePath}"); } } public void PrintForce() { - foreach (var item in _devices.Where(item => item.Link.Override.Value)) + foreach (var item in _devices.Where(item => item.Override.Value)) { - Logging.Logger.Log(LogType.Log, $"Link Override is ACTIVE: {item.Link.Path}"); + Logging.Logger.Log(LogType.Log, $"Link Override is ACTIVE: {item.Link.ScenePath}"); } } } diff --git a/Runtime/Scripts/System/ProjectTreeFactory.cs b/Runtime/Scripts/System/ProjectTreeFactory.cs index 08eeb68..4f459db 100644 --- a/Runtime/Scripts/System/ProjectTreeFactory.cs +++ b/Runtime/Scripts/System/ProjectTreeFactory.cs @@ -59,13 +59,13 @@ private static List GetDevices(Component root) links.Add(link); } - links = links.OrderBy(x => x.Path).ToList(); + links = links.OrderBy(x => x.ScenePath).ToList(); return links; } private static void CreateDevice(XElement root, Link link) { - var groups = link.Path.Split('.'); + var groups = link.ScenePath.Split('.'); var localRoot = root; for (var i = 1; i < groups.Length - 1; i++) @@ -97,7 +97,7 @@ private static XElement CreateDevice(Link link) { if (string.IsNullOrEmpty(attribute.Key)) { - Logging.Logger.LogWarning($"Device: {link.Path} {link.Type}: Attribute Key is empty"); + Logging.Logger.LogWarning($"Device: {link.ScenePath} {link.Type}: Attribute Key is empty"); continue; } device.Add(new XElement(attribute.Key, attribute.Value)); diff --git a/Samples/Demo/0.1 Devices.unity b/Samples/Demo/0.1 Devices.unity index bcf3146..4e58cdc 100644 --- a/Samples/Demo/0.1 Devices.unity +++ b/Samples/Demo/0.1 Devices.unity @@ -551,20 +551,21 @@ MonoBehaviour: OnActiveChanged: m_PersistentCalls: m_Calls: [] + _override: + _value: 0 _link: + Control: 0 + Status: 0 _enable: 1 - _override: - _value: 0 _connected: _value: 0 + _name: Drive_Speed + _scenePath: MAIN.Devices.Drives.Drive_Speed + _clientPath: MAIN.Devices.Drives.Drive_Speed _type: FB_Drive _parent: {fileID: 0} _attributes: [] - _name: Drive_Speed - _path: MAIN.Devices.Drives.Drive_Speed - _connectorData: - Control: 0 - Status: 0 + _variablesDescription: [] ControlData: 0 StatusData: 0 _stateObserver: @@ -632,16 +633,20 @@ MonoBehaviour: m_PersistentCalls: m_Calls: [] _link: + Control: 0 + Status: 0 _enable: 1 - _override: - _value: 0 _connected: _value: 0 + _name: SensorAnalog_1 + _scenePath: MAIN.Devices.SensorsAnalog.SensorAnalog_1 + _clientPath: MAIN.Devices.SensorsAnalog.SensorAnalog_1 _type: FB_SensorAnalog _parent: {fileID: 0} _attributes: [] - _name: SensorAnalog_1 - _path: MAIN.Devices.SensorsAnalog.SensorAnalog_1 + _variablesDescription: [] + ControlData: 0 + StatusData: 0 --- !u!114 &186187013 MonoBehaviour: m_ObjectHideFlags: 0 @@ -730,6 +735,8 @@ MonoBehaviour: _value: 0 _value: _value: 0 + _override: + _value: 0 _minus: _value: 0 _plus: @@ -784,19 +791,18 @@ MonoBehaviour: m_PersistentCalls: m_Calls: [] _link: + Control: 0 + Status: 0 _enable: 1 - _override: - _value: 0 _connected: _value: 0 + _name: Cylinder_1 + _scenePath: MAIN.Devices.++Cylinders.Cylinder_1 + _clientPath: MAIN.Devices.`++Cylinders`.Cylinder_1 _type: FB_Cylinder _parent: {fileID: 0} _attributes: [] - _name: Cylinder_1 - _path: MAIN.Devices.Cylinders.Cylinder_1 - _connector: - Control: 0 - Status: 0 + _variablesDescription: [] --- !u!1 &213885625 GameObject: m_ObjectHideFlags: 0 @@ -1176,16 +1182,18 @@ MonoBehaviour: m_PersistentCalls: m_Calls: [] _link: + Control: 0 + Status: 0 _enable: 1 - _override: - _value: 0 _connected: _value: 0 + _name: SensorBinary_1 + _scenePath: MAIN.Devices.SensorsBinary.SensorBinary_1 + _clientPath: MAIN.Devices.SensorsBinary.SensorBinary_1 _type: FB_SensorBinary _parent: {fileID: 0} _attributes: [] - _name: SensorBinary_1 - _path: MAIN.Devices.SensorsBinary.SensorBinary_1 + _variablesDescription: [] --- !u!65 &414147752 BoxCollider: m_ObjectHideFlags: 0 @@ -2308,20 +2316,21 @@ MonoBehaviour: OnActiveChanged: m_PersistentCalls: m_Calls: [] + _override: + _value: 0 _link: + Control: 0 + Status: 0 _enable: 1 - _override: - _value: 0 _connected: _value: 0 + _name: Drive_Simple + _scenePath: MAIN.Devices.Drives.Drive_Simple + _clientPath: MAIN.Devices.Drives.Drive_Simple _type: FB_Drive _parent: {fileID: 0} _attributes: [] - _name: Drive_Simple - _path: MAIN.Devices.Drives.Drive_Simple - _connectorData: - Control: 0 - Status: 0 + _variablesDescription: [] ControlData: 0 StatusData: 0 _stateObserver: @@ -3310,16 +3319,18 @@ MonoBehaviour: m_PersistentCalls: m_Calls: [] _link: + Control: 0 + Status: 0 _enable: 1 - _override: - _value: 0 _connected: _value: 0 + _name: SensorBinary_3 + _scenePath: MAIN.Devices.SensorsBinary.SensorBinary_3 + _clientPath: MAIN.Devices.SensorsBinary.SensorBinary_3 _type: FB_SensorBinary _parent: {fileID: 0} _attributes: [] - _name: SensorBinary_3 - _path: MAIN.Devices.SensorsBinary.SensorBinary_3 + _variablesDescription: [] --- !u!65 &1081963574 BoxCollider: m_ObjectHideFlags: 0 @@ -3668,16 +3679,18 @@ MonoBehaviour: m_PersistentCalls: m_Calls: [] _link: + Control: 0 + Status: 0 _enable: 1 - _override: - _value: 0 _connected: _value: 0 + _name: SensorBinary_2 + _scenePath: MAIN.Devices.SensorsBinary.SensorBinary_2 + _clientPath: MAIN.Devices.SensorsBinary.SensorBinary_2 _type: FB_SensorBinary _parent: {fileID: 0} _attributes: [] - _name: SensorBinary_2 - _path: MAIN.Devices.SensorsBinary.SensorBinary_2 + _variablesDescription: [] --- !u!65 &1154275226 BoxCollider: m_ObjectHideFlags: 0 @@ -3874,6 +3887,8 @@ MonoBehaviour: _value: 0 _value: _value: 0 + _override: + _value: 0 _minus: _value: 0 _plus: @@ -3928,19 +3943,18 @@ MonoBehaviour: m_PersistentCalls: m_Calls: [] _link: + Control: 0 + Status: 0 _enable: 1 - _override: - _value: 0 _connected: _value: 0 + _name: Cylinder_3 + _scenePath: MAIN.Devices.++Cylinders.Cylinder_3 + _clientPath: MAIN.Devices.`++Cylinders`.Cylinder_3 _type: FB_Cylinder _parent: {fileID: 0} _attributes: [] - _name: Cylinder_3 - _path: MAIN.Devices.Cylinders.Cylinder_3 - _connector: - Control: 0 - Status: 0 + _variablesDescription: [] --- !u!1 &1237805922 GameObject: m_ObjectHideFlags: 0 @@ -4130,16 +4144,20 @@ MonoBehaviour: m_PersistentCalls: m_Calls: [] _link: + Control: 0 + Status: 0 _enable: 1 - _override: - _value: 0 _connected: _value: 0 + _name: SensorAnalog_2 + _scenePath: MAIN.Devices.SensorsAnalog.SensorAnalog_2 + _clientPath: MAIN.Devices.SensorsAnalog.SensorAnalog_2 _type: FB_SensorAnalog _parent: {fileID: 0} _attributes: [] - _name: SensorAnalog_2 - _path: MAIN.Devices.SensorsAnalog.SensorAnalog_2 + _variablesDescription: [] + ControlData: 0 + StatusData: 0 --- !u!114 &1271094949 MonoBehaviour: m_ObjectHideFlags: 0 @@ -4745,16 +4763,20 @@ MonoBehaviour: m_PersistentCalls: m_Calls: [] _link: + Control: 0 + Status: 0 _enable: 1 - _override: - _value: 0 _connected: _value: 0 + _name: Lock + _scenePath: MAIN.Devices.Interactions.Lock + _clientPath: MAIN.Devices.Interactions.Lock _type: FB_Lock _parent: {fileID: 0} _attributes: [] - _name: Lock - _path: MAIN.Devices.Interactions.Lock + _variablesDescription: [] + ControlData: 0 + StatusData: 0 --- !u!1 &1553020088 GameObject: m_ObjectHideFlags: 0 @@ -4992,20 +5014,21 @@ MonoBehaviour: OnActiveChanged: m_PersistentCalls: m_Calls: [] + _override: + _value: 0 _link: + Control: 0 + Status: 0 _enable: 1 - _override: - _value: 0 _connected: _value: 0 + _name: Drive_Position + _scenePath: MAIN.Devices.Drives.Drive_Position + _clientPath: MAIN.Devices.Drives.Drive_Position _type: FB_Drive _parent: {fileID: 0} _attributes: [] - _name: Drive_Position - _path: MAIN.Devices.Drives.Drive_Position - _connectorData: - Control: 0 - Status: 0 + _variablesDescription: [] ControlData: 0 StatusData: 0 _stateObserver: @@ -5107,16 +5130,20 @@ MonoBehaviour: m_PersistentCalls: m_Calls: [] _link: + Control: 0 + Status: 0 _enable: 1 - _override: - _value: 0 _connected: _value: 0 + _name: SensorAnalog_3 + _scenePath: MAIN.Devices.SensorsAnalog.SensorAnalog_3 + _clientPath: MAIN.Devices.SensorsAnalog.SensorAnalog_3 _type: FB_SensorAnalog _parent: {fileID: 0} _attributes: [] - _name: SensorAnalog_3 - _path: MAIN.Devices.SensorsAnalog.SensorAnalog_3 + _variablesDescription: [] + ControlData: 0 + StatusData: 0 --- !u!114 &1674164523 MonoBehaviour: m_ObjectHideFlags: 0 @@ -5305,6 +5332,8 @@ MonoBehaviour: _value: 0 _value: _value: 0 + _override: + _value: 0 _minus: _value: 0 _plus: @@ -5359,19 +5388,18 @@ MonoBehaviour: m_PersistentCalls: m_Calls: [] _link: + Control: 0 + Status: 0 _enable: 1 - _override: - _value: 0 _connected: _value: 0 + _name: Cylinder_2 + _scenePath: MAIN.Devices.++Cylinders.Cylinder_2 + _clientPath: MAIN.Devices.`++Cylinders`.Cylinder_2 _type: FB_Cylinder _parent: {fileID: 0} _attributes: [] - _name: Cylinder_2 - _path: MAIN.Devices.Cylinders.Cylinder_2 - _connector: - Control: 0 - Status: 0 + _variablesDescription: [] --- !u!1 &1738973010 GameObject: m_ObjectHideFlags: 0 @@ -6218,25 +6246,24 @@ MonoBehaviour: _value: 0 _rootName: MAIN _link: - _enable: 0 - _override: - _value: 0 + Control: 0 + Status: 0 + _enable: 1 _connected: _value: 0 + _name: fbSystem + _scenePath: + _clientPath: _type: _parent: {fileID: 0} _attributes: [] - _name: - _path: - _connector: - Control: 0 - Status: 0 - TimeScale: 0 + _variablesDescription: [] + TimeScale: 1 _config: _name: Client _reconnect: 1 _netId: Local - _port: 351 + _port: 851 _clearBuffer: 1 _verbose: 0 --- !u!1 &2008748801 @@ -6481,17 +6508,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 817ecc2928f837b4aa8a08d6752902de, type: 3} m_Name: m_EditorClassIdentifier: - _link: - _enable: 1 - _override: - _value: 0 - _connected: - _value: 0 - _type: FB_Lamp - _parent: {fileID: 0} - _attributes: [] - _name: Lamp - _path: MAIN.Devices.Interactions.Lamp _override: _value: 0 _value: @@ -6499,6 +6515,19 @@ MonoBehaviour: _color: _value: {r: 0, g: 1, b: 1, a: 1} _colorChangers: [] + _link: + Control: 0 + Status: 0 + _enable: 1 + _connected: + _value: 0 + _name: Lamp + _scenePath: MAIN.Devices.Interactions.Lamp + _clientPath: MAIN.Devices.Interactions.Lamp + _type: FB_Lamp + _parent: {fileID: 0} + _attributes: [] + _variablesDescription: [] OnValueChanged: m_PersistentCalls: m_Calls: @@ -6939,20 +6968,24 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5f93e25de85dd144596dd28727a85363, type: 3} m_Name: m_EditorClassIdentifier: + _override: + _value: 0 + _index: + _value: 0 + _stateCount: 2 _link: + Control: 0 + Status: 0 _enable: 1 - _override: - _value: 0 _connected: _value: 0 + _name: Switch + _scenePath: MAIN.Devices.Interactions.Switch + _clientPath: MAIN.Devices.Interactions.Switch _type: FB_Switch _parent: {fileID: 0} _attributes: [] - _name: Switch - _path: MAIN.Devices.Interactions.Switch - _index: - _value: 0 - _stateCount: 2 + _variablesDescription: [] OnIndexChanged: m_PersistentCalls: m_Calls: [] diff --git a/Samples/Demo/Prefabs/Button.prefab b/Samples/Demo/Prefabs/Button.prefab index 8ac6c57..25e22f2 100644 --- a/Samples/Demo/Prefabs/Button.prefab +++ b/Samples/Demo/Prefabs/Button.prefab @@ -246,17 +246,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 614c4abb630a42d08afd8b0891123dc7, type: 3} m_Name: m_EditorClassIdentifier: - _link: - _enable: 1 - _override: - _value: 0 - _connected: - _value: 0 - _type: FB_Button - _parent: {fileID: 0} - _attributes: [] - _name: Button - _path: Button + _override: + _value: 0 _pressed: _value: 0 _feedback: @@ -268,6 +259,19 @@ MonoBehaviour: _color: _value: {r: 0, g: 1, b: 1, a: 1} _colorChangers: [] + _link: + Control: 0 + Status: 0 + _enable: 1 + _connected: + _value: 0 + _name: Button + _scenePath: + _clientPath: + _type: FB_Button + _parent: {fileID: 0} + _attributes: [] + _variablesDescription: [] OnClickEvent: m_PersistentCalls: m_Calls: [] diff --git a/Tests/Editor/Client/TestClientVariableExtension.cs b/Tests/Editor/Client/TestClientVariableExtension.cs index 0697620..04e989c 100644 --- a/Tests/Editor/Client/TestClientVariableExtension.cs +++ b/Tests/Editor/Client/TestClientVariableExtension.cs @@ -17,18 +17,14 @@ public bool IsVariableNameValid(string name) { return ClientVariableExtension.IsVariableNameValid(name); } - + [Test] - [TestCase("Machine&3", ExpectedResult = "Machine3")] - [TestCase("_FG01", ExpectedResult = "A_FG01")] - [TestCase("0001", ExpectedResult = "A0001")] - [TestCase("FG 01", ExpectedResult = "FG_01")] - [TestCase("FG-01", ExpectedResult = "FG_01")] - [TestCase("FG01", ExpectedResult = "FG01")] - [TestCase("FG_01", ExpectedResult = "FG_01")] - public string CorrectVariableName(string input) + [TestCase("MAIN.ST01.FG01.Cylinder_1", ExpectedResult = "MAIN.ST01.FG01.Cylinder_1")] + [TestCase("MAIN.++ST01.FG01.Cylinder_1", ExpectedResult = "MAIN.`++ST01`.FG01.Cylinder_1")] + [TestCase("MAIN.++ST01.+&FG01.--Cylinder_1", ExpectedResult = "MAIN.`++ST01`.`+&FG01`.`--Cylinder_1`")] + public string GetCompatiblePath(string input) { - return ClientVariableExtension.CorrectVariableName(input); + return input.GetClientCompatiblePath(); } } } \ No newline at end of file diff --git a/Tests/Editor/MaterialFlow/TestCollisionDetector.cs b/Tests/Editor/MaterialFlow/TestDetector.cs similarity index 70% rename from Tests/Editor/MaterialFlow/TestCollisionDetector.cs rename to Tests/Editor/MaterialFlow/TestDetector.cs index 20b970c..760a494 100644 --- a/Tests/Editor/MaterialFlow/TestCollisionDetector.cs +++ b/Tests/Editor/MaterialFlow/TestDetector.cs @@ -7,14 +7,15 @@ namespace OC.Tests.Editor.MaterialFlow { - public class TestCollisionDetector + public class TestDetector { - private CollisionDetector _collisionDetector; + private Detector _detector; [SetUp] - public void Initilize() + public void Initialize() { - _collisionDetector = new CollisionDetector(); + var gameObject = new GameObject(); + _detector = gameObject.AddComponent(); } [Test] @@ -45,10 +46,10 @@ public void Initilize() [TestCase(Payload.PayloadCategory.Part, CollisionFilter.All, ExpectedResult = true)] [TestCase(Payload.PayloadCategory.Assembly, CollisionFilter.All, ExpectedResult = true)] [TestCase(Payload.PayloadCategory.Transport, CollisionFilter.All, ExpectedResult = true)] - public bool IsEntityTypeValid(Payload.PayloadCategory entityType, CollisionFilter filter) + public bool IsPayloadTypeValid(Payload.PayloadCategory entityType, CollisionFilter filter) { - PayloadBase entityBase = NewEntity(entityType, 0); - return CollisionDetector.IsTypeValid(entityBase, filter); + PayloadBase entityBase = NewPayload(entityType, 0); + return PayloadUtils.IsTypeValid(entityBase, filter); } [Test] @@ -59,10 +60,10 @@ public bool IsEntityTypeValid(Payload.PayloadCategory entityType, CollisionFilte [TestCase(CollisionFilter.Static, ExpectedResult = true)] [TestCase(CollisionFilter.Storage, ExpectedResult = false)] [TestCase(CollisionFilter.All, ExpectedResult = true)] - public bool IsEntityStaticValid(CollisionFilter filter) + public bool IsPayloadStaticValid(CollisionFilter filter) { - PayloadBase entityBase = NewEntityStatic(0); - return CollisionDetector.IsTypeValid(entityBase, filter); + PayloadBase entityBase = NewPayloadStatic(0); + return PayloadUtils.IsTypeValid(entityBase, filter); } [Test] @@ -73,10 +74,10 @@ public bool IsEntityStaticValid(CollisionFilter filter) [TestCase(CollisionFilter.Static, ExpectedResult = false)] [TestCase(CollisionFilter.Storage, ExpectedResult = true)] [TestCase(CollisionFilter.All, ExpectedResult = true)] - public bool IsEntityStorgeValid(CollisionFilter filter) + public bool IsPayloadStorageValid(CollisionFilter filter) { - PayloadBase entityBase = NewEntityStorage(0); - return CollisionDetector.IsTypeValid(entityBase, filter); + PayloadBase entityBase = NewPayloadStorage(0); + return PayloadUtils.IsTypeValid(entityBase, filter); } [Test] @@ -103,10 +104,10 @@ public bool IsEntityStorgeValid(CollisionFilter filter) [TestCase(Payload.PayloadCategory.Transport, CollisionFilter.All, ExpectedResult = true)] public bool AddEntityTyp(Payload.PayloadCategory entityType, CollisionFilter filter) { - PayloadBase entityBase = NewEntity(entityType, 0); - _collisionDetector.Filter = filter; - _collisionDetector.Add(entityBase); - return _collisionDetector.Buffer.Count > 0; + PayloadBase entityBase = NewPayload(entityType, 0); + _detector.CollisionFilter = filter; + _detector.Add(entityBase); + return _detector.CollisionBuffer.Count > 0; } [Test] @@ -119,9 +120,10 @@ public bool AddEntityTyp(Payload.PayloadCategory entityType, CollisionFilter fil [TestCase(CollisionFilter.All, ExpectedResult = true)] public bool AddEntityStatic(CollisionFilter filter) { - PayloadBase entityBase = NewEntityStatic(0); - _collisionDetector.Filter = filter; - return _collisionDetector.Add(entityBase); + PayloadBase entityBase = NewPayloadStatic(0); + _detector.CollisionFilter = filter; + _detector.Add(entityBase); + return _detector.CollisionBuffer.Count > 0; } [Test] @@ -132,11 +134,12 @@ public bool AddEntityStatic(CollisionFilter filter) [TestCase(CollisionFilter.Static, ExpectedResult = false)] [TestCase(CollisionFilter.Storage, ExpectedResult = true)] [TestCase(CollisionFilter.All, ExpectedResult = true)] - public bool AddEntitityStorage(CollisionFilter filter) + public bool AddEntityStorage(CollisionFilter filter) { - PayloadBase entityBase = NewEntityStorage(0); - _collisionDetector.Filter = filter; - return _collisionDetector.Add(entityBase); + PayloadBase entityBase = NewPayloadStorage(0); + _detector.CollisionFilter = filter; + _detector.Add(entityBase); + return _detector.CollisionBuffer.Count > 0; } [Test] @@ -147,47 +150,47 @@ public void AddGameObject() gameObject.AddComponent(); gameObject.AddComponent(); - _collisionDetector.Filter = CollisionFilter.All; - _collisionDetector.Add(gameObject); - Assert.IsTrue(_collisionDetector.Collision); + _detector.CollisionFilter = CollisionFilter.All; + _detector.Add(gameObject); + Assert.IsTrue(_detector.Collision.Value); } [Test] public void AddGameObjectFailed() { - _collisionDetector.Add(new GameObject()); - Assert.IsFalse(_collisionDetector.Collision); + _detector.Add(new GameObject()); + Assert.IsFalse(_detector.Collision.Value); } [Test] public void IsGroupIdValid() { var random = new Random().Next(0, 20); - Assert.IsTrue(CollisionDetector.IsGroupValid(random,0), $"0 == {random}"); - Assert.IsTrue(CollisionDetector.IsGroupValid(random,random), $"{random} == {random}"); - Assert.IsFalse(CollisionDetector.IsGroupValid(random,random + 1), $"{random +1} == {random}"); + Assert.IsTrue(PayloadUtils.IsGroupValid(random,0), $"0 == {random}"); + Assert.IsTrue(PayloadUtils.IsGroupValid(random,random), $"{random} == {random}"); + Assert.IsFalse(PayloadUtils.IsGroupValid(random,random + 1), $"{random +1} == {random}"); } [Test] public void Remove() { - Initilize(); + Initialize(); const int instanceCount = 3; - var entity = NewEntity(Payload.PayloadCategory.Part, 0); + var entity = NewPayload(Payload.PayloadCategory.Part, 0); - _collisionDetector.Filter = CollisionFilter.Part; - _collisionDetector.GroupId = 0; + _detector.CollisionFilter = CollisionFilter.Part; + _detector.GroupId = 0; - _collisionDetector.Add(entity); + _detector.Add(entity); for (var i = 0; i < instanceCount; i++) { - _collisionDetector.Add(NewEntity(Payload.PayloadCategory.Part, 0)); + _detector.Add(NewPayload(Payload.PayloadCategory.Part, 0)); } - _collisionDetector.Remove(entity); + _detector.Remove(entity); - Assert.IsFalse(_collisionDetector.Buffer.Contains(entity)); + Assert.IsFalse(_detector.CollisionBuffer.Contains(entity)); } [Test] @@ -195,18 +198,18 @@ public void ClearAll() { const int instanceCount = 3; - _collisionDetector.Filter = CollisionFilter.Part; - _collisionDetector.GroupId = 0; + _detector.CollisionFilter = CollisionFilter.Part; + _detector.GroupId = 0; for (var i = 0; i < instanceCount; i++) { - _collisionDetector.Add(NewEntity(Payload.PayloadCategory.Part, 0)); + _detector.Add(NewPayload(Payload.PayloadCategory.Part, 0)); } - _collisionDetector.ClearAll(); + _detector.ClearAll(); - Assert.AreEqual(_collisionDetector.Buffer.Count, 0); - Assert.IsFalse(_collisionDetector.Collision.Value); + Assert.AreEqual(_detector.CollisionBuffer.Count, 0); + Assert.IsFalse(_detector.Collision.Value); } [Test] @@ -214,21 +217,21 @@ public void DestroyAll() { const int instanceCount = 3; - var entity = NewEntity(Payload.PayloadCategory.Part, 0); - _collisionDetector.Filter = CollisionFilter.Part; - _collisionDetector.GroupId = 0; + var entity = NewPayload(Payload.PayloadCategory.Part, 0); + _detector.CollisionFilter = CollisionFilter.Part; + _detector.GroupId = 0; - _collisionDetector.Add(entity); + _detector.Add(entity); for (var i = 0; i < instanceCount; i++) { - _collisionDetector.Add(NewEntity(Payload.PayloadCategory.Part, 0)); + _detector.Add(NewPayload(Payload.PayloadCategory.Part, 0)); } - _collisionDetector.DestroyAll(); + _detector.DestroyAll(); Assert.IsTrue(entity == null); - Assert.IsFalse(_collisionDetector.Collision); + Assert.IsFalse(_detector.Collision.Value); } [Test] @@ -236,18 +239,18 @@ public void DestroyEntityEvent() { const int instanceCount = 3; - _collisionDetector.Filter = CollisionFilter.Part; - _collisionDetector.GroupId = 0; + _detector.CollisionFilter = CollisionFilter.Part; + _detector.GroupId = 0; for (var i = 0; i < instanceCount; i++) { - _collisionDetector.Add(NewEntity(Payload.PayloadCategory.Part, 0)); + _detector.Add(NewPayload(Payload.PayloadCategory.Part, 0)); } - _collisionDetector.Buffer[0].DestroyDirty(); - _collisionDetector.Buffer[1].DestroyDirty(); + _detector.CollisionBuffer[0].DestroyDirty(); + _detector.CollisionBuffer[1].DestroyDirty(); - Assert.AreEqual(1, _collisionDetector.Buffer.Count); + Assert.AreEqual(1, _detector.CollisionBuffer.Count); } [Test] @@ -257,23 +260,23 @@ public void IsEmpty() const CollisionFilter requiredType = CollisionFilter.Assembly | CollisionFilter.Part | CollisionFilter.Transport | CollisionFilter.Storage; - _collisionDetector.Filter = requiredType; - _collisionDetector.GroupId = 0; + _detector.CollisionFilter = requiredType; + _detector.GroupId = 0; foreach (Payload.PayloadCategory entityType in Enum.GetValues(typeof(Payload.PayloadCategory))) { for (var i = 0; i < instanceCount; i++) { - _collisionDetector.Add(NewEntity(entityType, 0)); + _detector.Add(NewPayload(entityType, 0)); } } - _collisionDetector.DestroyAll(); + _detector.DestroyAll(); - Assert.IsFalse(_collisionDetector.Collision); + Assert.IsFalse(_detector.Collision.Value); } - private static Payload NewEntity(Payload.PayloadCategory type, int groupId) + private static Payload NewPayload(Payload.PayloadCategory type, int groupId) { var gameObject = new GameObject(); gameObject.AddComponent(); @@ -289,7 +292,7 @@ private static Payload NewEntity(Payload.PayloadCategory type, int groupId) return entity; } - private static StaticCollider NewEntityStatic(int groupId) + private static StaticCollider NewPayloadStatic(int groupId) { var gameObject = new GameObject(); var entity = gameObject.AddComponent(); @@ -297,7 +300,7 @@ private static StaticCollider NewEntityStatic(int groupId) return entity; } - private static PayloadStorage NewEntityStorage(int groupId) + private static PayloadStorage NewPayloadStorage(int groupId) { var gameObject = new GameObject(); var entity = gameObject.AddComponent(); diff --git a/Tests/Editor/MaterialFlow/TestCollisionDetector.cs.meta b/Tests/Editor/MaterialFlow/TestDetector.cs.meta similarity index 100% rename from Tests/Editor/MaterialFlow/TestCollisionDetector.cs.meta rename to Tests/Editor/MaterialFlow/TestDetector.cs.meta diff --git a/Tests/Editor/MaterialFlow/TestEntity.cs b/Tests/Editor/MaterialFlow/TestPayload.cs similarity index 91% rename from Tests/Editor/MaterialFlow/TestEntity.cs rename to Tests/Editor/MaterialFlow/TestPayload.cs index 4198455..55caad9 100644 --- a/Tests/Editor/MaterialFlow/TestEntity.cs +++ b/Tests/Editor/MaterialFlow/TestPayload.cs @@ -5,7 +5,7 @@ namespace OC.Tests.Editor.MaterialFlow { - public class TestEntity + public class TestPayload { private Payload _payload; @@ -46,9 +46,9 @@ public void SetControlState(ControlState controlState) [TestCase("Case3", Payload.PayloadCategory.Transport, ControlState.Error, PhysicState.Static)] [TestCase("Case4", Payload.PayloadCategory.Part, ControlState.Done, PhysicState.Free)] [TestCase("Case5", Payload.PayloadCategory.Assembly, ControlState.Ready, PhysicState.Parent)] - public void ApplyDiscription(string name, Payload.PayloadCategory entityType, ControlState controlState, PhysicState physicState) + public void ApplyDescription(string name, Payload.PayloadCategory entityType, ControlState controlState, PhysicState physicState) { - var discription = new PayloadDescription() + var description = new PayloadDescription() { Name = name, Type = (int)entityType, @@ -56,7 +56,7 @@ public void ApplyDiscription(string name, Payload.PayloadCategory entityType, Co PhysicState = (int)physicState }; - _payload.ApplyDescription(discription); + _payload.ApplyDescription(description); Assert.AreEqual(name, _payload.name, "Name is wrong"); Assert.AreEqual(entityType, _payload.Category, "Type is wrong"); @@ -71,16 +71,16 @@ public void ApplyDiscription(string name, Payload.PayloadCategory entityType, Co [TestCase(3, 6, (ulong)51)] [TestCase(4, 8, (ulong)61)] [TestCase(5, 10, (ulong)71)] - public void ApplyDiscription(int typeId, int groupId, ulong uniqueId) + public void ApplyDescription(int typeId, int groupId, ulong uniqueId) { - var discription = new PayloadDescription() + var description = new PayloadDescription() { TypeId = typeId, GroupId = groupId, UniqueId = uniqueId }; - _payload.ApplyDescription(discription); + _payload.ApplyDescription(description); Assert.AreEqual(typeId, _payload.TypeId, "TypeId is wrong"); Assert.AreEqual(groupId, _payload.GroupId, "GroupId is wrong"); diff --git a/Tests/Editor/MaterialFlow/TestEntity.cs.meta b/Tests/Editor/MaterialFlow/TestPayload.cs.meta similarity index 100% rename from Tests/Editor/MaterialFlow/TestEntity.cs.meta rename to Tests/Editor/MaterialFlow/TestPayload.cs.meta diff --git a/Tests/Editor/MaterialFlow/TestPoolBuffer.cs b/Tests/Editor/MaterialFlow/TestPoolBuffer.cs index b83e9ca..05bd9c1 100644 --- a/Tests/Editor/MaterialFlow/TestPoolBuffer.cs +++ b/Tests/Editor/MaterialFlow/TestPoolBuffer.cs @@ -13,20 +13,20 @@ public class TestPoolManager { private PoolManager _poolManager; - private static Payload CreateEntity(int typeId = 0, uint uniqueId = 0, GameObject parent = null) + private static Payload CreatePayload(int typeId = 0, uint uniqueId = 0, GameObject parent = null) { var gameObject = new GameObject(); gameObject.AddComponent(); gameObject.AddComponent(); var entity = gameObject.AddComponent(); - var discription = new PayloadDescription() + var description = new PayloadDescription() { TypeId = typeId, UniqueId = uniqueId }; - entity.ApplyDescription(discription); + entity.ApplyDescription(description); if (parent != null) gameObject.transform.parent = parent.transform; return entity; @@ -36,9 +36,9 @@ private static Payload CreateEntity(int typeId = 0, uint uniqueId = 0, GameObjec public void SetUp() { _poolManager = new PoolManager(); - _poolManager.PayloadList.Add(CreateEntity()); - _poolManager.PayloadList.Add(CreateEntity(1)); - _poolManager.PayloadList.Add(CreateEntity(2)); + _poolManager.PayloadList.Add(CreatePayload()); + _poolManager.PayloadList.Add(CreatePayload(1)); + _poolManager.PayloadList.Add(CreatePayload(2)); } [Test] @@ -66,18 +66,18 @@ public void GetValidType(int typeId, int expectedTypeId) [Test] public void InvalidTypeIdLog() { - var entity = CreateEntity(5); - _poolManager.Registrate(entity); + var payload = CreatePayload(5); + _poolManager.Registrate(payload); LogAssert.Expect(LogType.Error, new Regex(@"(isn't valid)")); } [Test] public void InvalidUniqueIdLog() { - var entity1 = CreateEntity(0, 1); - var entity2 = CreateEntity(0, 1); - _poolManager.Registrate(entity1); - _poolManager.Registrate(entity2); + var payload1 = CreatePayload(0, 1); + var payload2= CreatePayload(0, 1); + _poolManager.Registrate(payload1); + _poolManager.Registrate(payload2); LogAssert.Expect(LogType.Error, new Regex(@"(already exists)")); } @@ -109,39 +109,39 @@ public int Instantiate(ulong uniqueId, int actualCount) [Test] [TestCaseSource(nameof(GetEntityInfos))] - public void InstantiateWithInfo(EntityDiscriptionTestCase entityDiscriptionTestCase) + public void InstantiateWithInfo(PayloadDescriptionTestCase payloadDescriptionTestCase) { - for (var i = 1; i <= entityDiscriptionTestCase.ActualCount; i++) + for (var i = 1; i <= payloadDescriptionTestCase.ActualCount; i++) { _poolManager.Instantiate(Vector3.zero, Quaternion.identity, 0, (ulong)i); } LogAssert.ignoreFailingMessages = true; - _poolManager.Instantiate(entityDiscriptionTestCase.Description); - Assert.AreEqual(entityDiscriptionTestCase.ExpectedCount, _poolManager.Count, $"Pool Entities Count: {_poolManager.Count}, Expected: {entityDiscriptionTestCase.ExpectedCount}"); + _poolManager.Instantiate(payloadDescriptionTestCase.Description); + Assert.AreEqual(payloadDescriptionTestCase.ExpectedCount, _poolManager.Count, $"Pool Entities Count: {_poolManager.Count}, Expected: {payloadDescriptionTestCase.ExpectedCount}"); } - public static IEnumerable GetEntityInfos() + public static IEnumerable GetEntityInfos() { - yield return new EntityDiscriptionTestCase + yield return new PayloadDescriptionTestCase { Description = new PayloadDescription(){Type = 1, UniqueId = 1, Transform = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one)}, ActualCount = 3, ExpectedCount = 3, }; - yield return new EntityDiscriptionTestCase + yield return new PayloadDescriptionTestCase { Description = new PayloadDescription{Type = 1, UniqueId = 4, Transform = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one)}, ActualCount = 3, ExpectedCount = 4, }; - yield return new EntityDiscriptionTestCase + yield return new PayloadDescriptionTestCase { Description = new PayloadDescription{Type = 1, UniqueId = 5, Transform = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one)}, ActualCount = 5, ExpectedCount = 5, }; - yield return new EntityDiscriptionTestCase + yield return new PayloadDescriptionTestCase { Description = new PayloadDescription{Type = 1, UniqueId = 6, Transform = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one)}, ActualCount = 5, @@ -149,7 +149,7 @@ public static IEnumerable GetEntityInfos() }; } - public struct EntityDiscriptionTestCase + public struct PayloadDescriptionTestCase { public PayloadDescription Description; public int ActualCount; @@ -174,33 +174,33 @@ public void InstantiateWithWrongId(ulong uniqueId, int actualId, int expectedCou } [Test] - public void RegistrateParts() + public void RegisterParts() { const int expected = 3; for (var i = 0; i < expected; i++) { - _poolManager.Registrate(CreateEntity()); + _poolManager.Registrate(CreatePayload()); } Assert.AreEqual(expected, _poolManager.Count, $"Pool Entities Count: {_poolManager.Count}, Expected: {expected}"); - _poolManager.Registrate(CreateEntity(uniqueId: 1)); + _poolManager.Registrate(CreatePayload(uniqueId: 1)); LogAssert.Expect(LogType.Error, new Regex(@"(already exists)")); Assert.AreEqual(expected, _poolManager.Count, $"Pool Entities Count: {_poolManager.Count}, Expected: {expected}"); - _poolManager.Registrate(CreateEntity(typeId: 4)); + _poolManager.Registrate(CreatePayload(typeId: 4)); LogAssert.Expect(LogType.Error, new Regex(@"(isn't valid)")); Assert.AreEqual(expected, _poolManager.Count, $"Pool Entities Count: {_poolManager.Count}, Expected: {expected}"); } [Test] - public void UnregistrateParts() + public void UnregistrParts() { const int partsCount = 4; var parts = new List(); for (var i = 0; i < partsCount; i++) { - var part = CreateEntity(); + var part = CreatePayload(); parts.Add(part); _poolManager.Registrate(part); } @@ -214,24 +214,24 @@ public void UnregistrateParts() } [Test] - public void RegistrateAssembly() + public void Registrssembly() { - var assembly = CreateEntity(); - CreateEntity(parent: assembly.gameObject); - CreateEntity(parent: assembly.gameObject); - CreateEntity(parent: assembly.gameObject); + var assembly = CreatePayload(); + CreatePayload(parent: assembly.gameObject); + CreatePayload(parent: assembly.gameObject); + CreatePayload(parent: assembly.gameObject); _poolManager.Registrate(assembly); Assert.AreEqual(4, _poolManager.Count, $"Pool Entities Count: {_poolManager.Count}, Expected: {4}"); } [Test] - public void UnregistrateAssembly() + public void UnregistrAssembly() { - var assembly = CreateEntity(); - var partA = CreateEntity(parent: assembly.gameObject); - CreateEntity(parent: assembly.gameObject); - CreateEntity(parent: assembly.gameObject); + var assembly = CreatePayload(); + var partA = CreatePayload(parent: assembly.gameObject); + CreatePayload(parent: assembly.gameObject); + CreatePayload(parent: assembly.gameObject); _poolManager.Registrate(assembly); @@ -242,10 +242,10 @@ public void UnregistrateAssembly() } [Test] - public void UnregistrateInvalidPart() + public void UnregistrInvalidPart() { - var partA = CreateEntity(); - var partB = CreateEntity(); + var partA = CreatePayload(); + var partB = CreatePayload(); partB.Registrate(123); _poolManager.Registrate(partA); @@ -256,10 +256,10 @@ public void UnregistrateInvalidPart() } [Test] - public void UnregistrateInvalidUniqueId() + public void UnregistrInvalidUniqueId() { - var partA = CreateEntity(uniqueId: 1); - var partB = CreateEntity(uniqueId: 2); + var partA = CreatePayload(uniqueId: 1); + var partB = CreatePayload(uniqueId: 2); _poolManager.Registrate(partA); _poolManager.Registrate(partB); @@ -278,7 +278,7 @@ public void DestroyParts() for (var i = 0; i < partsCount; i++) { - var part = CreateEntity(); + var part = CreatePayload(); parts.Add(part); _poolManager.Registrate(part); } @@ -294,11 +294,11 @@ public void DestroyParts() [Test] public void DestroyAssembly() { - var part = CreateEntity(); - var assembly = CreateEntity(); - CreateEntity(parent: assembly.gameObject); - CreateEntity(parent: assembly.gameObject); - CreateEntity(parent: assembly.gameObject); + var part = CreatePayload(); + var assembly = CreatePayload(); + CreatePayload(parent: assembly.gameObject); + CreatePayload(parent: assembly.gameObject); + CreatePayload(parent: assembly.gameObject); _poolManager.Registrate(part); _poolManager.Registrate(assembly); @@ -311,11 +311,11 @@ public void DestroyAssembly() [Test] public void DestroyAll() { - var part = CreateEntity(); - var assembly = CreateEntity(); - CreateEntity(parent: assembly.gameObject); - CreateEntity(parent: assembly.gameObject); - CreateEntity(parent: assembly.gameObject); + var part = CreatePayload(); + var assembly = CreatePayload(); + CreatePayload(parent: assembly.gameObject); + CreatePayload(parent: assembly.gameObject); + CreatePayload(parent: assembly.gameObject); _poolManager.Registrate(assembly); _poolManager.Registrate(part); @@ -328,7 +328,7 @@ public void DestroyAll() public void ReplaceLogs() { var source = new GameObject("TestSource"); - var part = CreateEntity(typeId: 1); + var part = CreatePayload(typeId: 1); _poolManager.Registrate(part); _poolManager.Replace(source, null,0); @@ -352,7 +352,7 @@ public void ReplacePart(int uniqueId) var source = new GameObject("TestSource"); for (var i = 1; i <= entitiesCount; i++) { - _poolManager.Registrate(CreateEntity(1, (uint)i)); + _poolManager.Registrate(CreatePayload(1, (uint)i)); } var part = _poolManager.Payloads[(ulong)uniqueId]; @@ -377,12 +377,12 @@ public void ReplacePart(int uniqueId) [TestCase(1, 6, ExpectedResult = true)] [TestCase(5, 9, ExpectedResult = true)] [Obsolete("Obsolete")] - public bool RegistrateWithNewUniqueId(int actualUniqueId, int newUniqueId) + public bool RegistrWithNewUniqueId(int actualUniqueId, int newUniqueId) { const int entitiesCount = 5; for (var i = 1; i <= entitiesCount; i++) { - _poolManager.Registrate(CreateEntity(1, (uint)i)); + _poolManager.Registrate(CreatePayload(1, (uint)i)); } var part = _poolManager.Payloads[(ulong)actualUniqueId]; @@ -404,7 +404,7 @@ public void IsUniqueIdValid(int uniqueId, bool expected) const int entitiesCount = 5; for (var i = 1; i <= entitiesCount; i++) { - _poolManager.Registrate(CreateEntity(1, (uint)i)); + _poolManager.Registrate(CreatePayload(1, (uint)i)); } var result = _poolManager.IsUniqueIdValid((ulong)uniqueId); @@ -422,7 +422,7 @@ public int GetPossibleUniqueId(int uniqueId) const int entitiesCount = 5; for (var i = 1; i <= entitiesCount; i++) { - _poolManager.Registrate(CreateEntity(1, (uint)i)); + _poolManager.Registrate(CreatePayload(1, (uint)i)); } return (int)_poolManager.GetPossibleUniqueId((ulong)uniqueId); @@ -437,7 +437,7 @@ public void Repair(int uniqueId) const int entitiesCount = 5; for (var i = 1; i <= entitiesCount; i++) { - _poolManager.Registrate(CreateEntity(1, (uint)i)); + _poolManager.Registrate(CreatePayload(1, (uint)i)); } _poolManager.Payloads[(ulong)uniqueId] = null; diff --git a/Tests/Editor/TestUtils.cs b/Tests/Editor/TestUtils.cs new file mode 100644 index 0000000..14da417 --- /dev/null +++ b/Tests/Editor/TestUtils.cs @@ -0,0 +1,13 @@ +using UnityEngine; + +namespace OC.Tests +{ + public static class TestUtils + { + public static T CreateComponent() where T : Component + { + var gameObject = new GameObject(); + return gameObject.AddComponent(); + } + } +} \ No newline at end of file diff --git a/Tests/Editor/TestUtils.cs.meta b/Tests/Editor/TestUtils.cs.meta new file mode 100644 index 0000000..3b85ef9 --- /dev/null +++ b/Tests/Editor/TestUtils.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a2218b5b624f47908cb686c9599a76a7 +timeCreated: 1751013878 \ No newline at end of file diff --git a/Tests/Runtime/Components/TestAxis.cs b/Tests/Runtime/Components/TestAxis.cs index d63b6e7..aa5f46d 100644 --- a/Tests/Runtime/Components/TestAxis.cs +++ b/Tests/Runtime/Components/TestAxis.cs @@ -7,7 +7,7 @@ using UnityEngine.TestTools.Utils; using OC.Components; -namespace Components +namespace OC.Tests.Runtime.Components { public class TestAxis { diff --git a/Tests/Runtime/Components/TestCylinder.cs b/Tests/Runtime/Components/TestCylinder.cs index ba81fec..4208165 100644 --- a/Tests/Runtime/Components/TestCylinder.cs +++ b/Tests/Runtime/Components/TestCylinder.cs @@ -4,10 +4,9 @@ using System.Collections; using System.Collections.Generic; using NUnit.Framework; -using OC.Tests; using Assert = UnityEngine.Assertions.Assert; -namespace Components +namespace OC.Tests.Runtime.Components { public class TestCylinder { diff --git a/Tests/Runtime/Components/TestGripper.cs b/Tests/Runtime/Components/TestGripper.cs index 05a1a47..07417ff 100644 --- a/Tests/Runtime/Components/TestGripper.cs +++ b/Tests/Runtime/Components/TestGripper.cs @@ -6,7 +6,7 @@ using NUnit.Framework; using Assert = UnityEngine.Assertions.Assert; -namespace Components +namespace OC.Tests.Runtime.Components { public class TestGripper { @@ -217,7 +217,7 @@ public IEnumerator PickFromGripper() _gripperPick1.Pick(); Assert.IsTrue(_gripperPick1.IsActive.Value); Assert.IsTrue(_gripperPick1.IsPicked.Value); - var count = _gripperPick1.Entites.Count; + var count = _gripperPick1.Buffer.Count; _gripperPick1.transform.Translate(Vector3.up); yield return new WaitForSecondsRealtime(DELAY); @@ -230,7 +230,7 @@ public IEnumerator PickFromGripper() Assert.IsTrue(_gripperPick2.IsActive.Value); Assert.IsTrue(_gripperPick2.IsPicked.Value); - Assert.AreEqual(count - _gripperPick1.Entites.Count, _gripperPick2.Entites.Count); + Assert.AreEqual(count - _gripperPick1.Buffer.Count, _gripperPick2.Buffer.Count); } } } diff --git a/Tests/Runtime/Components/TestSensorBinary.cs b/Tests/Runtime/Components/TestSensorBinaryScene.cs similarity index 52% rename from Tests/Runtime/Components/TestSensorBinary.cs rename to Tests/Runtime/Components/TestSensorBinaryScene.cs index f76bbda..1c6ba53 100644 --- a/Tests/Runtime/Components/TestSensorBinary.cs +++ b/Tests/Runtime/Components/TestSensorBinaryScene.cs @@ -5,18 +5,18 @@ using UnityEngine; using UnityEngine.TestTools; -namespace Components +namespace OC.Tests.Runtime.Components { - public class TestSensorBinary + public class TestSensorBinaryScene { - private GameObject _testground; + private GameObject _testGround; private SensorBinary[] _allSensors; - private SensorBinary _sensorBinaryNone; - private SensorBinary _sensorBinaryAll; - private SensorBinary _sensorBinaryPart; - private SensorBinary _sensorBinaryAssembly; - private SensorBinary _sensorBinaryTransport; - private SensorBinary _sensorBinaryStatic; + private SensorBinary _sensorBinarySceneNone; + private SensorBinary _sensorBinarySceneAll; + private SensorBinary _sensorBinaryScenePart; + private SensorBinary _sensorBinarySceneAssembly; + private SensorBinary _sensorBinarySceneTransport; + private SensorBinary _sensorBinarySceneStatic; private Payload[] _allPayloads; private Payload _payloadPart; private Payload _payloadAssembly; @@ -26,33 +26,33 @@ public class TestSensorBinary [UnitySetUp] public IEnumerator UnitySetup() { - _testground = Object.Instantiate(Resources.Load("Prefabs/TestScene_SensorBinary")); - _allSensors = _testground.GetComponentsInChildren(); + _testGround = Object.Instantiate(Resources.Load("Prefabs/TestScene_SensorBinary")); + _allSensors = _testGround.GetComponentsInChildren(); foreach (var sensor in _allSensors) { switch (sensor.name) { case "SensorBinaryNone": - _sensorBinaryNone = sensor; + _sensorBinarySceneNone = sensor; break; case "SensorBinaryAll": - _sensorBinaryAll = sensor; + _sensorBinarySceneAll = sensor; break; case "SensorBinaryPart": - _sensorBinaryPart = sensor; + _sensorBinaryScenePart = sensor; break; case "SensorBinaryAssembly": - _sensorBinaryAssembly = sensor; + _sensorBinarySceneAssembly = sensor; break; case "SensorBinaryTransport": - _sensorBinaryTransport = sensor; + _sensorBinarySceneTransport = sensor; break; case "SensorBinaryStatic": - _sensorBinaryStatic = sensor; + _sensorBinarySceneStatic = sensor; break; } - _allPayloads = _testground.GetComponentsInChildren(); + _allPayloads = _testGround.GetComponentsInChildren(); foreach (var payload in _allPayloads) { switch (payload.name) @@ -69,7 +69,7 @@ public IEnumerator UnitySetup() } } - _staticCollider = _testground.GetComponentInChildren(); + _staticCollider = _testGround.GetComponentInChildren(); } yield return null; @@ -78,143 +78,143 @@ public IEnumerator UnitySetup() [UnityTest] public IEnumerator PartDetection() { - _payloadPart.transform.position = _sensorBinaryNone.transform.position; + _payloadPart.transform.position = _sensorBinarySceneNone.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryNone.Value.Value, "SensorBinary None detected something"); + Assert.IsFalse(_sensorBinarySceneNone.Value.Value, "SensorBinary None detected something"); yield return new WaitForSecondsRealtime(0.05f); - _payloadPart.transform.position = _sensorBinaryAll.transform.position; + _payloadPart.transform.position = _sensorBinarySceneAll.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsTrue(_sensorBinaryAll.Value.Value, "SensorBinary All detected nothing"); + Assert.IsTrue(_sensorBinarySceneAll.Value.Value, "SensorBinary All detected nothing"); yield return new WaitForSecondsRealtime(0.05f); - _payloadPart.transform.position = _sensorBinaryPart.transform.position; + _payloadPart.transform.position = _sensorBinaryScenePart.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsTrue(_sensorBinaryPart.Value.Value, "SensorBinary Part detected nothing"); + Assert.IsTrue(_sensorBinaryScenePart.Value.Value, "SensorBinary Part detected nothing"); yield return new WaitForSecondsRealtime(0.05f); - _payloadPart.transform.position = _sensorBinaryAssembly.transform.position; + _payloadPart.transform.position = _sensorBinarySceneAssembly.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryAssembly.Value.Value, "SensorBinary Assembly detected something"); + Assert.IsFalse(_sensorBinarySceneAssembly.Value.Value, "SensorBinary Assembly detected something"); yield return new WaitForSecondsRealtime(0.05f); - _payloadPart.transform.position = _sensorBinaryTransport.transform.position; + _payloadPart.transform.position = _sensorBinarySceneTransport.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryTransport.Value.Value, "SensorBinary Transport detected something"); + Assert.IsFalse(_sensorBinarySceneTransport.Value.Value, "SensorBinary Transport detected something"); yield return new WaitForSecondsRealtime(0.05f); - _payloadPart.transform.position = _sensorBinaryStatic.transform.position; + _payloadPart.transform.position = _sensorBinarySceneStatic.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryStatic.Value.Value, "SensorBinary Static detected something"); + Assert.IsFalse(_sensorBinarySceneStatic.Value.Value, "SensorBinary Static detected something"); yield return new WaitForSecondsRealtime(0.05f); } [UnityTest] public IEnumerator AssemblyDetection() { - _payloadAssembly.transform.position = _sensorBinaryNone.transform.position; + _payloadAssembly.transform.position = _sensorBinarySceneNone.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryNone.Value.Value, "SensorBinary None detected something"); + Assert.IsFalse(_sensorBinarySceneNone.Value.Value, "SensorBinary None detected something"); yield return new WaitForSecondsRealtime(0.05f); - _payloadAssembly.transform.position = _sensorBinaryAll.transform.position; + _payloadAssembly.transform.position = _sensorBinarySceneAll.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsTrue(_sensorBinaryAll.Value.Value, "SensorBinary All detected nothing"); + Assert.IsTrue(_sensorBinarySceneAll.Value.Value, "SensorBinary All detected nothing"); yield return new WaitForSecondsRealtime(0.05f); - _payloadAssembly.transform.position = _sensorBinaryPart.transform.position; + _payloadAssembly.transform.position = _sensorBinaryScenePart.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryPart.Value.Value, "SensorBinary Part detected something"); + Assert.IsFalse(_sensorBinaryScenePart.Value.Value, "SensorBinary Part detected something"); yield return new WaitForSecondsRealtime(0.05f); - _payloadAssembly.transform.position = _sensorBinaryAssembly.transform.position; + _payloadAssembly.transform.position = _sensorBinarySceneAssembly.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsTrue(_sensorBinaryAssembly.Value.Value, "SensorBinary Assembly detected nothing"); + Assert.IsTrue(_sensorBinarySceneAssembly.Value.Value, "SensorBinary Assembly detected nothing"); yield return new WaitForSecondsRealtime(0.05f); - _payloadAssembly.transform.position = _sensorBinaryTransport.transform.position; + _payloadAssembly.transform.position = _sensorBinarySceneTransport.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryTransport.Value.Value, "SensorBinary Transport detected something"); + Assert.IsFalse(_sensorBinarySceneTransport.Value.Value, "SensorBinary Transport detected something"); yield return new WaitForSecondsRealtime(0.05f); - _payloadAssembly.transform.position = _sensorBinaryStatic.transform.position; + _payloadAssembly.transform.position = _sensorBinarySceneStatic.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryStatic.Value.Value, "SensorBinary Static detected something"); + Assert.IsFalse(_sensorBinarySceneStatic.Value.Value, "SensorBinary Static detected something"); yield return new WaitForSecondsRealtime(0.05f); } [UnityTest] public IEnumerator TransportDetection() { - _payloadTransport.transform.position = _sensorBinaryNone.transform.position; + _payloadTransport.transform.position = _sensorBinarySceneNone.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryNone.Value.Value, "SensorBinary None detected something"); + Assert.IsFalse(_sensorBinarySceneNone.Value.Value, "SensorBinary None detected something"); yield return new WaitForSecondsRealtime(0.05f); - _payloadTransport.transform.position = _sensorBinaryAll.transform.position; + _payloadTransport.transform.position = _sensorBinarySceneAll.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsTrue(_sensorBinaryAll.Value.Value, "SensorBinary All detected nothing"); + Assert.IsTrue(_sensorBinarySceneAll.Value.Value, "SensorBinary All detected nothing"); yield return new WaitForSecondsRealtime(0.05f); - _payloadTransport.transform.position = _sensorBinaryPart.transform.position; + _payloadTransport.transform.position = _sensorBinaryScenePart.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryPart.Value.Value, "SensorBinary Part detected something"); + Assert.IsFalse(_sensorBinaryScenePart.Value.Value, "SensorBinary Part detected something"); yield return new WaitForSecondsRealtime(0.05f); - _payloadTransport.transform.position = _sensorBinaryAssembly.transform.position; + _payloadTransport.transform.position = _sensorBinarySceneAssembly.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryAssembly.Value.Value, "SensorBinary Assembly detected something"); + Assert.IsFalse(_sensorBinarySceneAssembly.Value.Value, "SensorBinary Assembly detected something"); yield return new WaitForSecondsRealtime(0.05f); - _payloadTransport.transform.position = _sensorBinaryTransport.transform.position; + _payloadTransport.transform.position = _sensorBinarySceneTransport.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsTrue(_sensorBinaryTransport.Value.Value, "SensorBinary Transport detected nothing"); + Assert.IsTrue(_sensorBinarySceneTransport.Value.Value, "SensorBinary Transport detected nothing"); yield return new WaitForSecondsRealtime(0.05f); - _payloadTransport.transform.position = _sensorBinaryStatic.transform.position; + _payloadTransport.transform.position = _sensorBinarySceneStatic.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryStatic.Value.Value, "SensorBinary Static detected something"); + Assert.IsFalse(_sensorBinarySceneStatic.Value.Value, "SensorBinary Static detected something"); yield return new WaitForSecondsRealtime(0.05f); } [UnityTest] public IEnumerator StaticDetection() { - _staticCollider.transform.position = _sensorBinaryNone.transform.position; + _staticCollider.transform.position = _sensorBinarySceneNone.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryNone.Value.Value, "SensorBinary None detected something"); + Assert.IsFalse(_sensorBinarySceneNone.Value.Value, "SensorBinary None detected something"); yield return new WaitForSecondsRealtime(0.05f); - _staticCollider.transform.position = _sensorBinaryAll.transform.position; + _staticCollider.transform.position = _sensorBinarySceneAll.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsTrue(_sensorBinaryAll.Value.Value, "SensorBinary All detected nothing"); + Assert.IsTrue(_sensorBinarySceneAll.Value.Value, "SensorBinary All detected nothing"); yield return new WaitForSecondsRealtime(0.05f); - _staticCollider.transform.position = _sensorBinaryPart.transform.position; + _staticCollider.transform.position = _sensorBinaryScenePart.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryPart.Value.Value, "SensorBinary Part detected something"); + Assert.IsFalse(_sensorBinaryScenePart.Value.Value, "SensorBinary Part detected something"); yield return new WaitForSecondsRealtime(0.05f); - _staticCollider.transform.position = _sensorBinaryAssembly.transform.position; + _staticCollider.transform.position = _sensorBinarySceneAssembly.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryAssembly.Value.Value, "SensorBinary Assembly detected something"); + Assert.IsFalse(_sensorBinarySceneAssembly.Value.Value, "SensorBinary Assembly detected something"); yield return new WaitForSecondsRealtime(0.05f); - _staticCollider.transform.position = _sensorBinaryTransport.transform.position; + _staticCollider.transform.position = _sensorBinarySceneTransport.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsFalse(_sensorBinaryTransport.Value.Value, "SensorBinary Transport detected something"); + Assert.IsFalse(_sensorBinarySceneTransport.Value.Value, "SensorBinary Transport detected something"); yield return new WaitForSecondsRealtime(0.05f); - _staticCollider.transform.position = _sensorBinaryStatic.transform.position; + _staticCollider.transform.position = _sensorBinarySceneStatic.transform.position; yield return new WaitForSecondsRealtime(0.05f); - Assert.IsTrue(_sensorBinaryStatic.Value.Value, "SensorBinary Static detected nothing"); + Assert.IsTrue(_sensorBinarySceneStatic.Value.Value, "SensorBinary Static detected nothing"); yield return new WaitForSecondsRealtime(0.05f); } [UnityTearDown] public IEnumerator Cleanup() { - Object.Destroy(_testground); + Object.Destroy(_testGround); yield return null; } } diff --git a/Tests/Runtime/Components/TestSensorBinary.cs.meta b/Tests/Runtime/Components/TestSensorBinaryScene.cs.meta similarity index 100% rename from Tests/Runtime/Components/TestSensorBinary.cs.meta rename to Tests/Runtime/Components/TestSensorBinaryScene.cs.meta diff --git a/Tests/Runtime/Utils.cs b/Tests/Runtime/Utils.cs index 0897e92..fac12cf 100644 --- a/Tests/Runtime/Utils.cs +++ b/Tests/Runtime/Utils.cs @@ -73,5 +73,11 @@ public static void AreEqual(Vector3 expected, Vector3 actual) { AreEqual(expected, actual, null); } + + public static T CreateComponent() where T : Component + { + var gameObject = new GameObject(); + return gameObject.AddComponent(); + } } } diff --git a/package.json b/package.json index b68bce2..b0990f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.open-commissioning.core", - "version": "1.2.6", + "version": "1.2.7", "displayName": "Open Commissioning", "description": "Open Commissioning is an open source framework for virtual commissioning. The goal is to provide an open platform for testing and commissioning of PLC code using a virtual model.", "unity": "2022.3",