44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
#if UNITY_EDITOR
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEditor.Experimental.SceneManagement;
|
|
#endif
|
|
|
|
public sealed class SpriteRendererSpriteSwapper : MonoBehaviour {
|
|
|
|
#if UNITY_EDITOR
|
|
[SerializableAttribute]
|
|
public sealed class SwapInfo {
|
|
[SerializeField]
|
|
private Sprite swapTargetSprite = default;
|
|
public Sprite SwapTargetSprite {
|
|
get{ return swapTargetSprite; }
|
|
}
|
|
[SerializeField]
|
|
private Sprite swapSprite = default;
|
|
public Sprite SwapSprite {
|
|
get{ return swapSprite; }
|
|
}
|
|
}
|
|
|
|
[SerializeField]
|
|
private SwapInfo[] swapInfoArray = new SwapInfo[1];
|
|
|
|
[ContextMenu("SwapSprite")]
|
|
private void SwapSprite(){
|
|
foreach(var info in swapInfoArray){
|
|
if(info.SwapTargetSprite == null) return ;
|
|
if(info.SwapSprite == null) return ;
|
|
|
|
transform.FindAllChildrensComponent<SpriteRenderer>(sr => {
|
|
if(sr.sprite == info.SwapTargetSprite){
|
|
sr.sprite = info.SwapSprite;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
#endif
|
|
}
|