https://github.com/PixeyeHQ/Unity3d-Signals
Signals are in-memory publish/subscribe system and effectively replace Unity3d SendMessage
https://github.com/PixeyeHQ/Unity3d-Signals
Last synced: 6 months ago
JSON representation
Signals are in-memory publish/subscribe system and effectively replace Unity3d SendMessage
- Host: GitHub
- URL: https://github.com/PixeyeHQ/Unity3d-Signals
- Owner: PixeyeHQ
- License: mit
- Archived: true
- Created: 2018-09-11T09:55:49.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-24T05:57:23.000Z (over 6 years ago)
- Last Synced: 2024-05-21T14:05:33.341Z (over 1 year ago)
- Language: C#
- Size: 23.4 KB
- Stars: 31
- Watchers: 5
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Signals
[](https://gitter.im/ActorsFramework/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](https://discord.gg/ukhzx83)
[](https://twitter.com/dimmPixeye)
[](https://github.com/dimmpixeye/Actors-Unity3d-Framework/blob/master/LICENSE)## What are signals?
Signals allow you to communicate between decoupled parts of the game in Unity3d. The work with signals is very straightforward and can be shown in few steps:
* Step 1 - Write a signal. It's a plain struct.
```csharp
public struct SignalExampleDamage
{
public GameObject go;
public int damage;
}
```* Step 2 - Inherit from IRecieve a class where you want your signal to be received.
```csharp
public class ExampleClassReciever : MonoBehaviour, IReceive
{
private void OnEnable()
{
// Add this object to ProcessingSignals.Default
ProcessingSignals.Default.Add(this);
}private void OnDisable()
{
// Remove this object from ProcessingSignals.Default. You don't want this object to receive signals anymore!
ProcessingSignals.Default.Remove(this);
}
// This method will work when the signal is received.
public void HandleSignal(SignalExampleDamage arg)
{
Debug.Log(string.Format("{0} deals {1} damage!", arg.go, arg.damage));
}
}
```
* Step 3 - Create a new signal and send it through ProcessingSignals.Default```csharp
public class ExampleClass : MonoBehaviour {
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
// create new signal
SignalExampleDamage signalExample;
signalExample.damage = Random.Range(1, 10);
signalExample.go = gameObject;
// send signal to the processor
ProcessingSignals.Default.Send(signalExample);
}
}
}
```## Other content
* [Foldout groups](https://github.com/dimmpixeye/InspectorFoldoutGroup) - an extension to add foldable groups to the inspector.
* [ACTORS](https://github.com/dimmpixeye/Actors-Unity3d-Framework) - Unity3d data-driven framework I'm currently working on. Signals work as part of the framework.