@@ -303,8 +303,16 @@ private void InitPreview()
303303 if ( m_PreviewUtility == null )
304304 {
305305 m_PreviewUtility = new PreviewRenderUtility ( true ) ;
306+ #if UNITY_2017_1_OR_NEWER
307+ m_PreviewUtility . cameraFieldOfView = 30f ;
308+ #else
306309 m_PreviewUtility . m_CameraFieldOfView = 30f ;
307- m_PreviewUtility . m_Camera . cullingMask = 1 << PreviewCullingLayer ;
310+ #endif
311+ GetPreviewCamera ( ) . cullingMask = 1 << PreviewCullingLayer ;
312+ #if UNITY_5_6_OR_NEWER
313+ GetPreviewCamera ( ) . allowHDR = false ;
314+ GetPreviewCamera ( ) . allowMSAA = false ;
315+ #endif
308316 CreatePreviewInstances ( ) ;
309317 }
310318 if ( m_FloorPlane == null )
@@ -330,24 +338,28 @@ private void InitPreview()
330338 GameObject original = ( GameObject ) EditorGUIUtility . Load ( "Avatar/dial_flat.prefab" ) ;
331339 m_ReferenceInstance = ( GameObject ) UnityEngine . Object . Instantiate ( original , Vector3 . zero , Quaternion . identity ) ;
332340 InitInstantiatedPreviewRecursive ( m_ReferenceInstance ) ;
341+ AddSingleGO ( m_ReferenceInstance ) ;
333342 }
334343 if ( m_DirectionInstance == null )
335344 {
336345 GameObject original2 = ( GameObject ) EditorGUIUtility . Load ( "Avatar/arrow.fbx" ) ;
337346 m_DirectionInstance = ( GameObject ) UnityEngine . Object . Instantiate ( original2 , Vector3 . zero , Quaternion . identity ) ;
338347 InitInstantiatedPreviewRecursive ( m_DirectionInstance ) ;
348+ AddSingleGO ( m_DirectionInstance ) ;
339349 }
340350 if ( m_PivotInstance == null )
341351 {
342352 GameObject original3 = ( GameObject ) EditorGUIUtility . Load ( "Avatar/root.fbx" ) ;
343353 m_PivotInstance = ( GameObject ) UnityEngine . Object . Instantiate ( original3 , Vector3 . zero , Quaternion . identity ) ;
344354 InitInstantiatedPreviewRecursive ( m_PivotInstance ) ;
355+ AddSingleGO ( m_PivotInstance ) ;
345356 }
346357 if ( m_RootInstance == null )
347358 {
348359 GameObject original4 = ( GameObject ) EditorGUIUtility . Load ( "Avatar/root.fbx" ) ;
349360 m_RootInstance = ( GameObject ) UnityEngine . Object . Instantiate ( original4 , Vector3 . zero , Quaternion . identity ) ;
350361 InitInstantiatedPreviewRecursive ( m_RootInstance ) ;
362+ AddSingleGO ( m_RootInstance ) ;
351363 }
352364 m_ShowReference = EditorPrefs . GetBool ( "AvatarpreviewShowReference" , true ) ;
353365 SetPreviewCharacterEnabled ( false , false ) ;
@@ -379,12 +391,12 @@ private void DoRenderPreview()
379391 Quaternion pivotRot = quaternion ;
380392 PositionPreviewObjects ( pivotRot , pivotPos , quaternion2 , bodyPosition , directionRot , quaternion , vector , directionPos , m_AvatarScale ) ;
381393
382- m_PreviewUtility . m_Camera . nearClipPlane = 0.5f * m_ZoomFactor ;
383- m_PreviewUtility . m_Camera . farClipPlane = 100f * m_AvatarScale ;
394+ GetPreviewCamera ( ) . nearClipPlane = 0.5f * m_ZoomFactor ;
395+ GetPreviewCamera ( ) . farClipPlane = 100f * m_AvatarScale ;
384396 Quaternion rotation = Quaternion . Euler ( - m_PreviewDir . y , - m_PreviewDir . x , 0f ) ;
385397 Vector3 position2 = rotation * ( Vector3 . forward * - 5.5f * m_ZoomFactor ) + bodyPosition + m_PivotPositionOffset ;
386- m_PreviewUtility . m_Camera . transform . position = position2 ;
387- m_PreviewUtility . m_Camera . transform . rotation = rotation ;
398+ GetPreviewCamera ( ) . transform . position = position2 ;
399+ GetPreviewCamera ( ) . transform . rotation = rotation ;
388400
389401 Quaternion identity = Quaternion . identity ;
390402 Vector3 position = new Vector3 ( 0f , 0f , 0f ) ;
@@ -393,10 +405,10 @@ private void DoRenderPreview()
393405 Matrix4x4 matrix2 = Matrix4x4 . TRS ( position , identity , Vector3 . one * 5f * m_AvatarScale ) ;
394406 floorMaterial . mainTextureOffset = - new Vector2 ( position . x , position . z ) * 5f * 0.08f * ( 1f / m_AvatarScale ) ;
395407 floorMaterial . SetVector ( "_Alphas" , new Vector4 ( 0.5f * 1f , 0.3f * 1f , 0f , 0f ) ) ;
396- Graphics . DrawMesh ( m_FloorPlane , matrix2 , floorMaterial , PreviewCullingLayer , m_PreviewUtility . m_Camera , 0 ) ;
408+ Graphics . DrawMesh ( m_FloorPlane , matrix2 , floorMaterial , PreviewCullingLayer , GetPreviewCamera ( ) , 0 ) ;
397409
398410 SetPreviewCharacterEnabled ( true , m_ShowReference ) ;
399- m_PreviewUtility . m_Camera . Render ( ) ;
411+ GetPreviewCamera ( ) . Render ( ) ;
400412 SetPreviewCharacterEnabled ( false , false ) ;
401413 TeardownPreviewLightingAndFx ( oldFog ) ;
402414 }
@@ -406,6 +418,7 @@ private void CreatePreviewInstances()
406418 DestroyPreviewInstances ( ) ;
407419 GameObject gameObject = UnityEngine . Object . Instantiate ( target ) as GameObject ;
408420 InitInstantiatedPreviewRecursive ( gameObject ) ;
421+ AddSingleGO ( gameObject ) ;
409422 Animator component = gameObject . GetComponent < Animator > ( ) ;
410423 if ( component )
411424 {
@@ -442,13 +455,34 @@ private void DestroyPreviewInstances()
442455 UnityEngine . Object . DestroyImmediate ( m_DirectionInstance ) ;
443456 }
444457
458+ private void AddSingleGO ( GameObject go )
459+ {
460+ #if UNITY_2017_1_OR_NEWER
461+ m_PreviewUtility . AddSingleGO ( go ) ;
462+ #endif
463+ }
464+
465+ private Camera GetPreviewCamera ( )
466+ {
467+ #if UNITY_2017_1_OR_NEWER
468+ return m_PreviewUtility . camera ;
469+ #else
470+ return m_PreviewUtility . m_Camera ;
471+ #endif
472+ }
473+
445474 private bool SetupPreviewLightingAndFx ( )
446475 {
447- m_PreviewUtility . m_Light [ 0 ] . intensity = 1.4f ;
448- m_PreviewUtility . m_Light [ 0 ] . transform . rotation = Quaternion . Euler ( 40f , 40f , 0f ) ;
449- m_PreviewUtility . m_Light [ 1 ] . intensity = 1.4f ;
476+ #if UNITY_2017_1_OR_NEWER
477+ Light [ ] lights = m_PreviewUtility . lights ;
478+ #else
479+ Light [ ] lights = m_PreviewUtility . m_Light ;
480+ #endif
481+ lights [ 0 ] . intensity = 1.4f ;
482+ lights [ 0 ] . transform . rotation = Quaternion . Euler ( 40f , 40f , 0f ) ;
483+ lights [ 1 ] . intensity = 1.4f ;
450484 Color ambient = new Color ( 0.1f , 0.1f , 0.1f , 0f ) ;
451- InternalEditorUtility . SetCustomLighting ( m_PreviewUtility . m_Light , ambient ) ;
485+ InternalEditorUtility . SetCustomLighting ( lights , ambient ) ;
452486 bool fog = RenderSettings . fog ;
453487 Unsupported . SetRenderSettingsUseFogNoDirty ( false ) ;
454488 return fog ;
@@ -715,7 +749,7 @@ public void DoAvatarPreviewOrbit(Event evt, Rect previewRect)
715749
716750 public void DoAvatarPreviewPan ( Event evt )
717751 {
718- Camera camera = m_PreviewUtility . m_Camera ;
752+ Camera camera = GetPreviewCamera ( ) ;
719753 Vector3 vector = camera . WorldToScreenPoint ( bodyPosition + m_PivotPositionOffset ) ;
720754 Vector3 a = new Vector3 ( - evt . delta . x , evt . delta . y , 0f ) ;
721755 vector += a * Mathf . Lerp ( 0.25f , 2f , m_ZoomFactor * 0.5f ) ;
@@ -749,7 +783,7 @@ public void DoAvatarPreviewFrame(Event evt, EventType type, Rect previewRect)
749783
750784 protected Vector3 GetCurrentMouseWorldPosition ( Event evt , Rect previewRect )
751785 {
752- Camera camera = m_PreviewUtility . m_Camera ;
786+ Camera camera = GetPreviewCamera ( ) ;
753787 float scaleFactor = m_PreviewUtility . GetScaleFactor ( previewRect . width , previewRect . height ) ;
754788 return camera . ScreenToWorldPoint ( new Vector3 ( ( evt . mousePosition . x - previewRect . x ) * scaleFactor , ( previewRect . height - ( evt . mousePosition . y - previewRect . y ) ) * scaleFactor , 0f )
755789 {
0 commit comments