Skip to content

Commit 4312761

Browse files
committed
Fix shader property ids not changing
1 parent 7d9074e commit 4312761

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Editor/ShaderPropertyPropertyDrawer.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,29 @@ namespace Zigurous.Graphics.Editor
77
public sealed class ShaderPropertyPropertyDrawer : PropertyDrawer
88
{
99
private SerializedProperty _name;
10+
private SerializedProperty _id;
1011

1112
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
1213
{
1314
if (_name == null) {
1415
_name = property.FindPropertyRelative("_name");
1516
}
1617

18+
if (_id == null) {
19+
_id = property.FindPropertyRelative("_id");
20+
}
21+
1722
EditorGUI.BeginProperty(position, label, property);
1823
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
19-
_name.stringValue = EditorGUI.TextField(position, _name.stringValue);
24+
25+
string name = EditorGUI.TextField(position, _name.stringValue);
26+
27+
if (name != _name.stringValue)
28+
{
29+
_name.stringValue = name;
30+
_id.intValue = Shader.PropertyToID(name);
31+
}
32+
2033
EditorGUI.EndProperty();
2134
}
2235

Runtime/ShaderProperty.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace Zigurous.Graphics
99
[System.Serializable]
1010
public struct ShaderProperty
1111
{
12+
[SerializeField]
13+
[HideInInspector]
1214
private int _id;
1315

1416
/// <summary>

0 commit comments

Comments
 (0)