Class AudioHistory
Retains a history of BackgroundAudio, capped by MaxCapacity.
Namespace: OmiyaGames.Audio
Assembly: cs.temp.dll.dll
Syntax
public class AudioHistory : IReadOnlyList<AssetRef<BackgroundAudio>>
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: 6/17/2022 Author: Taro Omiya | Initial verison. |
Constructors
AudioHistory(Int32)
Constructs a new history with a specified capacity.
Declaration
public AudioHistory(int maxCapacity = 100)
Parameters
Type | Name | Description |
---|---|---|
Int32 | maxCapacity | The maximum capacity of the history. |
Fields
DEFAULT_HISTORY_SIZE
Default history size.
Declaration
public const int DEFAULT_HISTORY_SIZE = 100
Field Value
Type | Description |
---|---|
Int32 |
Properties
Count
How many entries are currently in the history.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
Item[Int32]
Gets a specific audio clip, index
place
from oldest entry in the history.
Declaration
public AssetRef<BackgroundAudio> this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | Placement from oldest entry, up. |
Property Value
Type | Description |
---|---|
AssetRef<BackgroundAudio> | The BackgroundAudio, |
Remarks
This property's performance is O(n). It does attempt to iterate either in chronological or reverse order, whichever is faster. This does make getting the newest or oldest entries a O(1) operation.
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | If |
MaxCapacity
Gets or sets the maximum capacity of this history.
Declaration
public int MaxCapacity { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
Newest
Grabs the newest entry in the history.
Declaration
public AssetRef<BackgroundAudio> Newest { get; }
Property Value
Type | Description |
---|---|
AssetRef<BackgroundAudio> |
Oldest
Grabs the oldest entry in the history.
Declaration
public AssetRef<BackgroundAudio> Oldest { get; }
Property Value
Type | Description |
---|---|
AssetRef<BackgroundAudio> |
Methods
Add(in AssetRef<BackgroundAudio>)
Adds an asset to the history as the newest entry.
Declaration
public void Add(in AssetRef<BackgroundAudio> asset)
Parameters
Type | Name | Description |
---|---|---|
AssetRef<BackgroundAudio> | asset | Newest asset to add to the history. |
Clear()
Empties the history.
Declaration
public void Clear()
Contains(in AssetRef<BackgroundAudio>)
Indicates if a specific asset is already in the history.
Declaration
public bool Contains(in AssetRef<BackgroundAudio> asset)
Parameters
Type | Name | Description |
---|---|---|
AssetRef<BackgroundAudio> | asset | The audio clip to search in the history. |
Returns
Type | Description |
---|---|
Boolean | true if asset is in the history; false, otherwise. |
GetEnumerator()
Declaration
public IEnumerator<AssetRef<BackgroundAudio>> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<AssetRef<BackgroundAudio>> |
GetEnumerator(Boolean)
Gets an iterator in either chronological or reverse history order.
Declaration
public IEnumerator<AssetRef<BackgroundAudio>> GetEnumerator(bool newestToOldest)
Parameters
Type | Name | Description |
---|---|---|
Boolean | newestToOldest | If true, enumerates the history in reverse order. Otherwise, iteraates in the chronological order. |
Returns
Type | Description |
---|---|
IEnumerator<AssetRef<BackgroundAudio>> | Iterator through the whole history. |
RemoveNewest()
Removes the newest entry in the history.
Declaration
public void RemoveNewest()
Remarks
Does nothing if history is empty.
RemoveOldest()
Removes the oldest entry in the history.
Declaration
public void RemoveOldest()
Remarks
Does nothing if history is empty.
Events
OnAfterAdd
Event called by Add(in AssetRef<BackgroundAudio>), after a new asset has been added to the history.
Declaration
public event AudioHistory.OnAdd OnAfterAdd
Event Type
Type | Description |
---|---|
AudioHistory.OnAdd |
OnAfterClear
Event called by Clear(), after the history has been cleared.
Declaration
public event Action<AudioHistory> OnAfterClear
Event Type
Type | Description |
---|---|
Action<AudioHistory> |
OnAfterRemove
Event called by RemoveOldest() and RemoveNewest(), after an asset has been removed from the history.
Declaration
public event AudioHistory.OnRemove OnAfterRemove
Event Type
Type | Description |
---|---|
AudioHistory.OnRemove |
Remarks
This event does not get called by Clear(). Use OnAfterClear to listen to that event.
OnBeforeAdd
Event called by Add(in AssetRef<BackgroundAudio>), before a new asset is added to the history.
Declaration
public event AudioHistory.OnAdd OnBeforeAdd
Event Type
Type | Description |
---|---|
AudioHistory.OnAdd |
OnBeforeClear
Event called by Clear(), before the history is cleared.
Declaration
public event Action<AudioHistory> OnBeforeClear
Event Type
Type | Description |
---|---|
Action<AudioHistory> |
OnBeforeRemove
Event called by RemoveOldest() and RemoveNewest(), before an asset is removed from the history.
Declaration
public event AudioHistory.OnRemove OnBeforeRemove
Event Type
Type | Description |
---|---|
AudioHistory.OnRemove |
Remarks
This event does not get called by Clear(). Use OnBeforeClear to listen to that event.