using Sirenix.OdinInspector; using System.Collections.Generic; using UnityEditor; using UnityEngine; using UnityEngine.UI; [ExecuteAlways] public class ImagesPrevSetter : MonoBehaviour { #if UNITY_EDITOR public Sprite[] sprites; public List images; public Image prefab; public int max; [PropertyRange(0, "max")] public int index; public int last; [ExecuteAlways] private void Update() { max = this.images.Count - 1; if (index == last) { return; } last = index; foreach (var item in images) { item.gameObject.SetActive(false); } images[index].gameObject.SetActive(true); } [Button] [ContextMenu("SetValue")] private void SetValue() { var items = this.images.ToArray(); foreach (var item in items) { if (item == true) { DestroyImmediate(item); } } images.Clear(); prefab.gameObject.SetActive(true); foreach (var item in sprites) { var go = UnityEditor.Editor.Instantiate(prefab, this.transform); go.sprite = item; go.name = item.name; images.Add(go); EditorUtility.SetDirty(go); } prefab.gameObject.SetActive(false); } #endif }