Last active
May 17, 2017 08:06
-
-
Save tsubaki/adf522126051dd227f36fe3830a67e8a to your computer and use it in GitHub Desktop.
シェーダーを実行時に更新
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
#if UNITY_EDITOR | |
using System.Linq; | |
#endif | |
public class UpdateShader : MonoBehaviour { | |
[SerializeField] Material[] mats; | |
#if UNITY_EDITOR | |
void Awake () { | |
// 登録したマテリアルのシェーダーを更新 | |
foreach (var mat in mats) { | |
mat.shader = Shader.Find (mat.shader.name); | |
} | |
} | |
void Reset () | |
{ | |
// シーン内のマテリアルを収集する | |
List<Material> matList = new List<Material> (); | |
matList.AddRange( GameObject.FindObjectsOfType<MeshRenderer> ().SelectMany( c => c.sharedMaterials) ); | |
matList.AddRange (GameObject.FindObjectsOfType<SkinnedMeshRenderer> ().SelectMany (c => c.sharedMaterials)); | |
mats = matList.Distinct().ToArray (); | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment