Legacy Interfaces (Deprecated)
Deprecated: This documentation covers the legacy interface system using InterfaceBaseClass and InterfaceThreadedBaseClass. These approaches are deprecated and should not be used for new projects. Use FastInterface for all new interface development.
This guide provides reference documentation for the legacy interface system that was used in realvirtual before FastInterface was introduced. If you have existing interfaces built with these deprecated base classes, consider migrating to FastInterface for better performance, reliability, and maintainability.
Legacy Interface Base Classes
The legacy system provided two base classes for custom interface development:
InterfaceBaseClass (Single-threaded)
The simplest approach for basic protocol communication that runs on Unity's main thread:
using UnityEngine;
namespace realvirtual
{
public class MyLegacyInterface : InterfaceBaseClass
{
[Header("Connection Settings")]
public string ServerIP = "192.168.1.100";
public int Port = 502;
private bool isConnected = false;
public override void OpenInterface()
{
try
{
// Connect to external system
ConnectToServer(ServerIP, Port);
isConnected = true;
Debug.Log("Interface connected");
}
catch (System.Exception ex)
{
Debug.LogError($"Connection failed: {ex.Message}");
isConnected = false;
}
}
public override void CloseInterface()
{
try
{
DisconnectFromServer();
isConnected = false;
Debug.Log("Interface disconnected");
}
catch (System.Exception ex)
{
Debug.LogError($"Disconnect error: {ex.Message}");
}
}
public override void CommunicationUpdate()
{
if (!isConnected) return;
try
{
// Read Unity signals and send to external system
var inputValues = ReadInputSignals();
SendToExternalSystem(inputValues);
// Read from external system and update Unity signals
var receivedValues = ReceiveFromExternalSystem();
WriteOutputSignals(receivedValues);
}
catch (System.Exception ex)
{
Debug.LogError($"Communication error: {ex.Message}");
isConnected = false;
}
}
public override bool GetCommunicationState()
{
return isConnected;
}
}
}Key characteristics:
Runs on Unity's main thread
Simple synchronous operation
Can cause Unity frame drops with slow communication
Suitable only for very fast protocols or testing
InterfaceThreadedBaseClass (Multi-threaded)
A more advanced approach that runs communication on a background thread:
Key characteristics:
Runs on background thread
Better performance than single-threaded approach
Manual thread management required
Complex error handling and synchronization
Prone to threading issues and race conditions
Legacy Signal Management
The legacy system used different methods for signal access:
Reading Input Signals (Legacy)
Writing Output Signals (Legacy)
Common Issues with Legacy System
Threading Problems
The legacy threaded approach was prone to various threading issues:
Manual Signal Management
Legacy interfaces required manual signal discovery and management:
No Automatic Reconnection
Legacy interfaces required manual reconnection logic:
Migration Guide to FastInterface
To migrate from legacy interfaces to FastInterface, follow these key steps:
1. Change Base Class
2. Replace Thread Management
3. Use Built-in Signal Management
4. Update Logging
5. Handle Properties Thread-Safely
Legacy Interface Examples
Here's a complete legacy interface example for reference:
Why FastInterface is Better
FastInterface addresses all the major problems of the legacy system:
Manual thread management
Automatic thread lifecycle management
Complex error handling
Built-in reconnection and error recovery
Threading bugs and race conditions
Thread-safe design patterns
Manual signal discovery
Automatic signal detection and management
No performance optimization
Built-in change detection and batching
Inconsistent implementations
Standardized architecture across all interfaces
Limited debugging tools
Comprehensive logging and state monitoring
Property synchronization issues
Automatic thread-safe property copying
See Also
Building Custom Interfaces - Modern FastInterface development guide
Interface Overview - Overview of all available interfaces
Signal Management - Understanding realvirtual signals
S7 Interface - Example of FastInterface implementation
Last updated