Fabric Manual How To'sHow to Post Events

How to Post Events

The game communicates with Fabric by posting events, these is the best and most efficient method for integrating Fabric in your games. An event based system allows:

  • Programmers can post events at any time without affecting the audio
  • Sound Designers create Fabric behaviors without requiring any code integration to start with
  • Sound Designers can change the hierarchy at any time without affecting the game code

 

Events are posted using the Event manager PostEvent functions,

Fabric.EventManager.Instance.PostEvent(....

 

Here are a number of example on how to post events from your game,

Example 1: Posting an event

		if(Input.GetKeyDown(KeyCode.Alpha1)) 
		{
			/////////////////////////////////////////////////////////////
			// This event by default will send the PlaySound EventAction.
			// The gameObject used is the one that has the FabricManager
            Fabric.EventManager.Instance.PostEvent("Simple");
		}

Example 2: Posting an event with a gameObject

		if(Input.GetKeyDown(KeyCode.Alpha2)) 
		{
			/////////////////////////////////////////////////////////////
			// This event by default will send the PlaySound EventAction.
			// The gameObject passed is used to track position and associated with an instance if max instances property is set
			
			Fabric.EventManager.Instance.PostEvent("Simple", gameObject);
		}

Example 3: Posting an event with a PlaySound action and a gameObject

		if(Input.GetKeyDown(KeyCode.Alpha3)) 
		{
			Fabric.EventManager.Instance.PostEvent("Simple", Fabric.EventAction.PlaySound, null, gameObject);
		}

Example 4: Posting a stop sound event action

      if(Input.GetKeyDown(KeyCode.Alpha4)) 
		{
			Fabric.EventManager.Instance.PostEvent("Simple", Fabric.EventAction.StopSound, null, gameObject);
		}
	

Example 5: Adding/Removing dynamic mixer preset

		if(Input.GetKeyDown(KeyCode.Alpha7)) 
		{
			// The event name must be "DynamicMixer"
			Fabric.EventManager.Instance.PostEvent ( "DynamicMixer", Fabric.EventAction.AddPreset, "MuteAll", null ) ;
		}
		// Example 8: Removing dynamic mixer preset
		else if(Input.GetKeyDown(KeyCode.Alpha8)) 
		{
			// The event name must be "DynamicMixer"
			Fabric.EventManager.Instance.PostEvent ( "DynamicMixer", Fabric.EventAction.RemovePreset, "MuteAll", null ) ;
		}