Skip to content

ceyhuntasci/MasonsLittleUnityMessagingSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Mason's Little Unity Messaging System

This little framework lets scripts communicate between themselves easily. Create your game events and make every script handle their actions.

Usage

  • Create Data Models:
   public class OnGameStartModel : Model
   {
       public string GameMode;
       public int PlayerCount;

       public OnGameStartModel(string gameMode, int playerCount)
       {
           GameMode = gameMode;
           PlayerCount = playerCount;
       }
   }
  • Subscribe & Unsubscribe to Message Channels
   void OnEnable()
   {
       EventManager.Subscribe("OnGameStart", OnGameStart);
   }
   void OnDisable()
   {
       EventManager.Unsubscribe("OnGameStart", OnGameStart);
   }
   void OnGameStart(Model obj)
   {
       //Bind data first
       OnGameStartModel model = (OnGameStartModel)obj;

       Debug.LogFormat("Game Mode is {0} with {1} players", model.GameMode, model.PlayerCount);
   }
  • Trigger Events
   EventManager.TriggerEvent("OnGameStart", new OnGameStartModel("Multiplayer", 2));

Releases

No releases published

Packages

No packages published

Languages