@@ -57,31 +57,68 @@ internal abstract class Prop
57
57
internal abstract class Prop < T > ( T value ) : Prop
58
58
{
59
59
internal T Value = value ;
60
+
61
+ internal abstract bool UpdateIfChanged ( T value ) ;
60
62
public override string ToString ( ) => Value . ToString ( ) ;
61
63
}
62
64
63
65
internal class PropColor ( Color value ) : Prop < Color > ( value )
64
66
{
67
+ internal override bool UpdateIfChanged ( Color value )
68
+ {
69
+ if ( Utils . ApproxEquals ( value , Value ) ) return false ;
70
+ Value = value ;
71
+ return true ;
72
+ }
73
+
65
74
internal override void Write ( int id , MaterialPropertyBlock mpb ) => mpb . SetColor ( id , Value ) ;
66
75
}
67
76
68
77
internal class PropFloat ( float value ) : Prop < float > ( value )
69
78
{
79
+ internal override bool UpdateIfChanged ( float value )
80
+ {
81
+ if ( Utils . ApproxEqualsRel ( value , Value ) ) return false ;
82
+ Value = value ;
83
+ return true ;
84
+ }
85
+
70
86
internal override void Write ( int id , MaterialPropertyBlock mpb ) => mpb . SetFloat ( id , Value ) ;
71
87
}
72
88
73
89
internal class PropInt ( int value ) : Prop < int > ( value )
74
90
{
91
+ internal override bool UpdateIfChanged ( int value )
92
+ {
93
+ if ( value == Value ) return false ;
94
+ Value = value ;
95
+ return true ;
96
+ }
97
+
75
98
internal override void Write ( int id , MaterialPropertyBlock mpb ) => mpb . SetInt ( id , Value ) ;
76
99
}
77
100
78
101
internal class PropTexture ( Texture value ) : Prop < Texture > ( value )
79
102
{
103
+ internal override bool UpdateIfChanged ( Texture value )
104
+ {
105
+ if ( ReferenceEquals ( value , Value ) ) return false ;
106
+ Value = value ;
107
+ return true ;
108
+ }
109
+
80
110
internal override void Write ( int id , MaterialPropertyBlock mpb ) => mpb . SetTexture ( id , Value ) ;
81
111
}
82
112
83
113
internal class PropVector ( Vector4 value ) : Prop < Vector4 > ( value )
84
114
{
115
+ internal override bool UpdateIfChanged ( Vector4 value )
116
+ {
117
+ if ( Utils . ApproxEqualsRel ( value , Value ) ) return false ;
118
+ Value = value ;
119
+ return true ;
120
+ }
121
+
85
122
internal override void Write ( int id , MaterialPropertyBlock mpb ) => mpb . SetVector ( id , Value ) ;
86
123
}
87
124
@@ -118,17 +155,15 @@ public sealed class Props(int priority) : IDisposable
118
155
public void SuppressEagerUpdatesThisFrame ( )
119
156
{
120
157
SuppressEagerUpdate = true ;
121
- MaterialPropertyManager . Instance . ScheduleLateUpdate ( this ) ;
158
+ MaterialPropertyManager . Instance ? . ScheduleLateUpdate ( this ) ;
122
159
}
123
160
124
161
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
125
162
private void _internalSet < T , TProp > ( int id , T value ) where TProp : Prop < T >
126
163
{
127
164
if ( props . TryGetValue ( id , out var prop ) ) {
128
165
if ( prop is TProp typedProp ) {
129
- if ( EqualityComparer < T > . Default . Equals ( value , typedProp . Value ) ) return ;
130
-
131
- typedProp . Value = value ;
166
+ if ( ! typedProp . UpdateIfChanged ( value ) ) return ;
132
167
133
168
if ( ! SuppressEagerUpdate ) {
134
169
OnValueChanged ( this ) ;
@@ -179,7 +214,7 @@ internal void Write(int id, MaterialPropertyBlock mpb)
179
214
throw new KeyNotFoundException ( $ "property { PropIdToName . Get ( id ) } not found") ;
180
215
}
181
216
182
- MaterialPropertyManager . Instance . LogDebug (
217
+ MaterialPropertyManager . Instance ? . LogDebug (
183
218
$ "writing property { PropIdToName . Get ( id ) } = { prop } ") ;
184
219
185
220
prop . Write ( id , mpb ) ;
0 commit comments