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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
using UnityEngine;
using UnityEditor;
using System;
namespace AmplifyShaderEditor
{
[System.Serializable]
public class InlineProperty
{
[SerializeField]
private float m_value = 0;
[SerializeField]
private bool m_active = false;
[SerializeField]
private int m_nodeId = -1;
[SerializeField]
private string m_nodePropertyName = string.Empty;
public InlineProperty() { }
public InlineProperty( float val )
{
m_value = val;
}
public InlineProperty( int val )
{
m_value = val;
}
public void ResetProperty()
{
m_nodeId = -1;
m_active = false;
}
public void CopyFrom( InlineProperty other )
{
m_value = other.m_value;
m_active = other.m_active;
m_nodeId = other.m_nodeId;
}
public void SetInlineByName( string propertyName )
{
m_nodeId = UIUtils.GetNodeIdByName( propertyName );
m_nodePropertyName = propertyName;
m_active = m_nodeId != -1;
}
public void IntField( ref UndoParentNode owner, string content )
{
if( !m_active )
{
EditorGUILayout.BeginHorizontal();
m_value = owner.EditorGUILayoutIntField( content, (int)m_value );
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
m_active = !m_active;
EditorGUILayout.EndHorizontal();
}
else
{
DrawPicker( ref owner, content );
}
}
public void IntSlider( ref UndoParentNode owner, GUIContent content, int min, int max )
{
if( !m_active )
{
EditorGUILayout.BeginHorizontal();
m_value = owner.EditorGUILayoutIntSlider( content, (int)m_value, min, max );
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
m_active = !m_active;
EditorGUILayout.EndHorizontal();
}
else
{
DrawPicker( ref owner, content );
}
}
public void IntSlider( ref UndoParentNode owner, string content, int min, int max )
{
if( !m_active )
{
EditorGUILayout.BeginHorizontal();
m_value = owner.EditorGUILayoutIntSlider( content, (int)m_value, min, max );
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
m_active = !m_active;
EditorGUILayout.EndHorizontal();
}
else
{
DrawPicker( ref owner, content );
}
}
public void EnumTypePopup( ref UndoParentNode owner, string content, string[] displayOptions )
{
if( !m_active )
{
EditorGUILayout.BeginHorizontal();
m_value = owner.EditorGUILayoutPopup( content, (int)m_value, displayOptions );
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
m_active = !m_active;
EditorGUILayout.EndHorizontal();
}
else
{
DrawPicker( ref owner, content );
}
}
public void FloatField( ref UndoParentNode owner, string content )
{
if( !m_active )
{
EditorGUILayout.BeginHorizontal();
m_value = owner.EditorGUILayoutFloatField( content, m_value );
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
m_active = !m_active;
EditorGUILayout.EndHorizontal();
}
else
{
DrawPicker( ref owner, content );
}
}
public void SliderField( ref UndoParentNode owner, string content, float min, float max )
{
if( !m_active )
{
EditorGUILayout.BeginHorizontal();
m_value = owner.EditorGUILayoutSlider( content, m_value, min, max );
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
m_active = !m_active;
EditorGUILayout.EndHorizontal();
}
else
{
DrawPicker( ref owner, content );
}
}
public void RangedFloatField( ref UndoParentNode owner, string content, float min, float max )
{
if( !m_active )
{
EditorGUILayout.BeginHorizontal();
m_value = owner.EditorGUILayoutRangedFloatField( content, m_value, min, max );
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
m_active = !m_active;
EditorGUILayout.EndHorizontal();
}
else
{
DrawPicker( ref owner, content );
}
}
public void CustomDrawer( ref UndoParentNode owner, DrawPropertySection Drawer, string content )
{
if( !m_active )
{
EditorGUILayout.BeginHorizontal();
Drawer( owner );
if( GUILayout.Button( UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
m_active = !m_active;
EditorGUILayout.EndHorizontal();
}
else
{
DrawPicker( ref owner, content );
}
}
public delegate void DrawPropertySection( UndoParentNode owner );
private void DrawPicker( ref UndoParentNode owner, GUIContent content )
{
DrawPicker( ref owner, content.text );
}
private void DrawPicker( ref UndoParentNode owner, string content )
{
EditorGUILayout.BeginHorizontal();
m_nodeId = owner.EditorGUILayoutIntPopup( content, m_nodeId, UIUtils.FloatIntNodeArr(), UIUtils.FloatIntNodeIds() );
if( GUILayout.Button( UIUtils.FloatIntIconOFF, UIUtils.FloatIntPickerONOFF, GUILayout.Width( 15 ), GUILayout.Height( 15 ) ) )
m_active = !m_active;
EditorGUILayout.EndHorizontal();
}
public string GetValueOrProperty( bool parentesis = true )
{
if( m_active )
{
PropertyNode node = GetPropertyNode();
if( node != null )
{
return parentesis ? "[" + node.PropertyName + "]" : node.PropertyName;
}
else
{
m_active = false;
m_nodeId = -1;
return m_value.ToString();
}
}
else
{
return m_value.ToString();
}
}
public string GetValueOrProperty( string defaultValue, bool parentesis = true )
{
if( m_active )
{
PropertyNode node = GetPropertyNode();
if( node != null )
{
return parentesis ? "[" + node.PropertyName + "]" : node.PropertyName;
}
else if( !string.IsNullOrEmpty( defaultValue ) )
{
m_active = false;
m_nodeId = -1;
return defaultValue;
}
else
{
m_active = false;
m_nodeId = -1;
return m_value.ToString();
}
}
else
{
return defaultValue;
}
}
public void ReadFromString( ref uint index, ref string[] nodeParams, bool isInt = true )
{
m_value = isInt ? Convert.ToInt32( nodeParams[ index++ ] ) : Convert.ToSingle( nodeParams[ index++ ] );
m_active = Convert.ToBoolean( nodeParams[ index++ ] );
m_nodeId = Convert.ToInt32( nodeParams[ index++ ] );
}
public void ReadFromSingle( string singleLine )
{
string[] data = singleLine.Split( IOUtils.VECTOR_SEPARATOR );
m_value = Convert.ToSingle( data[ 0 ] );
m_active = Convert.ToBoolean( data[ 1 ] );
m_nodeId = Convert.ToInt32( data[ 2 ] );
}
public void WriteToString( ref string nodeInfo )
{
IOUtils.AddFieldValueToString( ref nodeInfo, m_value );
IOUtils.AddFieldValueToString( ref nodeInfo, m_active );
IOUtils.AddFieldValueToString( ref nodeInfo, m_nodeId );
}
public string WriteToSingle()
{
return m_value.ToString() + IOUtils.VECTOR_SEPARATOR + m_active + IOUtils.VECTOR_SEPARATOR + m_nodeId;
}
public void SetInlineNodeValue()
{
if( IsValid )
{
RangedFloatNode fnode = UIUtils.GetNode( m_nodeId ) as RangedFloatNode;
if( fnode != null )
{
fnode.Value = m_value;
fnode.SetMaterialValueFromInline( m_value );
}
else
{
IntNode inode = UIUtils.GetNode( m_nodeId ) as IntNode;
inode.Value = (int)m_value;
inode.SetMaterialValueFromInline( (int)m_value );
}
}
}
public bool IsValid { get { return m_active && m_nodeId != -1; } }
public PropertyNode GetPropertyNode()
{
if( m_nodeId >= 0 )
return UIUtils.GetNode( m_nodeId ) as PropertyNode;
if( m_nodeId < -1 )
{
if(!string.IsNullOrEmpty(m_nodePropertyName))
return UIUtils.GetInternalTemplateNode( m_nodePropertyName );
return UIUtils.GetInternalTemplateNode( m_nodeId );
}
return null;
}
public int IntValue { get { return (int)m_value; } set { m_value = value; } }
public float FloatValue { get { return m_value; } set { m_value = value; } }
public bool Active { get { return m_active; } set { m_active = value; } }
public int NodeId { get { return m_nodeId; } set { m_nodeId = value; } }
}
}
|