Scripting API Reference | Common

10. Scripting API Reference | Common

The following are defined in the FMODUnity namespace:

  • EventReference Holds a reference to an FMOD Studio event.
  • ImportType Ways to import Banks into the project.
  • BankLoadType Automatic Bank loading options used by the RuntimeManger.
  • MeterChannelOrderingType Corresponds to the Metering Channel Order in FMOD Studio.
  • EmitterGameEvent The Unity Events used by the Studio Event Emitter, Global ParameterTrigger and Parameter Trigger components.
  • LoaderGameEvent The Unity Events used by the Bank Loader component.
  • EmitterRef Class used by the StudioParameterTrigger for StudioEventEmitter and Parameter info.
  • ParamRef Class used to store important Parameter information.
  • ThreadAffinityGroup Class for mapping the affinity of a group of thread types.
  • ThreadAffinity Enum for different thread affinities.
  • ThreadType Enum for various thread types.
  • EventLinkage Different ways to link an Event to an EventReference.

BankLoadType

Automatic Bank loading options used by the RuntimeManger.

C#

enum BankLoadType
{
    All,
    Specified,
    None
}
All
Loads all the Banks in the StreamingAssets folder, in no particular order.
Specified
Only loads the Banks that have been specified, in their current order.
None
Don't load any Banks at initialization, you are responsible for loading the Banks.

When using localization or DLC, the order in which Banks are loaded can be important.

See Also: Dialogue and Localization

EmitterGameEvent

The Unity Events used by the Studio Event Emitter, Global ParameterTrigger and Parameter Trigger components.

C#

enum EmitterGameEvent : int
{
    None,
    ObjectStart,
    ObjectDestroy,
    TriggerEnter,
    TriggerExit,
    TriggerEnter2D,
    TriggerExit2D,
    CollisionEnter,
    CollisionExit,
    CollisionEnter2D,
    CollisionExit2D,
    ObjectEnable,
    ObjectDisable,
    ObjectMouseEnter,
    ObjectMouseExit,
    ObjectMouseDown,
    ObjectMouseUp,
    UIMouseEnter,
    UIMouseExit,
    UIMouseDown,
    UIMouseUp
}
None
Default.
ObjectStart
MonoBehaviour.Start(), Start is called on the frame when a script is enabled just before any of the Update methods are called the first time.
ObjectDestroy
MonoBehaviour.OnDestroy(), OnDestroy occurs when a Scene or game ends and will only be called on game objects that have previously been active.
TriggerEnter
MonoBehaviour.OnTriggerEnter(), OnTriggerEnter is called when the GameObject collides with another GameObject.
TriggerExit
MonoBehaviour.OnTriggerExit(), OnTriggerExit is called when the Collider other has stopped touching the trigger.
TriggerEnter2D
MonoBehaviour.OnTriggerEnter2D, Sent when another object enters a trigger collider attached to this object (2D physics only).
TriggerExit2D
MonoBehaviour.OnTriggerExit2D, Sent when another object leaves a trigger collider attached to this object (2D physics only).
CollisionEnter
MonoBehaviour.OnCollisionEnter(), OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
CollisionExit
MonoBehaviour.OnCollisionExit(), OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.
CollisionEnter2D
MonoBehaviour.OnCollisionEnter2D(), Sent when an incoming collider makes contact with this object's collider (2D physics only).
CollisionExit2D
MonoBehaviour.OnCollisionExit2D(), Sent when a collider on another object stops touching this object's collider (2D physics only).
ObjectEnable
MonoBehaviour.OnEnable(), This function is called when the object becomes enabled and active.
ObjectDisable
MonoBehaviour.OnDisable(), This function is called when the behavior becomes disabled.
ObjectMouseEnter
MonoBehaviour.OnMouseEnter(), This function is called when the mouse enters the Collider.
ObjectMouseExit
MonoBehaviour.OnMouseExit(), This function is called when the mouse is not any longer over the Collider.
ObjectMouseDown
MonoBehaviour.OnMouseDown(), This function is called when the user has pressed the left mouse button while over the Collider.
ObjectMouseUp
MonoBehaviour.OnMouseUp(), this function is called when the user has released the left mouse button.
UIMouseEnter
OnPointerEnter() inherited from IPointerExitHandler, this function is called when the mouse overlaps the UI element.
UIMouseExit
OnPointerExit() inherited from IPointerExitHandler, this function is called when the mouse exits the UI element.
UIMouseDown
OnPointerDown() inherited from IPointerDownHandler, this function is called when the user has pressed the left mouse button while over the UI element.
UIMouseUp
OnPointerUp() inherited from IPointerUpHandler, this function is called when the user has released the left mouse button while over the UI element.

See Also: IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler

EmitterRef

Class used by the StudioParameterTrigger for StudioEventEmitter and Parameter info.

C#

class EmitterRef
{
    public StudioEventEmitter Target;
    public ParamRef[] Params;
}
Target
The StudioEventEmitter that is being used.
Params
List of parameter info for the targeted StudioEventEmitter.

See Also: StudioEventEmitter, ParamRef

EventLinkage

Different ways to link an Event to an EventReference.

C#

enum EventLinkage
{
    Path,
    GUID,
}
Path
For linking events via their path.
GUID
For linking events via their guids.

EventReference

Holds a reference to an FMOD Studio event.

At runtime only the event's GUID is stored, as this is the most efficient way to look up an event. In the editor, the event's path is stored as well, to enable a more user-friendly UI.

C#

[Serializable]
public struct EventReference
{
    public FMOD.GUID Guid;

#if UNITY_EDITOR
    public string Path;

    public static Func<string, FMOD.GUID> GuidLookupDelegate;

    public override string ToString()
    {
        return string.Format("{0} ({1})", Guid, Path);
    }

    public bool IsNull
    {
        get
        {
            return string.IsNullOrEmpty(Path) && Guid.IsNull;
        }
    }

    public static EventReference Find(string path)
    {
        if (GuidLookupDelegate == null)
        {
            throw new InvalidOperationException("EventReference.Find called before EventManager was initialized");
        }

        return new EventReference { Path = path, Guid = GuidLookupDelegate(path) };
    }
#else
    public override string ToString()
    {
        return Guid.ToString();
    }

    public bool IsNull
    {
        get
        {
            return Guid.IsNull;
        }
    }
#endif
}
Guid
GUID of the event.
Path
Path of the event. Only defined in the editor.
GuidLookupDelegate
Callback used to search for Guid. Used inside the Find method.
Find(string path)

Finds an event by path and returns an EventReference that points to it. Only defined in the editor.

To define a default value for an EventReference field, call Find from your MonoBehaviour's Reset method:

#if UNITY_EDITOR
    void Reset()
    {
        eventReference = FMODUnity.EventReference.Find("event:/music/music");
    }
#endif

Path lookups only succeed if the strings bank is loaded.

ImportType

Ways to import Banks into the project.

C#

enum ImportType
{
    StreamingAssets,
    AssetBundle,
}
StreamingAssets
Import the banks to the StreamingAssets folder.
AssetBundle
Store the banks as binary data, in .asset files, in the directory specified in FMOD Asset Folder.

See Also: AssetBundles & Addressables

LoaderGameEvent

The Unity Events used by the Bank Loader component.

C#

enum LoaderGameEvent : int
{
    None,
    ObjectStart,
    ObjectDestroy,
    TriggerEnter,
    TriggerExit,
    TriggerEnter2D,
    TriggerExit2D,
    ObjectEnable,
    ObjectDisable,
}
None
Default.
ObjectStart
MonoBehaviour.Start(), Start is called on the frame when a script is enabled just before any of the Update methods are called the first time.
ObjectDestroy
MonoBehaviour.OnDestroy(), OnDestroy occurs when a Scene or game ends and will only be called on game objects that have previously been active.
TriggerEnter
MonoBehaviour.OnTriggerEnter(), OnTriggerEnter is called when the GameObject collides with another GameObject.
TriggerExit
MonoBehaviour.OnTriggerExit(), OnTriggerExit is called when the Collider other has stopped touching the trigger.
TriggerEnter2D
MonoBehaviour.OnTriggerEnter2D, Sent when another object enters a trigger collider attached to this object (2D physics only).
TriggerExit2D
MonoBehaviour.OnTriggerExit2D, Sent when another object leaves a trigger collider attached to this object (2D physics only).
ObjectEnable
MonoBehaviour.OnEnable(), This function is called when the object becomes enabled and active.
ObjectDisable
MonoBehaviour.OnDisable(), This function is called when the behaviour becomes disabled.

MeterChannelOrderingType

Corresponds to the Metering Channel Order in FMOD Studio.

C#

enum MeterChannelOrderingType
{
    Standard,
    SeparateLFE,
    Positional
}
Standard
(L, R, C, LFE, LS, RS, LSR, RSR, TFL, TFR, TBL, TBR)
SeparateLFE
(L, R, LS, RS, LSR, RSR, TFL, TFR, TBL, TBR, LFE)
Positional
(LSR, LS, L, C, R, RS, RSR, TBL, TFL, TFR, TBR, LFE)

See Also: Metering Channel Order.

ParamRef

Class used to store important Parameter information.

C#

class ParamRef
{
    public string Name;
    public float Value;
    public FMOD.Studio.PARAMETER_ID ID;
}
Name
Name of the parameter.
Value
The parameter value.
ID
Parameter identifier.

ParamRef is used by various classes in the integration, such as RuntimeManager, RuntimeManager, and StudioEventEmitter, to cache retrieved Parameter information that is being used by those classes.

ParamRef can also be used as an attribute on string properties to hold the path of a Global Parameter. For more information, see the Global Parameters section of the Scripting API Reference.

While both can be used to store a reference to their respective objects, ParamRef cannot be assigned via the Unity Inspector window in the same manner that EventReference can be. This is because FMOD for Unity generates and stores cached editor-only data for events based on your FMOD Studio project's banks, but does not do the same for parameters.

See Also: FMOD_STUDIO_PARAMETER_ID.

ThreadAffinity

Enum for different thread affinities.

C#

[Flags]
public enum ThreadAffinity : uint
{
    Any = 0,
    Core0 = 1 << 0,
    Core1 = 1 << 1,
    Core2 = 1 << 2,
    Core3 = 1 << 3,
    Core4 = 1 << 4,
    Core5 = 1 << 5,
    Core6 = 1 << 6,
    Core7 = 1 << 7,
    Core8 = 1 << 8,
    Core9 = 1 << 9,
    Core10 = 1 << 10,
    Core11 = 1 << 11,
    Core12 = 1 << 12,
    Core13 = 1 << 13,
    Core14 = 1 << 14,
    Core15 = 1 << 15,
}

See Also: FMOD_THREAD_TYPE, Threads and Thread Safety, FMOD Thread Types

ThreadAffinityGroup

Class for mapping the affinity of a group of thread types.

C#

[Serializable]
public class ThreadAffinityGroup
{
    public List<ThreadType> threads = new List<ThreadType>();
    public ThreadAffinity affinity = ThreadAffinity.Any;

    public ThreadAffinityGroup()
    {
    }

    public ThreadAffinityGroup(ThreadAffinityGroup other)
    {
        threads = new List<ThreadType>(other.threads);
        affinity = other.affinity;
    }

    public ThreadAffinityGroup(ThreadAffinity affinity, params ThreadType[] threads)
    {
        this.threads = new List<ThreadType>(threads);
        this.affinity = affinity;
    }
}

See Also: ThreadAffinity, ThreadType, FMOD_THREAD_TYPE, Threads and Thread Safety, FMOD Thread Types

ThreadType

Enum for various thread types.

C#

public enum ThreadType
{
    Mixer,
    Feeder,
    Stream,
    File,
    Nonblocking,
    Record,
    Geometry,
    Profiler,
    Studio_Update,
    Studio_Load_Bank,
    Studio_Load_Sample,
    Convolution_1,
    Convolution_2,
}

See Also: FMOD_THREAD_TYPE, Threads and Thread Safety, FMOD Thread Types