using UnityEngine;
using UnityEngine.UI;
using System;

public class ShaderResetter : MonoBehaviour {

	[SerializableAttribute]
	public struct ResetTarget{
		public string shaderName;
		public Renderer[] renderers;
		public Image[] images;
	}
	[SerializeField]
    private ResetTarget[] resetTargets = default;
	[HideInInspector, SerializeField]
	private bool reseted = false;

    void Awake(){
		if(!reseted){
			Reset();
		}
		Destroy(this);
    }

	public void Reset(){
		foreach(ResetTarget target in resetTargets){
	        Shader shader = Shader.Find(target.shaderName);
			if(shader != null){
				foreach(Renderer renderer in target.renderers){
					renderer.sharedMaterial.shader = shader;
				}
				foreach(Image image in target.images){
					image.material.shader = shader;
				}
			}else{
				Debug.LogWarning(target.shaderName + " not exists shader.");
			}
		}
		reseted = true;
	}
}
