1
1
using System . Collections . Generic ;
2
+ using System . Linq ;
2
3
using System . Runtime . CompilerServices ;
3
4
using KSPBuildTools ;
4
5
using UnityEngine ;
5
6
6
7
namespace Shabby ;
7
8
9
+ internal static class PropIdToName
10
+ {
11
+ private static readonly string [ ] CommonProperties = [
12
+ "TransparentFX" ,
13
+ "_BumpMap" ,
14
+ "_Color" ,
15
+ "_EmissiveColor" ,
16
+ "_MainTex" ,
17
+ "_MaxX" ,
18
+ "_MaxY" ,
19
+ "_MinX" ,
20
+ "_MinY" ,
21
+ "_Multiplier" ,
22
+ "_Opacity" ,
23
+ "_RimColor" ,
24
+ "_RimFalloff" ,
25
+ "_TC1Color" ,
26
+ "_TC1MetalBlend" ,
27
+ "_TC1Metalness" ,
28
+ "_TC1SmoothBlend" ,
29
+ "_TC1Smoothness" ,
30
+ "_TC2Color" ,
31
+ "_TC2MetalBlend" ,
32
+ "_TC2Metalness" ,
33
+ "_TC2SmoothBlend" ,
34
+ "_TC2Smoothness" ,
35
+ "_TemperatureColor" ,
36
+ "_Tex" ,
37
+ "_Tint" ,
38
+ "_TintColor" ,
39
+ "_subdiv" ,
40
+ "localMatrix" ,
41
+ "upMatrix"
42
+ ] ;
43
+
44
+ private static readonly Dictionary < int , string > IdToName =
45
+ CommonProperties . ToDictionary ( Shader . PropertyToID , name => name ) ;
46
+
47
+ internal static string Get ( int id ) =>
48
+ IdToName . TryGetValue ( id , out var name ) ? name : $ "<{ id } >";
49
+ }
50
+
8
51
internal abstract class Prop ;
9
52
10
53
internal class Prop < T > ( T value ) : Prop
@@ -38,10 +81,6 @@ public sealed class Props(int priority)
38
81
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
39
82
private void _internalSet < T > ( int id , T value )
40
83
{
41
- Dirty = true ;
42
-
43
- MaterialPropertyManager . Instance . LogDebug ( $ "setting { id } to { value } ") ;
44
-
45
84
if ( ! _props . TryGetValue ( id , out var prop ) ) {
46
85
_props [ id ] = new Prop < T > ( value ) ;
47
86
Changed = true ;
@@ -50,7 +89,7 @@ private void _internalSet<T>(int id, T value)
50
89
51
90
if ( prop is not Prop < T > propT ) {
52
91
MaterialPropertyManager . Instance . LogWarning (
53
- $ "property { id } has mismatched type; overwriting with { typeof ( T ) . Name } !") ;
92
+ $ "property { PropIdToName . Get ( id ) } has mismatched type; overwriting with { typeof ( T ) . Name } !") ;
54
93
_props [ id ] = new Prop < T > ( value ) ;
55
94
Changed = true ;
56
95
return ;
@@ -85,9 +124,12 @@ private void _internalSet<T>(int id, T value)
85
124
internal void Write ( int id , MaterialPropertyBlock mpb )
86
125
{
87
126
if ( ! _props . TryGetValue ( id , out var prop ) ) {
88
- throw new KeyNotFoundException ( $ "property { id } not found") ;
127
+ throw new KeyNotFoundException ( $ "property { PropIdToName . Get ( id ) } not found") ;
89
128
}
90
129
130
+ MaterialPropertyManager . Instance . LogDebug (
131
+ $ "writing property { PropIdToName . Get ( id ) } = { prop } ") ;
132
+
91
133
switch ( prop ) {
92
134
case Prop < Color > c : mpb . SetColor ( id , c . Value ) ; break ;
93
135
case Prop < float > f : mpb . SetFloat ( id , f . Value ) ; break ;
@@ -102,7 +144,7 @@ public override string ToString()
102
144
var sb = StringBuilderCache . Acquire ( ) ;
103
145
sb . AppendFormat ( "(Priority {0}) {{\n " , Priority ) ;
104
146
foreach ( var ( id , prop ) in _props ) {
105
- sb . AppendFormat ( "{0} = {1}\n " , id , prop ) ;
147
+ sb . AppendFormat ( "{0} = {1}\n " , PropIdToName . Get ( id ) , prop ) ;
106
148
}
107
149
108
150
sb . AppendLine ( "}" ) ;
0 commit comments