Last#
Collections / Last
Can Read
Cannot Write
Description#
The Game Object placed at the end of a collection
Parameters#
| Name | Description |
|---|---|
| Collection | The collection the Game Object is taken from |
Code#
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Pool;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Last")]
[Category("Collections/Last")]
[Description("The Game Object placed at the end of a collection")]
[Image(typeof(IconListLast), ColorTheme.Type.Teal)]
[Parameter("Collection", "The collection the Game Object is taken from")]
[Keywords("Tail", "End", "Bottom", "Index", "List", "Array")]
[Serializable]
public class TypeGameObjectCollectionLast : TypeGameObject
{
[SerializeField] private GetCollectionGameObjects m_Collection = new GetCollectionGameObjects();
public override GameObject Get(Args args)
{
List<GameObject> buffer = ListPool<GameObject>.Get();
try
{
this.m_Collection.Get(args, buffer);
GameObject result = buffer.Count > 0 ? buffer[^1] : null;
return result;
}
finally
{
ListPool<GameObject>.Release(buffer);
}
}
public override string ToString()
{
return $"Last of {this.m_Collection}";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}