Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ReInitShaderFromEditor : MonoBehaviour {
- public Renderer[] renderers;
- public Material[] materials;
- public string[] shaders;
- private static ReInitShaderFromEditor _instance;
- public static ReInitShaderFromEditor Instance
- {
- get
- {
- if (_instance == null)
- _instance = FindObjectOfType<ReInitShaderFromEditor> ();
- if (_instance == null)
- _instance = new GameObject ("_ReInitShaderFromEditor").AddComponent<ReInitShaderFromEditor> ();
- return _instance;
- }
- }
- void Awake()
- {
- if (_instance != null && _instance != this){
- Destroy (this.gameObject);
- return;
- } else if(_instance == null)
- _instance = this;
- }
- public void ReInit (Transform tr)
- {
- renderers = tr.GetComponentsInChildren<Renderer>(true);
- foreach(var rend in renderers)
- {
- materials = rend.sharedMaterials;
- shaders = new string[materials.Length];
- for( int i = 0; i < materials.Length; i++)
- {
- shaders[i] = materials[i].shader.name;
- }
- for( int i = 0; i < materials.Length; i++)
- {
- materials[i].shader = Shader.Find(shaders[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement