Created
January 8, 2016 13:10
-
-
Save tsubaki/694731a19a189b093557 to your computer and use it in GitHub Desktop.
マテリアル拡張その4
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 UnityEngine; | |
using System.Collections; | |
using UnityEditor; | |
public class ExampleShaderInspector : MaterialEditor { | |
// マテリアルへのアクセス | |
Material material{ | |
get{ | |
return (Material)target; | |
} | |
} | |
[SerializeField] | |
Texture texture1, texture2; | |
static bool IsShowAdvancedSettings = false; | |
// Inspectorに表示される内容 | |
public override void OnInspectorGUI () | |
{ | |
// マテリアルを閉じた時に非表示にする | |
if (isVisible == false ) { return; } | |
// 入力内容が変更されたかチェック | |
EditorGUI.BeginChangeCheck (); | |
// InspectorのGUIを定義 | |
Texture mainTex = EditorGUILayout.ObjectField ( | |
"main texture", | |
material.GetTexture ("_MainTex"), | |
typeof(Texture), | |
false) as Texture; | |
// 更新されたら内容を反映 | |
if (EditorGUI.EndChangeCheck ()) { | |
material.SetTexture ("_MainTex", mainTex); | |
} | |
// 見たくない場合は非表示にする | |
IsShowAdvancedSettings = EditorGUILayout.Foldout (IsShowAdvancedSettings, "advanced"); | |
if (IsShowAdvancedSettings) { | |
// 1段下げてUIを表示 | |
EditorGUI.indentLevel = 1; | |
EditorGUILayout.HelpBox ("高度な設定云々", MessageType.Info); | |
EditorGUI.BeginChangeCheck (); | |
Color color = EditorGUILayout.ColorField ( | |
"color", | |
material.GetColor ("_Color")); | |
if (EditorGUI.EndChangeCheck ()) { | |
material.SetColor ("_Color", color); | |
} | |
EditorGUI.indentLevel = 0; | |
} | |
if (GUILayout.Button ("Set 1")) { | |
material.SetTexture ("_MainTex", texture1); | |
} | |
if (GUILayout.Button ("Set 2")) { | |
material.SetTexture ("_MainTex", texture2); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment