@@ -204,7 +204,8 @@ void DrawHandles()
204
204
205
205
if ( editMode == k_EditShapePreservingUV || editMode == k_EditShapeWithoutPreservingUV )
206
206
{
207
- using ( new Handles . DrawingScope ( Color . white , Matrix4x4 . TRS ( decalProjector . transform . position , decalProjector . transform . rotation , Vector3 . one ) ) )
207
+ Vector3 scale = decalProjector . transform . lossyScale ;
208
+ using ( new Handles . DrawingScope ( Color . white , Matrix4x4 . TRS ( decalProjector . transform . position , decalProjector . transform . rotation , scale ) ) )
208
209
{
209
210
bool needToRefreshDecalProjector = false ;
210
211
@@ -223,8 +224,26 @@ void DrawHandles()
223
224
// Adjust decal transform if handle changed.
224
225
Undo . RecordObject ( decalProjector , "Decal Projector Change" ) ;
225
226
226
- decalProjector . size = handle . size ;
227
- decalProjector . offset = handle . center ;
227
+ // Preserve serialized state for axes with scale 0.
228
+ Vector3 newSize = decalProjector . size ;
229
+ Vector3 newOffset = decalProjector . offset ;
230
+ if ( scale . x != 0f )
231
+ {
232
+ newSize . x = handle . size . x ;
233
+ newOffset . x = handle . center . x ;
234
+ }
235
+ if ( scale . y != 0f )
236
+ {
237
+ newSize . y = handle . size . y ;
238
+ newOffset . y = handle . center . y ;
239
+ }
240
+ if ( scale . z != 0f )
241
+ {
242
+ newSize . z = handle . size . z ;
243
+ newOffset . z = handle . center . z ;
244
+ }
245
+ decalProjector . size = newSize ;
246
+ decalProjector . offset = newOffset ;
228
247
229
248
Vector3 boundsSizeCurrentOS = handle . size ;
230
249
Vector3 boundsMinCurrentOS = handle . size * - 0.5f + handle . center ;
@@ -233,14 +252,19 @@ void DrawHandles()
233
252
{
234
253
// Treat decal projector bounds as a crop tool, rather than a scale tool.
235
254
// Compute a new uv scale and bias terms to pin decal projection pixels in world space, irrespective of projector bounds.
255
+ // Preserve serialized state for axes with scale 0.
236
256
Vector2 uvScale = decalProjector . uvScale ;
237
- uvScale . x *= Mathf . Max ( 1e-5f , boundsSizeCurrentOS . x ) / Mathf . Max ( 1e-5f , boundsSizePreviousOS . x ) ;
238
- uvScale . y *= Mathf . Max ( 1e-5f , boundsSizeCurrentOS . y ) / Mathf . Max ( 1e-5f , boundsSizePreviousOS . y ) ;
257
+ if ( scale . x != 0f )
258
+ uvScale . x *= Mathf . Max ( 1e-5f , boundsSizeCurrentOS . x ) / Mathf . Max ( 1e-5f , boundsSizePreviousOS . x ) ;
259
+ if ( scale . y != 0f )
260
+ uvScale . y *= Mathf . Max ( 1e-5f , boundsSizeCurrentOS . y ) / Mathf . Max ( 1e-5f , boundsSizePreviousOS . y ) ;
239
261
decalProjector . uvScale = uvScale ;
240
262
241
263
Vector2 uvBias = decalProjector . uvBias ;
242
- uvBias . x += ( boundsMinCurrentOS . x - boundsMinPreviousOS . x ) / Mathf . Max ( 1e-5f , boundsSizeCurrentOS . x ) * decalProjector . uvScale . x ;
243
- uvBias . y += ( boundsMinCurrentOS . y - boundsMinPreviousOS . y ) / Mathf . Max ( 1e-5f , boundsSizeCurrentOS . y ) * decalProjector . uvScale . y ;
264
+ if ( scale . x != 0f )
265
+ uvBias . x += ( boundsMinCurrentOS . x - boundsMinPreviousOS . x ) / Mathf . Max ( 1e-5f , boundsSizeCurrentOS . x ) * decalProjector . uvScale . x ;
266
+ if ( scale . y != 0f )
267
+ uvBias . y += ( boundsMinCurrentOS . y - boundsMinPreviousOS . y ) / Mathf . Max ( 1e-5f , boundsSizeCurrentOS . y ) * decalProjector . uvScale . y ;
244
268
decalProjector . uvBias = uvBias ;
245
269
}
246
270
@@ -263,7 +287,7 @@ void DrawHandles()
263
287
// Re-center the transform to the center of the decal projector bounds,
264
288
// while maintaining the world-space coordinates of the decal projector boundings vertices.
265
289
// Center of the decal projector is not the same of the HierarchicalBox as we want it to be on the z face as lights
266
- decalProjector . transform . Translate ( decalProjector . offset + new Vector3 ( 0f , 0f , handle . size . z * - 0.5f ) , Space . Self ) ;
290
+ decalProjector . transform . Translate ( Vector3 . Scale ( decalProjector . offset + new Vector3 ( 0f , 0f , handle . size . z * - 0.5f ) , scale ) , Space . Self ) ;
267
291
268
292
decalProjector . offset = new Vector3 ( 0f , 0f , handle . size . z * 0.5f ) ;
269
293
if ( PrefabUtility . IsPartOfNonAssetPrefabInstance ( decalProjector ) )
@@ -290,18 +314,22 @@ void DrawHandles()
290
314
[ DrawGizmo ( GizmoType . Selected | GizmoType . Active ) ]
291
315
static void DrawGizmosSelected ( DecalProjector decalProjector , GizmoType gizmoType )
292
316
{
293
- //draw them scale independent
317
+ //draw them with scale applied to size and offset instead of TRS to keep proportions of the arrow and bold lines.
294
318
using ( new Handles . DrawingScope ( Color . white , Matrix4x4 . TRS ( decalProjector . transform . position , decalProjector . transform . rotation , Vector3 . one ) ) )
295
319
{
296
- handle . center = decalProjector . offset ;
297
- handle . size = decalProjector . size ;
320
+ Vector3 scale = decalProjector . transform . lossyScale ;
321
+ Vector3 scaledOffset = Vector3 . Scale ( decalProjector . offset , scale ) ;
322
+ Vector3 scaledSize = Vector3 . Scale ( decalProjector . size , scale ) ;
323
+
324
+ handle . center = scaledOffset ;
325
+ handle . size = scaledSize ;
298
326
bool inEditMode = editMode == k_EditShapePreservingUV || editMode == k_EditShapeWithoutPreservingUV ;
299
327
handle . DrawHull ( inEditMode ) ;
300
328
301
329
Quaternion arrowRotation = Quaternion . LookRotation ( Vector3 . down , Vector3 . right ) ;
302
- float arrowSize = decalProjector . size . z * 0.25f ;
303
- Vector3 pivot = decalProjector . offset ;
304
- Vector3 projectedPivot = pivot + decalProjector . size . z * 0.5f * Vector3 . back ;
330
+ float arrowSize = scaledSize . z * 0.25f ;
331
+ Vector3 pivot = scaledOffset ;
332
+ Vector3 projectedPivot = pivot + scaledSize . z * 0.5f * Vector3 . back ;
305
333
Handles . ArrowHandleCap ( 0 , projectedPivot , Quaternion . identity , arrowSize , EventType . Repaint ) ;
306
334
307
335
//[TODO: add editable pivot. Uncomment this when ready]
@@ -315,13 +343,13 @@ static void DrawGizmosSelected(DecalProjector decalProjector, GizmoType gizmoTyp
315
343
//Handles.DrawLine(projectedPivot, projectedPivot + decalProjector.m_Size.z * 0.5f * Vector3.forward);
316
344
317
345
//draw UV and bolder edges
318
- using ( new Handles . DrawingScope ( Matrix4x4 . TRS ( decalProjector . transform . position - decalProjector . transform . rotation * ( decalProjector . size * 0.5f + decalProjector . offset . z * Vector3 . back ) , decalProjector . transform . rotation , Vector3 . one ) ) )
346
+ using ( new Handles . DrawingScope ( Matrix4x4 . TRS ( decalProjector . transform . position - decalProjector . transform . rotation * ( scaledSize * 0.5f + scaledOffset . z * Vector3 . back ) , decalProjector . transform . rotation , Vector3 . one ) ) )
319
347
{
320
348
if ( inEditMode )
321
349
{
322
350
Vector2 size = new Vector2 (
323
- ( decalProjector . uvScale . x > 100000 || decalProjector . uvScale . x < - 100000 ? 0f : 1f / decalProjector . uvScale . x ) * decalProjector . size . x ,
324
- ( decalProjector . uvScale . y > 100000 || decalProjector . uvScale . y < - 100000 ? 0f : 1f / decalProjector . uvScale . y ) * decalProjector . size . y
351
+ ( decalProjector . uvScale . x > 100000 || decalProjector . uvScale . x < - 100000 ? 0f : 1f / decalProjector . uvScale . x ) * scaledSize . x ,
352
+ ( decalProjector . uvScale . y > 100000 || decalProjector . uvScale . y < - 100000 ? 0f : 1f / decalProjector . uvScale . y ) * scaledSize . y
325
353
) ;
326
354
Vector2 start = ( Vector2 ) projectedPivot - new Vector2 ( decalProjector . uvBias . x * size . x , decalProjector . uvBias . y * size . y ) ;
327
355
Handles . DrawDottedLines (
@@ -335,7 +363,7 @@ static void DrawGizmosSelected(DecalProjector decalProjector, GizmoType gizmoTyp
335
363
5f ) ;
336
364
}
337
365
338
- Vector2 halfSize = decalProjector . size * .5f ;
366
+ Vector2 halfSize = scaledSize * .5f ;
339
367
Vector2 halfSize2 = new Vector2 ( halfSize . x , - halfSize . y ) ;
340
368
Vector2 center = ( Vector2 ) projectedPivot + halfSize ;
341
369
Handles . DrawLine ( center - halfSize , center - halfSize2 , 3f ) ;
0 commit comments