|
using UnityEngine; |
|
using UnityEditor; |
|
using System; |
|
|
|
namespace GatoMaterialPropertyDrawer |
|
{ |
|
internal class LineDecorator : MaterialPropertyDrawer |
|
{ |
|
private float spaceSize; |
|
|
|
public LineDecorator() |
|
{ |
|
spaceSize = 0; |
|
} |
|
|
|
public LineDecorator(float spaceSize) |
|
{ |
|
this.spaceSize = spaceSize; |
|
} |
|
|
|
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) |
|
{ |
|
GUILayout.Space(spaceSize); |
|
GUILayout.Box(string.Empty, GUILayout.ExpandWidth(true), GUILayout.Height(1)); |
|
GUILayout.Space(spaceSize); |
|
} |
|
} |
|
|
|
internal class SingleLineTexDrawer : MaterialPropertyDrawer |
|
{ |
|
public SingleLineTexDrawer() { } |
|
|
|
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) |
|
{ |
|
editor.TexturePropertySingleLine(label, prop); |
|
} |
|
} |
|
|
|
internal class FoldoutDecorator : MaterialPropertyDrawer |
|
{ |
|
public bool isFoldout = false; |
|
private bool useIndent = true; |
|
private string groupKeyword; |
|
|
|
public FoldoutDecorator(string groupKeyword) |
|
{ |
|
this.groupKeyword = groupKeyword; |
|
} |
|
|
|
public FoldoutDecorator(string groupKeyword, float isFoldout) |
|
{ |
|
this.groupKeyword = groupKeyword; |
|
this.isFoldout = Convert.ToBoolean(isFoldout); |
|
} |
|
|
|
public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) |
|
{ |
|
return EditorGUIUtility.singleLineHeight; |
|
} |
|
|
|
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) |
|
{ |
|
var style = new GUIStyle("ShurikenModuleTitle"); |
|
style.font = new GUIStyle(EditorStyles.label).font; |
|
style.border = new RectOffset(15, 7, 4, 4); |
|
style.fixedHeight = 22; |
|
style.contentOffset = new Vector2(20f, -2f); |
|
|
|
var rect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight); |
|
GUI.Box(rect, groupKeyword, style); |
|
|
|
var e = Event.current; |
|
|
|
var toggleRect = new Rect(rect.x + 4f, rect.y + 2f, 13f, 13f); |
|
if (e.type == EventType.Repaint) |
|
{ |
|
EditorStyles.foldout.Draw(toggleRect, false, false, isFoldout, false); |
|
} |
|
|
|
if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition)) |
|
{ |
|
isFoldout = !isFoldout; |
|
e.Use(); |
|
} |
|
|
|
var material = editor.target as Material; |
|
material.SetFloat("_IsFoldout"+groupKeyword, Convert.ToSingle(isFoldout)); |
|
} |
|
} |
|
|
|
internal class FoldoutGroupDrawer : MaterialPropertyDrawer |
|
{ |
|
private string groupKeyword; |
|
|
|
public FoldoutGroupDrawer(string groupKeyword) |
|
{ |
|
this.groupKeyword = groupKeyword; |
|
} |
|
|
|
public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) |
|
{ |
|
var material = editor.target as Material; |
|
if (!material.HasProperty("_IsFoldout" + groupKeyword)) return 0f; |
|
var isFoldout = Convert.ToBoolean(material.GetFloat("_IsFoldout" + groupKeyword)); |
|
|
|
if (!isFoldout) |
|
{ |
|
return 0f; |
|
} |
|
else |
|
{ |
|
return base.GetPropertyHeight(prop, label, editor); |
|
} |
|
} |
|
|
|
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) |
|
{ |
|
var material = editor.target as Material; |
|
if (!material.HasProperty("_IsFoldout" + groupKeyword)) return; |
|
var isFoldout = Convert.ToBoolean(material.GetFloat("_IsFoldout" + groupKeyword)); |
|
|
|
if (!isFoldout) |
|
{ |
|
return; |
|
} |
|
|
|
EditorGUI.indentLevel++; |
|
editor.DefaultShaderProperty(prop, label.text); |
|
EditorGUI.indentLevel--; |
|
} |
|
} |
|
} |