Skip to content
This repository has been archived by the owner on May 24, 2020. It is now read-only.

PixeyeHQ/Unity3d-Signals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Signals

Join the chat at https://gitter.im/ActorsFramework/Lobby Join the chat at https://discord.gg/ukhzx83 Twitter Follow 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.
 public struct SignalExampleDamage
    {
        public GameObject go;
        public int damage;
    }
  • Step 2 - Inherit from IRecieve a class where you want your signal to be received.
public class ExampleClassReciever : MonoBehaviour, IReceive<SignalExampleDamage>
    {
    
        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
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 - an extension to add foldable groups to the inspector.
  • ACTORS - Unity3d data-driven framework I'm currently working on. Signals work as part of the framework.

About

Signals are in-memory publish/subscribe system and effectively replace Unity3d SendMessage

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages