Class AudioPlayerManager
Handles managing BackgroundAudio.Players, including
generating and auto-removing unused players. Generally used like
a
Namespace: OmiyaGames.Audio
Assembly: cs.temp.dll.dll
Syntax
public class AudioPlayerManager : MonoBehaviour
Remarks
Copyright (c) 2022 Omiya Games Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
| Revision | Description |
|---|---|
|
Version: 1.0.0 Date: 5/22/2022 Author: Taro Omiya | Initial verison. |
Properties
GarbageCollectAfterSeconds
Gets or sets how long an idle (basically, stopped) BackgroundAudio.Player remains in memory before being auto-deleted by this manager.
Declaration
public float GarbageCollectAfterSeconds { get; set; }
Property Value
| Type | Description |
|---|---|
| Single |
Methods
CreateManager(Transform, String)
Creates a new
Declaration
public static AudioPlayerManager CreateManager(Transform parent, string gameObjectName)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | parent | The |
| String | gameObjectName | The name of the new |
Returns
| Type | Description |
|---|---|
| AudioPlayerManager | A new instance of AudioPlayerManager,
attached by a new |
CreatePlayerCoroutine(AssetRef<BackgroundAudio>, Action<BackgroundAudio.Player>)
Starts a coroutine that generates a new
BackgroundAudio.Player from audio.
Declaration
public IEnumerator CreatePlayerCoroutine(AssetRef<BackgroundAudio> audio, Action<BackgroundAudio.Player> onPlayerCreated = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AssetRef<BackgroundAudio> | audio | The audio file that generates players. |
| Action<BackgroundAudio.Player> | onPlayerCreated | Delegate that triggers at the end of this coroutine. Argument will be set to the newly generated BackgroundAudio.Player. |
Returns
| Type | Description |
|---|---|
| IEnumerator | A coroutine that creates a new BackgroundAudio.Player. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If |
GarbageCollect(AudioPlayerManager.AudioState)
destroyPlayersWithStates.
Declaration
public void GarbageCollect(AudioPlayerManager.AudioState destroyPlayersWithStates = AudioPlayerManager.AudioState.Stopped)
Parameters
| Type | Name | Description |
|---|---|---|
| AudioPlayerManager.AudioState | destroyPlayersWithStates | The state of BackgroundAudio.Players to destroy. |
GetPlayer(AssetRef<BackgroundAudio>, AudioPlayerManager.AudioState)
Gets the first BackgroundAudio.Player associated with an audio asset at a specific state.
Declaration
public BackgroundAudio.Player GetPlayer(AssetRef<BackgroundAudio> audio, AudioPlayerManager.AudioState playerState = AudioPlayerManager.AudioState.All)
Parameters
| Type | Name | Description |
|---|---|---|
| AssetRef<BackgroundAudio> | audio | The audio file that generates players. |
| AudioPlayerManager.AudioState | playerState | Filters BackgroundAudio.Players based on state. |
Returns
| Type | Description |
|---|---|
| BackgroundAudio.Player | The first BackgroundAudio.Player that plays
the audio clips from |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If |
See Also
GetPlayers(AssetRef<BackgroundAudio>, AudioPlayerManager.AudioState)
Gets a list of players associated with audio,
filtered by playerState. This method creates
a new
Declaration
public List<BackgroundAudio.Player> GetPlayers(AssetRef<BackgroundAudio> audio, AudioPlayerManager.AudioState playerState = AudioPlayerManager.AudioState.All)
Parameters
| Type | Name | Description |
|---|---|---|
| AssetRef<BackgroundAudio> | audio | The audio file that generates players. |
| AudioPlayerManager.AudioState | playerState | Filters BackgroundAudio.Players based on state. |
Returns
| Type | Description |
|---|---|
| List<BackgroundAudio.Player> | List of BackgroundAudio.Players associated with
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If |
See Also
GetPlayers(AssetRef<BackgroundAudio>, AudioPlayerManager.AudioState, in List<BackgroundAudio.Player>)
Gets a list of players associated with audio,
filtered by playerState. This method recycles
a
Declaration
public void GetPlayers(AssetRef<BackgroundAudio> audio, AudioPlayerManager.AudioState playerState, in List<BackgroundAudio.Player> returnPlayers)
Parameters
| Type | Name | Description |
|---|---|---|
| AssetRef<BackgroundAudio> | audio | The audio file that generates players. |
| AudioPlayerManager.AudioState | playerState | Filters BackgroundAudio.Players based on state. |
| List<BackgroundAudio.Player> | returnPlayers | The list to append BackgroundAudio.Players to. Effectively the return variable. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If |
IsPlayerMatchingState(BackgroundAudio.Player, AudioPlayerManager.AudioState)
Checks if an BackgroundAudio.Player is at a state that matches
any of the flags in state.
Declaration
public static bool IsPlayerMatchingState(BackgroundAudio.Player player, AudioPlayerManager.AudioState state)
Parameters
| Type | Name | Description |
|---|---|---|
| BackgroundAudio.Player | player | The player to check the state. |
| AudioPlayerManager.AudioState | state | Flags to compare the state of the |
Returns
| Type | Description |
|---|---|
| Boolean | true if the
is in a state that matches any one of flags in
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If |