Random Sprite#
Random / Random Sprite
Can Read
Cannot Write
Description#
Picks a random Sprite from the list
Parameters#
| Name | Description |
|---|---|
| Sprites | The list of assets one of them is picked from |
Code#
using System;
using System.Collections.Generic;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Random Sprite")]
[Category("Random/Sprite")]
[Description("Picks a random Sprite from the list")]
[Image(typeof(IconSprite), ColorTheme.Type.Purple, typeof(BadgeDice))]
[Parameter("Sprites", "The list of assets one of them is picked from")]
[Keywords("Dice", "Constant", "Random", "List", "Array", "Any", "Choose")]
[Serializable]
public class TypeSpriteRandom : TypeSprite
{
[SerializeField] private List<Sprite> m_Sprites = new List<Sprite>();
public override Sprite GetPreview(GameObject source) => this.Pick();
public override Sprite Get(Args args) => this.Pick();
private Sprite Pick()
{
int count = this.m_Sprites.Count;
return count > 0 ? this.m_Sprites[UnityEngine.Random.Range(0, count)] : null;
}
public override string ToString()
{
return $"Random Sprite ({this.m_Sprites.Count})";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnEditorChange;
}
}