Blueprint/example interface demonstrating signal handling without external communication. More...
Public Member Functions | |
| override void | OpenInterface () |
| Opens the interface - called on main thread. | |
| override void | CloseInterface () |
| Closes the interface - called on main thread. | |
Public Member Functions inherited from realvirtual.FastInterfaceBase | |
| override void | OpenInterface () |
| Opens the interface and starts communication thread. | |
| override void | CloseInterface () |
| Closes the interface and stops communication thread. | |
| virtual void | PreFixedUpdate () |
| Processes PLC outputs before FixedUpdate - applies data FROM PLC TO Unity objects IMPLEMENTS IPreFixedUpdate::PreFixedUpdate. | |
| virtual void | PostFixedUpdate () |
| Processes PLC inputs after FixedUpdate - reads data FROM Unity objects TO send to PLC IMPLEMENTS IPostFixedUpdate::PostFixedUpdate. | |
| void | SetManualPhysicsMode (bool enabled) |
| Enables or disables manual physics control mode. | |
| void | StepPhysics (float timestep=0f) |
| Steps physics simulation forward by a specified time duration. | |
| override void | PostAllScenesLoaded () |
| Override PostAllScenesLoaded to prevent base class from opening interface too early. | |
| void | OnInterfaceEnable () |
| Called by realvirtualController after all scenes are loaded to enable the interface. | |
Public Member Functions inherited from realvirtual.InterfaceBaseClass | |
| void | UpdateInterfaceSignals (ref int inputs, ref int outputs) |
| Creates a new List of InterfaceSignals based on the Components under this Interface GameObject. | |
| Signal | CreateSignalObject (string name, SIGNALTYPE type, SIGNALDIRECTION direction) |
| Create a signal object as sub gameobject. | |
| Signal | AddSignal (InterfaceSignal interfacesignal) |
| void | RemoveSignal (InterfaceSignal interfacesignal) |
| virtual GameObject | GetSignal (string name) |
| Gets a signal with a name. | |
| void | SetAllSignalStatus (bool connected) |
| void | DestroyAllSignals () |
| void | DeleteSignals () |
Public Member Functions inherited from realvirtual.realvirtualBehavior | |
| virtual void | OnOwnershipChanged (bool isOwner) |
| Called when network ownership changes. | |
| void | SetNetworkOwner (bool isOwner) |
| Sets IsNetworkOwner and triggers OnOwnershipChanged callback. | |
| void | PreStartSim () |
| Is called by the realvirtualController before the component is started. | |
| void | StartSim () |
| Is called by the realvirtualController to start or stop the component. | |
| void | StopSim () |
| Vector3 | DirectionToVector (DIRECTION direction) |
| Transfers the direction enumeration to a vector. | |
| DIRECTION | VectorToDirection (bool torotatoin, Vector3 vector) |
| Transfers a vector to the direction enumeration. | |
| float | GetLocalScale (Transform thetransform, DIRECTION direction) |
| List< BehaviorInterfaceConnection > | UpdateConnectionInfo () |
| List< Signal > | GetConnectedSignals () |
| void | SetVisibility (bool visibility) |
| Sets the visibility of this object including all subobjects. | |
| List< BehaviorInterfaceConnection > | GetConnections () |
| List< Signal > | GetSignals () |
| GameObject | GetChildByName (string name) |
| Gets a child by name. | |
| List< GameObject > | GetChildsByName (string name) |
| Gets all child by name. | |
| GameObject | GetChildByNameAlsoHidden (string name) |
| List< GameObject > | GetAllMeshesWithGroup (string group) |
| List< GameObject > | GetAllWithGroup (string group) |
| List< GameObject > | GetAllWithGroups (List< string > groups) |
| List< GameObject > | GetAllMeshesWithGroups (List< string > groups) |
| List< string > | GetMyGroups () |
| List< GameObject > | GetMeshesWithSameGroups () |
| List< GameObject > | GetAllWithSameGroups () |
| MeshRenderer | GetMeshRenderer () |
| Gets the mesh renderers in the childrens. | |
| void | SetCollider (bool enabled, bool includeTriggers=true) |
| sets the collider in all child objects | |
| void | ErrorMessage (string message) |
| Displays an error message. | |
| void | ChangeConnectionMode (bool isconnected) |
| void | Log (string message) |
| Logs a message. | |
| void | Log (string message, object obj) |
| Logs a message with a relation to an object. | |
| void | Warning (string message, object obj) |
| Logs a warning with a relation to an object. | |
| void | Error (string message, object obj) |
| Logs an error with a relation to an object. | |
| void | Error (string message) |
| Logs an error. | |
| GameObject | DebugPosition (string debugname, Vector3 position, Quaternion quaternation, float scale) |
| Displays a gizmo for debugging positions. | |
| void | SetFreezePosition (bool enabled) |
| Freezes all child components to the current poosition. | |
| void | SetRbConstraints (RigidbodyConstraints constraints) |
| virtual void | AwakeAlsoDeactivated () |
Public Attributes | |
| int | LogIntervalCycles |
| Log signal values every N cycles when DebugMode is enabled. | |
| bool | SimulateValueChanges |
| Simulate changing values for output signals. | |
| float | ValueChangeSpeed |
| Speed of simulated value changes. | |
| int | TotalSignalsFound |
| Total number of signals found. | |
| int | InputSignalCount |
| Number of input signals. | |
| int | OutputSignalCount |
| Number of output signals. | |
| int | DataExchangeCycles |
| Number of communication cycles completed. | |
| float | SimulationTime |
| Total simulation time in seconds. | |
Public Attributes inherited from realvirtual.FastInterfaceBase | |
| string | State |
| Current connection status with visual indicator. | |
| InterfaceState | state |
| Internal connection state enum. | |
| new string | ErrorMessage |
| Last error message if connection failed. | |
| int | ReconnectAttemptCount |
| Number of reconnection attempts made. | |
| bool | IsReconnecting |
| Whether interface is currently attempting to reconnect. | |
| int | InputSignals |
| Total number of input signals found. | |
| int | OutputSignals |
| Total number of output signals found. | |
| int | CommCycleMs |
| Actual communication cycle time in milliseconds. | |
| int | CycleCount |
| Total number of communication cycles completed. | |
| int | UpdateCycleMs |
| Communication thread update interval in milliseconds. | |
| bool | OnlyTransmitChangedInputs |
| Only send input signals that have changed since last transmission (performance optimization) | |
| bool | AutoReconnect |
| Automatically attempt to reconnect on connection loss. | |
| float | ReconnectIntervalSeconds |
| Time to wait between reconnection attempts. | |
| int | MaxReconnectAttempts |
| Maximum reconnection attempts (-1 = unlimited) | |
| bool | DebugMode |
Public Attributes inherited from realvirtual.InterfaceBaseClass | |
| bool | IsConnected |
| List< InterfaceSignal > | InterfaceSignals |
| Hashtable | SignalNamesOutputs |
| Hashtable | SignalNamesInputs |
Public Attributes inherited from realvirtual.realvirtualBehavior | |
| string | Name |
| The name of the component if it should be different from the GameObject name. | |
| ActiveOnly | Active |
| GameObject | FromTemplate |
| realvirtualController | realvirtualController |
| bool | HideNonG44Components |
| bool | SceneIsAdditive |
| bool | ForceStop |
| bool | IsNetworkOwner |
| True when this component owns its simulation (local authority). Set to false by MultiplayerWEB on remote clients. | |
Protected Member Functions | |
| virtual void | OnInterfaceStarting () |
| Called when interface starts - performs initialization on main thread This method is called from OpenInterface() BEFORE the background communication thread starts. | |
| virtual void | OnInterfaceStopping () |
| Called when interface stops - performs cleanup on main thread This method is called from CloseInterface() AFTER the background communication thread has stopped. | |
| override async Task | EstablishConnection (CancellationToken cancellationToken) |
| Establishes connection on background thread This method is called ONCE when starting communication. | |
| override async Task | CommunicationLoop (CancellationToken cancellationToken) |
| Main communication processing on background thread This method is called REPEATEDLY in a loop after connection is established. | |
| override void | CloseConnection () |
| Cleanup when closing connection on background thread This method is called when stopping communication or before reconnection. | |
| override void | OnCommunicationStarted () |
| Called when communication thread starts successfully. | |
Protected Member Functions inherited from realvirtual.FastInterfaceBase | |
| virtual void | OnCommunicationError (Exception exception) |
| Handles communication errors and manages reconnection logic. | |
| virtual void | OnCommunicationStopped () |
| Called when communication thread stops. | |
| void | Start () |
| Unity Start - block base class behavior. | |
| new void | OnEnable () |
| Unity OnEnable - opens interface when component is enabled. | |
| new void | OnDisable () |
| virtual void | OnApplicationPause (bool pauseStatus) |
| Handles application pause events. | |
| void | FixedUpdate () |
| Unity FixedUpdate for main thread operations (signal sync moved to PrePost FixedUpdate) | |
| Dictionary< string, object > | GetInputsForPLC () |
| Gets all input signal values to send to PLC from background threads. | |
| Dictionary< string, object > | GetChangedInputsForPLC () |
| Gets only changed input signal values to send to PLC from background threads. | |
| void | ResetInputChangeDetection () |
| Resets change detection forcing all inputs to be considered changed on next call. | |
| void | SetOutputsFromPLC (Dictionary< string, object > outputs) |
| Sets output signal values from PLC data in background threads. | |
| void | SetOutputFromPLC (string signalName, object value) |
| Sets single output signal value from PLC data in background threads. | |
| void | RebuildCachedSignalArrays () |
| Rebuilds the cached signal arrays used by SyncOutputsToUnity/SyncInputsFromUnity. | |
| Dictionary< string, object > | ReadInputsThreadSafe () |
| [DEPRECATED] Use GetInputsForPLC() instead for clearer data flow direction | |
| Dictionary< string, object > | ReadChangedInputsThreadSafe () |
| [DEPRECATED] Use GetChangedInputsForPLC() instead for clearer data flow direction | |
| void | WriteOutputsThreadSafe (Dictionary< string, object > outputs) |
| [DEPRECATED] Use SetOutputsFromPLC() instead for clearer data flow direction | |
| void | WriteOutputThreadSafe (string signalName, object value) |
| [DEPRECATED] Use SetOutputFromPLC() instead for clearer data flow direction | |
| virtual void | CopyPropertiesToThreadSafe () |
| Copies MonoBehaviour properties to thread-safe variables before background thread starts. | |
| virtual void | PrepareForBackgroundThread () |
| Called on main thread to prepare any Unity GameObject data before background thread starts Override this to cache signal names, GameObject references, or other Unity-specific data that the background thread will need to access. | |
| virtual void | CleanupAfterBackgroundThread () |
| Called on main thread after background thread stops to clean up Unity-specific resources Override this to clean up cached data, reset Unity components, or perform other main-thread cleanup. | |
| virtual void | UpdateSignalCounts () |
| Updates input and output signal counts. | |
Protected Member Functions inherited from realvirtual.InterfaceBaseClass | |
| void | OnConnected () |
| void | OnDisconnected () |
| void | OnEnable () |
| void | OnDisable () |
Protected Member Functions inherited from realvirtual.realvirtualBehavior | |
| bool | hidename () |
| bool | hideactiveonly () |
| virtual void | OnStopSim () |
| virtual void | OnPreStartSim () |
| virtual void | OnStartSim () |
| MU | GetTopOfMu (GameObject obj) |
| Gets the top of an MU component (the first MU script going up in the hierarchy) | |
| void | InitGame4Automation () |
| Initialiates the components and gets the reference to the realvirtualController in the scene. | |
| virtual void | AfterAwake () |
| void | Awake () |
Additional Inherited Members | |
Public Types inherited from realvirtual.realvirtualBehavior | |
| enum | ActiveOnly { Always , Connected , Disconnected , Never , DontChange } |
Static Public Member Functions inherited from realvirtual.FastInterfaceBase | |
| static bool | IsManualPhysicsMode () |
| Gets whether manual physics mode is currently enabled globally. | |
Static Public Member Functions inherited from realvirtual.realvirtualBehavior | |
| static bool | DirectionIsLinear (DIRECTION direction) |
| Gets back if the direction is linear or a rotation. | |
Protected Attributes inherited from realvirtual.FastInterfaceBase | |
| string | threadSafeErrorMessage |
| int | privateCycleCount |
| int | privateCommCycleMs |
| bool | threadSafeDebugMode |
| int | threadSafeUpdateCycleMs |
Properties inherited from realvirtual.FastInterfaceBase | |
| new bool | IsConnected [get] |
| override bool | ShowIsConnectedField [get] |
| Used by [ShowIf] to hide IsConnected field for FastInterface classes - always returns false. | |
| bool | IsInterfaceReady [get] |
| Returns true if the interface has been initialized via OnInterfaceEnable. | |
Properties inherited from realvirtual.InterfaceBaseClass | |
| virtual string | InterfaceDisplayName [get] |
| Display name for interface in UI lists (removes "Interface" suffix by default, can be overridden for custom names) | |
| virtual bool | ShowIsConnectedField [get] |
Properties inherited from realvirtual.IOnInterfaceEnable | |
Detailed Description
Blueprint/example interface demonstrating signal handling without external communication.
This interface serves as a template for creating custom interfaces. It demonstrates:
- Signal discovery and metadata handling
- Thread-safe communication patterns
- Proper initialization and cleanup
- Value simulation for testing
To create your own interface:
- Copy this file and rename the class
- Replace the simulated connection in EstablishConnection() with your real connection logic
- Implement your protocol in ProcessCommunication()
- Add any cleanup code in CloseConnection()
Key helper methods available from FastInterface base class:
- this.GetAllSignals() - Get all child signals efficiently
- this.GetSignalComponent("name") - Find a specific signal by name with O(1) lookup
- GetSignalValue<T>("name") - Get signal value directly with fast access
- SetSignalValue<T>("name", value) - Set signal value directly with fast access Note: Additional extension methods may be available from FastSignalManagerHelper for specialized operations like signal creation and batch operations
Thread-safe data exchange (use in ProcessCommunication):
- GetInputsForPLC() - Read all input values safely from background thread
- SetOutputsFromPLC() - Write output values safely from background thread
Signal metadata methods:
- signal.SetMetadata("key", value) - Store custom data with signals
- signal.GetMetadata<T>("key") - Retrieve metadata
- signal.HasMetadata("key") - Check if metadata exists
Member Function Documentation
◆ CloseConnection()
|
protectedvirtual |
Cleanup when closing connection on background thread This method is called when stopping communication or before reconnection.
Use this to:
- Close network connections gracefully
- Send disconnect messages to external system
- Dispose of communication resources
- Clean up any background thread resources
IMPORTANT: This runs on a background thread - do NOT access Unity GameObjects! This is called both during normal shutdown and before reconnection attempts.
Available methods:
- ThreadSafeLogger.LogInfo/LogError/LogWarning() - Thread-safe logging
- privateCycleCount - Get total cycles completed for logging
- Connection cleanup methods (Close(), Dispose(), Disconnect())
Example TCP cleanup: stream?.Close(); stream?.Dispose(); tcpClient?.Close();
Reimplemented from realvirtual.FastInterfaceBase.
◆ CloseInterface()
|
virtual |
Closes the interface - called on main thread.
Reimplemented from realvirtual.InterfaceBaseClass.
◆ CommunicationLoop()
|
protectedvirtual |
Main communication processing on background thread This method is called REPEATEDLY in a loop after connection is established.
Use this to:
- Read data from external system
- Process received data and update output signals
- Read input signals and send to external system
- Handle protocol-specific communication
IMPORTANT: This runs on a background thread - do NOT access Unity GameObjects directly! The base class handles the loop timing based on UpdateCycleMs setting. This method should complete quickly to maintain consistent cycle times.
Available methods for signal data exchange:
- GetInputsForPLC(OnlyTransmitChangedInputs) - Get input signal values as Dictionary<string, object>
- SetOutputsFromPLC(Dictionary<string, object>) - Update output signal values
Available helper properties/fields:
- threadSafeDebugMode - Thread-safe copy of DebugMode property
- threadSafeUpdateCycleMs - Thread-safe copy of UpdateCycleMs
- threadSafeOnlyTransmitChangedInputs - Thread-safe copy of OnlyTransmitChangedInputs
- privateCycleCount - Current cycle number (use for statistics)
Available methods for logging and communication:
- ThreadSafeLogger.LogInfo/LogError/LogWarning() - Thread-safe logging
- ThreadSafeLogger.LogInfoIf(condition, message, source) - Conditional logging
- Network read/write methods on your connection objects
- Protocol-specific encoding/decoding methods
Example TCP pattern: byte[] buffer = new byte[1024]; int bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length); await stream.WriteAsync(data, 0, data.Length);
Reimplemented from realvirtual.FastInterfaceBase.
◆ EstablishConnection()
|
protectedvirtual |
Establishes connection on background thread This method is called ONCE when starting communication.
Use this to:
- Open network connections (TCP, UDP, WebSocket, etc.)
- Authenticate with external systems
- Perform handshaking protocols
- Initialize communication libraries
IMPORTANT: This runs on a background thread - do NOT access Unity GameObjects! If connection fails, throw an exception. The base class will handle reconnection automatically.
Available methods:
- ThreadSafeLogger.LogInfo/LogError/LogWarning() - Thread-safe logging
- Task.Delay(milliseconds) - Async delays
- Standard .NET networking classes (TcpClient, UdpClient, HttpClient, ClientWebSocket)
- throw new Exception("message") - To indicate connection failure
Example TCP implementation: tcpClient = new TcpClient(); await tcpClient.ConnectAsync(ip, port); stream = tcpClient.GetStream();
Reimplemented from realvirtual.FastInterfaceBase.
◆ OnCommunicationStarted()
|
protectedvirtual |
Called when communication thread starts successfully.
Reimplemented from realvirtual.FastInterfaceBase.
◆ OnInterfaceStarting()
|
protectedvirtual |
Called when interface starts - performs initialization on main thread This method is called from OpenInterface() BEFORE the background communication thread starts.
The signal manager is already initialized by the base class before this method is called. Use this to:
- Discover and configure signals
- Set up any data structures needed for communication
- Add metadata to signals
- Initialize hardware or libraries (main thread only operations)
IMPORTANT: This runs on the Unity main thread, so you can safely access GameObjects IMPORTANT: Signal manager is pre-initialized - you can immediately use all helper methods
Available methods from FastInterface base class:
- this.GetAllSignals() - Get all child signals as IEnumerable<Signal>
- this.GetSignalComponent("signalName") - Find specific signal by name (O(1) lookup)
- GetSignalValue<T>("signalName") - Get signal value directly
- SetSignalValue<T>("signalName", value) - Set signal value directly
Available extension methods from FastSignalManagerHelper (for Editor operations):
- this.CreateOrUpdateSignal("name", SignalType.Bool, SignalDirection.Input, metadata)
- signal.SetMetadata("key", value) - Add metadata to existing signals
- signal.GetMetadata<T>("key", defaultValue) - Read signal metadata
- this.GetAllSignals().Where(s => s.HasMetadata("key")) - Find signals by metadata
- this.HasSignal("signalName") - Check if signal exists
- this.GetInputSignals() / this.GetOutputSignals() - Get signals by direction
- this.CountSignals(direction, signalType) - Count signals by criteria
NEW: Comprehensive Signal Management with CreateOrUpdateSignal:
- this.CreateOrUpdateSignal("name", SignalType.Bool, SignalDirection.Input, metadata) → Creates new signal if doesn't exist → Updates metadata if signal exists with same direction → Replaces signal component if direction changed (keeps GameObject)
Example usage for dynamic signal import: var metadata = new Dictionary<string, object> { ["Source"] = "PLC", ["Address"] = "DB100.DBX0.0" }; var signal = this.CreateOrUpdateSignal("Motor1_Running", SignalType.Bool, SignalDirection.Output, metadata);
Signal direction change handling: // If Motor1_Running was previously an Input, it will be replaced with Output component // The GameObject is preserved, only the component changes signal = this.CreateOrUpdateSignal("Motor1_Running", SignalType.Bool, SignalDirection.Output, metadata, allowDirectionChange: true);
◆ OnInterfaceStopping()
|
protectedvirtual |
Called when interface stops - performs cleanup on main thread This method is called from CloseInterface() AFTER the background communication thread has stopped.
Use this to:
- Log final statistics
- Clean up any resources created in OnInterfaceStarting
- Save any persistent data
IMPORTANT: This runs on the Unity main thread after communication has fully stopped
Available methods:
- this.GetAllSignals() - Access all signals for final state logging
- this.GetSignalValue<T>("signalName") - Read final signal values
- Debug.Log() - Safe to use Unity logging
◆ OpenInterface()
|
virtual |
Opens the interface - called on main thread.
Reimplemented from realvirtual.InterfaceBaseClass.
Member Data Documentation
◆ DataExchangeCycles
| int realvirtual.BlueprintFastInterface.DataExchangeCycles |
Number of communication cycles completed.
◆ InputSignalCount
| int realvirtual.BlueprintFastInterface.InputSignalCount |
Number of input signals.
◆ LogIntervalCycles
| int realvirtual.BlueprintFastInterface.LogIntervalCycles |
Log signal values every N cycles when DebugMode is enabled.
◆ OutputSignalCount
| int realvirtual.BlueprintFastInterface.OutputSignalCount |
Number of output signals.
◆ SimulateValueChanges
| bool realvirtual.BlueprintFastInterface.SimulateValueChanges |
Simulate changing values for output signals.
◆ SimulationTime
| float realvirtual.BlueprintFastInterface.SimulationTime |
Total simulation time in seconds.
◆ TotalSignalsFound
| int realvirtual.BlueprintFastInterface.TotalSignalsFound |
Total number of signals found.
◆ ValueChangeSpeed
| float realvirtual.BlueprintFastInterface.ValueChangeSpeed |
Speed of simulated value changes.
Public Member Functions inherited from