Singularity/Library/PackageCache/com.unity.2d.animation@7.0.10/Samples~/AnimationSamples/5 SpriteSwap/Scripts/Runtime/SwapFullSkin.cs

39 lines
1.1 KiB
C#
Raw Permalink Normal View History

2024-05-06 14:45:45 -04:00
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D.Animation;
using UnityEngine.UI;
namespace Unity.U2D.Animation.Sample
{
public class SwapFullSkin : MonoBehaviour
{
public SpriteLibraryAsset[] spriteLibraries;
public SpriteLibrary spriteLibraryTarget;
public Dropdown dropDownSelection;
// Start is called before the first frame update
void Start()
{
UpdateSelectionChoice();
}
void OnDropDownValueChanged(int value)
{
spriteLibraryTarget.spriteLibraryAsset = spriteLibraries[value];
}
internal void UpdateSelectionChoice()
{
dropDownSelection.ClearOptions();
var options = new List<Dropdown.OptionData>(spriteLibraries.Length);
for (int i = 0; i < spriteLibraries.Length; ++i)
{
options.Add(new Dropdown.OptionData(spriteLibraries[i].name));
}
dropDownSelection.options = options;
dropDownSelection.onValueChanged.AddListener(OnDropDownValueChanged);
}
}
}