MolodoyDEV - Developer of indie games





My projects





The game - SysAdmin Odyssey. Back to the office

Telegram

sysadmproject.main@gmail.com

Steam page

YouTube





Runtime physical wire system

Links

Telegram: https://t.me/your_ai_assistant

Gmail: sysadmproject.main@gmail.com

Asset store: https://assetstore.unity.com/packages/slug/315989

Video tutorial:


Introduction

This tool will allow you to create realistic wires at runtime and connect them to various types of sockets and plugs that you create yourself. You can change the length of the wires, attach the wires to the intermediate points and transfer data between the connected sockets. Models and textures are not included in this package! The project is completely customizable. You can add your own models and modify the source code to suit your needs. An example of using this tool from the game "SysAdmin Odyssey. Back to the office": https://youtu.be/C1Uoz_lFK5s

Demo scene

In the demo scene, you can test the operation of the tool in different situations. https://youtu.be/DIL7VQHhtoo Various types of cables (multicolored spheres) are placed on the scene. By going to the sphere and clicking the left mouse button, you select this cable to connect. You can also create bundles of different cables. Each cable has different types of plugs that match the same type of sockets. One cable may have different plugs at different ends of the cable. After you have selected the cable, you can point to the socket of the desired type (color) and left-click to create a connection. The socket will be highlighted if at least one of the free cable plugs matches the type of this socket. Sockets can support different types of plugs, but a plug can only have one type. Imagine a USB socket, you can physically insert USB 2.0, USB 3.0, and USB 3.1 plugs into it. How it works: You create a prefab of a cable by analogy with "ConnectionSystem > Prefabs > Cord > ConnectedCord*" Then you create a prefab of a coil of wires in which you put one or more prefabs of a cable. Now, when you select a coil of wires and point at the socket, the system checks whether this cable can be connected to this socket and, if so, highlights the socket. You can cancel the connection by pressing the ESC button or disconnect the connected cable by left-clicking on the socket.

Get started

Preparation. Important! The following parameters must be set for the correct operation of the system: "Project Settings > Physics > Default Solver Iterations": Set between 10 to 20. In the demo scene, it's 15. Create a new layer, example: "wire". Go to "Project Settings > Physics > Layer Collision Matrix" > disables collisions of the layer with itself. Set the layer "wire" in the prefabs Segment, WireBuilderRuntime and all prefabs under "ConnectionSystem > Prefabs > Cord" folder . Change childrens as well. If you use URP add layer "wire" to URP Renderer Data > Filtering. Create you own wires and sockets prefabs based on "ConnectionSystem > Prefabs". Configure parameters of WiredPhysicalPort, CoilOfCord and ConnectedCordPhysics scripts on prefabs.

API references


Connected cord

public abstract class ConnectedCordBase : MonoBehaviour

A basic abstract class that defines an interface for connecting cables to sockets and visualizing this process. Uses ConnectorProperty to store information for each side of the cable.

public class ConnectedCordPhysics : ConnectedCordBase

Implementation of a physically correct cable. Uses ConnectedCordHelper to control the connection creation process.

public class ConnectorProperty : ConnectedCordBase

Stores cable plugs settings such as Transform, Renderer, plug type and format

public class ConnectedCordHelper : MonoBehaviour

Responds to user input and manages the process of creating a connection, changing the length of the cable, and visualizing. Controls the length of the cable and allows you to fix the cable at intermediate points. Uses the WireControllerRuntime to control the connected cable

public class WireControllerRuntime : MonoBehaviour

Controls the behavior of the connected cable. Allows you to add and remove segments, as well as freeze the physics of the cable. Uses TubeRenderer to render the cable.

public class TubeRenderer : MonoBehaviour

Responsible for rendering and rebuilding the mesh of the cable.

Coil of cord

public class CoilOfCord : MonoBehaviour

Provides an interface for creating a ConnectedCordBase instance from a prefab. Sets basic parameters such as cable length and number of uses. It is usually used by the player to create cables.

public class UniversalCoilOfCord : CoilOfCord

Expands the capabilities of CoilOfCord by allowing you to set several prefabs for wires, from which the appropriate one for connection will be selected. Uses CordConnectedPrefabParams to store the configuration of each prefab.

public class CordConnectedPrefabParams

Stores the configuration of the ConnectedCordBase prefab.

Physical sockets

public abstract class PhysicalPortSimple : MonoBehaviour, IHaveSnapPoint

The base class is a simple implementation of a physical socket with all the necessary interfaces. Defines the plug format - ConnectorFormat. It has an interface implementation for the correct placement of plugs in the sockets - IHaveSnapPoint.

public class WiredPhysicalPort : PhysicalPortSimple

A specific implementation of the physical socket where the cables are connected. Defines the types of plug that can be connected to this socket - List.

Selection

public class Selectable : MonoBehaviour

Implements an interface for creating a semi-transparent model on top of an existing one while maintaining its mesh. It is used to create the effect of highlighting and highlighting an object.

public class SelectionMaterials : SharedResourcesBase

Provides easy access to materials stored in the Resources folder.

public class SelectionProperties

Stores pre-prepared materials and parameters for selecting objects.

Utils

public class ConnectionSnapPoint : MonoBehaviour

It is an anchor point that allows you to correctly position objects relative to each other.

public abstract class SharedResourcesBase<Property_T> where Property_T : Object

A universal class that allows you to conveniently describe and retrieve objects that are stored in the Resources folder.

public interface IHaveSnapPoint

An interface that says that this object can be positioned relative to another object.

public enum WiredConnectorType

The type of wired connection. You can add your own types to use when configuring your sockets and plugs.

public enum ConnectorFormat

Plug format. It's always Mom or Dad. The plugs can only be connected to sockets of a different type.