@@ -243,75 +243,71 @@ internal void DoDuplicateShapePreviewHandle(Vector3 position)
243243 {
244244 var evt = Event . current ;
245245
246+ if ( evt . type != EventType . Repaint )
247+ return ;
248+
246249 bool previewShortcutActive = evt . shift && ! ( evt . control || evt . command ) ;
247250
248- if ( evt . type == EventType . Layout )
251+ if ( HandleUtility . nearestControl != m_ControlID || ! previewShortcutActive )
249252 {
250- if ( HandleUtility . nearestControl == m_ControlID && previewShortcutActive )
251- {
252- var pivotLocation = ( PivotLocation ) s_LastPivotLocation . value ;
253- var size = currentShapeInOverlay . size ;
254-
255- m_Bounds . size = size ;
256- Vector3 cornerPosition ;
253+ DestroyImmediate ( m_DuplicateGO ) ;
254+ return ;
255+ }
257256
258- switch ( pivotLocation )
259- {
260- case PivotLocation . FirstCorner :
261- cornerPosition = GetPoint ( position ) ;
262- m_PlaneRotation = Quaternion . LookRotation ( m_PlaneForward , m_Plane . normal ) ;
263- m_Bounds . center = cornerPosition + m_PlaneRotation * size / 2f ;
264-
265- m_BB_Origin = cornerPosition ;
266- m_BB_HeightCorner = m_Bounds . center + m_PlaneRotation * ( size / 2f ) ;
267- m_BB_OppositeCorner = m_BB_HeightCorner - m_PlaneRotation * new Vector3 ( 0 , size . y , 0 ) ;
268- break ;
269-
270- case PivotLocation . Center :
271- default :
272- position = GetPoint ( position ) ;
273- cornerPosition = position - size / 2f ;
274- cornerPosition . y = position . y ;
275- m_Bounds . center = cornerPosition + new Vector3 ( size . x / 2f , 0 , size . z / 2f ) + ( size . y / 2f ) * m_Plane . normal ;
276- m_PlaneRotation = Quaternion . LookRotation ( m_PlaneForward , m_Plane . normal ) ;
277-
278- m_BB_Origin = m_Bounds . center - m_PlaneRotation * ( size / 2f ) ;
279- m_BB_HeightCorner = m_Bounds . center + m_PlaneRotation * ( size / 2f ) ;
280- m_BB_OppositeCorner = m_BB_HeightCorner - m_PlaneRotation * new Vector3 ( 0 , size . y , 0 ) ;
281- break ;
282- }
257+ var pivotLocation = ( PivotLocation ) s_LastPivotLocation . value ;
258+ var size = currentShapeInOverlay . size ;
283259
284- if ( m_DuplicateGO == null )
285- {
286- var instantiated = ShapeFactory . Instantiate ( activeShapeType , ( ( PivotLocation ) s_LastPivotLocation . value ) ) ;
287- var shape = instantiated . GetComponent < ProBuilderShape > ( ) ;
288- m_DuplicateGO = shape . gameObject ;
289- m_DuplicateGO . hideFlags = HideFlags . DontSave | HideFlags . HideInHierarchy ;
290- ApplyPrefsSettings ( shape ) ;
291- shape . GetComponent < MeshRenderer > ( ) . sharedMaterial = m_ShapePreviewMaterial ;
292-
293- EditorShapeUtility . CopyLastParams ( shape . shape , shape . shape . GetType ( ) ) ;
294- shape . Rebuild ( m_Bounds , m_PlaneRotation , m_BB_Origin ) ;
295- ProBuilderEditor . Refresh ( false ) ;
296- }
260+ m_Bounds . size = size ;
261+ Vector3 cornerPosition ;
297262
298- var pivot = GetPoint ( position ) ;
299- if ( pivotLocation == PivotLocation . Center )
300- pivot += m_Plane . normal * size . y * .5f ;
301-
302- m_DuplicateGO . transform . position = pivot ;
303- m_DuplicateGO . transform . rotation = Quaternion . LookRotation ( m_PlaneForward , m_Plane . normal ) ;
304- }
305- else if ( m_DuplicateGO != null )
306- {
307- DestroyImmediate ( m_DuplicateGO ) ;
308- }
263+ switch ( pivotLocation )
264+ {
265+ case PivotLocation . FirstCorner :
266+ cornerPosition = GetPoint ( position ) ;
267+ m_PlaneRotation = Quaternion . LookRotation ( m_PlaneForward , m_Plane . normal ) ;
268+ m_Bounds . center = cornerPosition + m_PlaneRotation * size / 2f ;
269+
270+ m_BB_Origin = cornerPosition ;
271+ m_BB_HeightCorner = m_Bounds . center + m_PlaneRotation * ( size / 2f ) ;
272+ m_BB_OppositeCorner = m_BB_HeightCorner - m_PlaneRotation * new Vector3 ( 0 , size . y , 0 ) ;
273+ break ;
274+
275+ case PivotLocation . Center :
276+ default :
277+ position = GetPoint ( position ) ;
278+ cornerPosition = position - size / 2f ;
279+ cornerPosition . y = position . y ;
280+ m_Bounds . center = cornerPosition + new Vector3 ( size . x / 2f , 0 , size . z / 2f ) + ( size . y / 2f ) * m_Plane . normal ;
281+ m_PlaneRotation = Quaternion . LookRotation ( m_PlaneForward , m_Plane . normal ) ;
282+
283+ m_BB_Origin = m_Bounds . center - m_PlaneRotation * ( size / 2f ) ;
284+ m_BB_HeightCorner = m_Bounds . center + m_PlaneRotation * ( size / 2f ) ;
285+ m_BB_OppositeCorner = m_BB_HeightCorner - m_PlaneRotation * new Vector3 ( 0 , size . y , 0 ) ;
286+ break ;
309287 }
310- else if ( evt . type == EventType . Repaint )
288+
289+ if ( m_DuplicateGO == null )
311290 {
312- if ( GUIUtility . hotControl == 0 && previewShortcutActive )
313- DrawBoundingBox ( false ) ;
291+ var instantiated = ShapeFactory . Instantiate ( activeShapeType , ( ( PivotLocation ) s_LastPivotLocation . value ) ) ;
292+ var shape = instantiated . GetComponent < ProBuilderShape > ( ) ;
293+ m_DuplicateGO = shape . gameObject ;
294+ m_DuplicateGO . hideFlags = HideFlags . DontSave | HideFlags . HideInHierarchy ;
295+ ApplyPrefsSettings ( shape ) ;
296+ shape . GetComponent < MeshRenderer > ( ) . sharedMaterial = m_ShapePreviewMaterial ;
297+
298+ EditorShapeUtility . CopyLastParams ( shape . shape , shape . shape . GetType ( ) ) ;
299+ shape . Rebuild ( m_Bounds , m_PlaneRotation , m_BB_Origin ) ;
300+ ProBuilderEditor . Refresh ( false ) ;
314301 }
302+
303+ var pivot = GetPoint ( position ) ;
304+ if ( pivotLocation == PivotLocation . Center )
305+ pivot += m_Plane . normal * size . y * .5f ;
306+
307+ m_DuplicateGO . transform . position = pivot ;
308+ m_DuplicateGO . transform . rotation = Quaternion . LookRotation ( m_PlaneForward , m_Plane . normal ) ;
309+
310+ DrawBoundingBox ( false ) ;
315311 }
316312
317313 void RecalculateBounds ( )
0 commit comments