This is a small unity package I made which offers many possibilities of use. It let you use the Unity Editor scene hierarchy to create an electronical signal that goes from children to their parent. You can activate everything you want regarding on condition connectors in the hierarchy. Let's have a small example: Imagine you have an AND connector that has two children. The AND connector will only be activated if both the children are. Of course for this to work the children you want to act as signal transmitters must have a script component derived from the BaseConnector class attached to them. This system is cost-free. Any signal that changes will update all its parents the same game frame. The package comes with prefabs, that are just empty gameobjects with one of the different condition connectors script attached to it. Of course they are juste example, and the different script can be attached to any object you want.
|
How to use it
Each connector, that means each gameobject you want to use in an electronical circuit, must have a script component that derives from the BaseConnector script. At any time, such a gameobject can know if its signal is activated by accessing the connector component and by reading its Activated property which is a boolean value. Besides, everytime the signal changes, the gameobject receives a message that calls any OnReceiveFromConnector(bool b) methods he has on its scripts. The boolean b tells us if the signal is on or off. So there is no need for you to check the Activated property at each frame since every time this property changes you get a call of the OnReceiveFromConnector(bool b) function.
Additional feature
Any connector comes with an empty public gameobject property that you can set in the editor. You can put here any gameobject you want. This gameobject will now receive the OnReceiveFromConnector(bool b) mehtod call too. It can be usefull when you don't want a gameobject to be part of a connector hierarchy but still have notification of changes from one of them.
Loop: a special connector
If you look in the package there is a connector called LoopConnector, and if you look on any connector, you can see a public list of loop connectors you can set in the editor. This connector lets you make loop on your circuit and also let you send a signal received on a specific circuit to another circuit. To do so, you just have to add the Loop connector gameobject to the loop connectors list from where you want the signal to be sent. The signal will be received by the loop connector and will be its signal value.
Input Connector
Input connector are connectors that don't process their children signals. By default, if you create a new connector, it will not take into account its children and will be an input controller. For example, the loop connector is an input connector. To process children signals, you just have to override the OnReceiveFromChild(bool activate) method in your script.
What can I do with this ?
I think you can do lots of thing with this package. Here are some ideas in which I would use it:
- Button system to have a complexe system to open doors, switching lights, etc...
- Dialog system to unlock dialog options
- Quest system to make multiple way to achieve a same quest
- Crafting system to have complex recipes
- Simply for an electronical circuit and to be as creative as some minecraft redstones players !
Code overview
This is the base class for connectors.