Collection Item at Index#
Collections / Collection Item at Index
Can Read
Cannot Write
Description#
Reads the item of a collection found at the specified position as an Audio Resource
Parameters#
| Name | Description |
|---|---|
| Collection | The collection the item is taken from |
| Index | The zero based position of the item. Returns nothing when out of range |
Code#
using System;
using UnityEngine;
using UnityEngine.Audio;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Collection Item at Index")]
[Category("Collections/Item at Index")]
[Description("Reads the item of a collection found at the specified position as an Audio Resource")]
[Image(typeof(IconAudioClip), ColorTheme.Type.Yellow, typeof(BadgeIndex))]
[Parameter("Collection", "The collection the item is taken from")]
[Parameter("Index", "The zero based position of the item. Returns nothing when out of range")]
[Keywords("List", "Array", "Element", "Entry", "Position", "Get")]
[Serializable]
public class TypeAudioResourceCollectionIndex : TypeAudioResource
{
[SerializeField] private GetCollection m_Collection = new GetCollection();
[SerializeField] private GetInteger m_Index = new GetInteger(0);
public override AudioResource Get(Args args)
{
using Args scoped = Args.Get(args);
int count = this.m_Collection.Capture(scoped);
int index = this.m_Index.GetInt(args);
if (index < 0 || index >= count) return null;
return ArgsCollectionParameters.TryGetItem(this.m_Collection, scoped, index, out AudioResource item)
? item
: null;
}
public override string ToString()
{
return $"{this.m_Collection}[{this.m_Index}]";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}