-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathMaterialMinMaxSliderDrawer.cs
More file actions
54 lines (46 loc) · 1.67 KB
/
MaterialMinMaxSliderDrawer.cs
File metadata and controls
54 lines (46 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using UnityEditor;
using UnityEngine;
namespace Toolbox.Editor.Drawers
{
using Toolbox.Editor.Internal;
public class MaterialMinMaxSliderDrawer : BaseMaterialPropertyDrawer
{
private readonly float minValue;
private readonly float maxValue;
public MaterialMinMaxSliderDrawer(float minValue, float maxValue)
{
this.minValue = minValue;
this.maxValue = maxValue;
}
protected override float GetPropertyHeightSafe(MaterialProperty prop, string label, MaterialEditor editor)
{
return EditorGUIUtility.singleLineHeight;
}
protected override void OnGUISafe(Rect position, MaterialProperty prop, string label, MaterialEditor editor)
{
using (new FixedFieldsScope())
{
EditorGUIUtility.labelWidth = 0;
var vectorValue = prop.vectorValue;
var xValue = vectorValue.x;
var yValue = vectorValue.y;
EditorGUI.BeginChangeCheck();
ToolboxEditorGui.DrawMinMaxSlider(position, label, ref xValue, ref yValue, minValue, maxValue);
if (EditorGUI.EndChangeCheck())
{
vectorValue.x = xValue;
vectorValue.y = yValue;
prop.vectorValue = vectorValue;
}
}
}
protected override bool IsPropertyValid(MaterialProperty prop)
{
#if UNITY_6000_3_OR_NEWER
return prop.propertyType == UnityEngine.Rendering.ShaderPropertyType.Vector;
#else
return prop.type == MaterialProperty.PropType.Vector;
#endif
}
}
}