internal static VisualisationGITexture GetSelectedObjectGITexture(GITextureType textureType)
        {
            VisualisationGITexture result = default(VisualisationGITexture);

            LightmapVisualizationUtility.GetSelectedObjectGITextureInternal(textureType, ref result);
            return(result);
        }
        void ShowRealtimeLightmapPreview(Hash128 inputSystemHash)
        {
            if (inputSystemHash == new Hash128())
            {
                return;
            }

            Hash128 contentHash = LightmapVisualizationUtility.GetRealtimeGITextureHash(inputSystemHash, GITextureType.Irradiance);

            // if we need to fetch a new texture
            if (m_CachedRealtimeTexture.texture == null || m_CachedRealtimeTexture.contentHash != contentHash)
            {
                m_CachedRealtimeTexture = LightmapVisualizationUtility.GetRealtimeGITexture(inputSystemHash, GITextureType.Irradiance);
            }

            if (m_CachedRealtimeTexture.texture == null)
            {
                return;
            }

            GUILayout.BeginHorizontal();
            GUILayout.Space(30);

            Rect rect = GUILayoutUtility.GetRect(100, 100, EditorStyles.objectField);

            EditorGUI.Toggle(rect, false, EditorStyles.objectFieldThumb);

            if (rect.Contains(Event.current.mousePosition))
            {
                Object    actualTargetObject = m_CachedRealtimeTexture.texture;
                Component com = actualTargetObject as Component;

                if (com)
                {
                    actualTargetObject = com.gameObject;
                }

                if (Event.current.clickCount == 2)
                {
                    LightmapPreviewWindow.CreateLightmapPreviewWindow(m_Renderers[0].GetInstanceID(), true, false);
                }
            }

            if (Event.current.type == EventType.Repaint)
            {
                rect = EditorStyles.objectFieldThumb.padding.Remove(rect);
                EditorGUI.DrawPreviewTexture(rect, m_CachedRealtimeTexture.texture);
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
Example #3
0
        bool UpdateRealtimeTexture(Hash128 inputSystemHash, int instanceId)
        {
            if (inputSystemHash == new Hash128())
            {
                return(false);
            }

            Hash128 contentHash = LightmapVisualizationUtility.GetRealtimeGITextureHash(inputSystemHash, GITextureType.Irradiance);

            // if we need to fetch a new texture
            if (m_CachedRealtimeTexture.texture == null || m_CachedRealtimeTexture.contentHash != contentHash)
            {
                m_CachedRealtimeTexture = LightmapVisualizationUtility.GetRealtimeGITexture(inputSystemHash, GITextureType.Irradiance);
            }

            if (m_CachedRealtimeTexture.texture == null)
            {
                return(false);
            }

            return(true);
        }
Example #4
0
        void ShowAtlasGUI(int instanceID, bool isMeshRenderer)
        {
            if (m_LightmapIndex == null)
            {
                return;
            }

            Hash128 contentHash = LightmapVisualizationUtility.GetBakedGITextureHash(m_LightmapIndex.intValue, 0, GITextureType.Baked);

            // if we need to fetch a new texture
            if (m_CachedBakedTexture.texture == null || m_CachedBakedTexture.contentHash != contentHash)
            {
                m_CachedBakedTexture = LightmapVisualizationUtility.GetBakedGITexture(m_LightmapIndex.intValue, 0, GITextureType.Baked);
            }

            if (m_CachedBakedTexture.texture == null)
            {
                return;
            }

            m_ShowBakedLM.value = EditorGUILayout.Foldout(m_ShowBakedLM.value, Styles.atlas, true);

            if (!m_ShowBakedLM.value)
            {
                return;
            }

            EditorGUI.indentLevel += 1;

            GUILayout.BeginHorizontal();

            DrawLightmapPreview(m_CachedBakedTexture.texture, false, instanceID);

            GUILayout.BeginVertical();

            GUILayout.Label(Styles.atlasIndex.text + ": " + m_LightmapIndex.intValue);
            GUILayout.Label(Styles.atlasTilingX.text + ": " + m_LightmapTilingOffsetX.floatValue.ToString(CultureInfo.InvariantCulture.NumberFormat));
            GUILayout.Label(Styles.atlasTilingY.text + ": " + m_LightmapTilingOffsetY.floatValue.ToString(CultureInfo.InvariantCulture.NumberFormat));
            GUILayout.Label(Styles.atlasOffsetX.text + ": " + m_LightmapTilingOffsetZ.floatValue.ToString(CultureInfo.InvariantCulture.NumberFormat));
            GUILayout.Label(Styles.atlasOffsetY.text + ": " + m_LightmapTilingOffsetW.floatValue.ToString(CultureInfo.InvariantCulture.NumberFormat));

            var settings = Lightmapping.GetLightingSettingsOrDefaultsFallback();

            float lightmapResolution = settings.lightmapResolution * CalcLODScale(isMeshRenderer) * m_LightmapScale.floatValue;

            if (isMeshRenderer && (m_Renderers != null) && (m_Renderers.Length > 0))
            {
                Transform transform           = m_Renderers[0].GetComponent <Transform>();
                float     lightmapObjectScale = System.Math.Min(System.Math.Min(transform.localScale.x, transform.localScale.y), transform.localScale.z);
                GUILayout.Label(Styles.lightmapResolution.text + ": " + lightmapResolution.ToString(CultureInfo.InvariantCulture.NumberFormat));
                GUILayout.Label(Styles.lightmapObjectScale.text + ": " + lightmapObjectScale.ToString(CultureInfo.InvariantCulture.NumberFormat));
            }

            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            bool showProgressiveInfo = isPrefabAsset || (settings.bakedGI && settings.lightmapper != LightingSettings.Lightmapper.Enlighten);

            if (showProgressiveInfo && Unsupported.IsDeveloperMode())
            {
                Hash128 instanceHash;
                Lightmapping.GetPVRInstanceHash(instanceID, out instanceHash);
                EditorGUILayout.LabelField(Styles.pvrInstanceHash, GUIContent.Temp(instanceHash.ToString()));

                Hash128 atlasHash;
                Lightmapping.GetPVRAtlasHash(instanceID, out atlasHash);
                EditorGUILayout.LabelField(Styles.pvrAtlasHash, GUIContent.Temp(atlasHash.ToString()));

                int atlasInstanceOffset;
                Lightmapping.GetPVRAtlasInstanceOffset(instanceID, out atlasInstanceOffset);
                EditorGUILayout.LabelField(Styles.pvrAtlasInstanceOffset, GUIContent.Temp(atlasInstanceOffset.ToString()));
            }
            EditorGUI.indentLevel -= 1;

            GUILayout.Space(5);
        }
        private void UpdateCachedTexture(GITextureType textureType)
        {
            if (isIndexBased)
            {
                if (isRealtimeLightmap)
                {
                    Hash128[] mainHashes = Lightmapping.GetMainSystemHashes();

                    if (!m_RealtimeTextureHash.isValid || !mainHashes.Contains(m_RealtimeTextureHash))
                    {
                        m_RealtimeTextureHash = mainHashes.ElementAtOrDefault(m_LightmapIndex);
                    }
                }
            }
            else // instance based
            {
                if (isRealtimeLightmap)
                {
                    Hash128 systemHash;

                    if (!Lightmapping.GetInputSystemHash(m_InstanceID, out systemHash))
                    {
                        m_CachedTexture.textureAvailability = GITextureAvailability.GITextureNotAvailable;
                        return;
                    }
                    m_RealtimeTextureHash = systemHash;
                }
                else
                {
                    int lightmapIndex;

                    if (!Lightmapping.GetLightmapIndex(m_InstanceID, out lightmapIndex))
                    {
                        m_CachedTexture.textureAvailability = GITextureAvailability.GITextureNotAvailable;
                        return;
                    }

                    m_LightmapIndex = lightmapIndex;
                }
            }

            Hash128 contentHash = isRealtimeLightmap ? LightmapVisualizationUtility.GetRealtimeGITextureHash(m_RealtimeTextureHash, textureType) :
                                  LightmapVisualizationUtility.GetBakedGITextureHash(m_LightmapIndex, m_InstanceID, textureType);

            // if we need to fetch a new texture
            if (m_CachedTexture.texture == null || m_CachedTexture.type != textureType || m_CachedTexture.contentHash != contentHash || m_CachedTexture.contentHash == new Hash128())
            {
                m_CachedTexture = isRealtimeLightmap ?
                                  LightmapVisualizationUtility.GetRealtimeGITexture(m_RealtimeTextureHash, textureType) :
                                  LightmapVisualizationUtility.GetBakedGITexture(m_LightmapIndex, m_InstanceID, textureType);
            }

            if (!m_ShowUVOverlay)
            {
                return; // if we don't wanna show any overlay
            }
            if (m_CachedTexture.texture == null || m_CachedTexture.textureAvailability == GITextureAvailability.GITextureNotAvailable || m_CachedTexture.textureAvailability == GITextureAvailability.GITextureUnknown)
            {
                return; // if we dont have a texture
            }
            // fetch Renderers

            if (isRealtimeLightmap)
            {
                m_CachedTextureObjects = LightmapVisualizationUtility.GetRealtimeGITextureRenderers(m_RealtimeTextureHash);
            }
            else if (LightmapVisualizationUtility.IsAtlasTextureType(textureType))
            {
                m_CachedTextureObjects = LightmapVisualizationUtility.GetBakedGITextureRenderers(m_LightmapIndex);
            }
            else // if it's an instance based baked lightmap, we only have 1 object in it
            {
                m_CachedTextureObjects = new GameObject[] {}
            };
        }
 public void ObjectPreview(Rect r)
 {
     if (r.height > 0f)
     {
         if (this.m_ZoomablePreview == null)
         {
             this.m_ZoomablePreview           = new ZoomableArea(true);
             this.m_ZoomablePreview.hRangeMin = 0f;
             this.m_ZoomablePreview.vRangeMin = 0f;
             this.m_ZoomablePreview.hRangeMax = 1f;
             this.m_ZoomablePreview.vRangeMax = 1f;
             this.m_ZoomablePreview.SetShownHRange(0f, 1f);
             this.m_ZoomablePreview.SetShownVRange(0f, 1f);
             this.m_ZoomablePreview.uniformScale    = true;
             this.m_ZoomablePreview.scaleWithWindow = true;
         }
         GUI.Box(r, "", "PreBackground");
         Rect position = new Rect(r);
         position.y     += 1f;
         position.height = 18f;
         GUI.Box(position, "", EditorStyles.toolbar);
         Rect position2 = new Rect(r);
         position2.y     += 1f;
         position2.height = 18f;
         position2.width  = 120f;
         Rect rect = new Rect(r);
         rect.yMin  += position2.height;
         rect.yMax  -= 14f;
         rect.width -= 11f;
         int num = Array.IndexOf <GUIContent>(LightingWindowObjectTab.Styles.ObjectPreviewTextureOptions, this.m_SelectedObjectPreviewTexture);
         if (num < 0 || !LightmapVisualizationUtility.IsTextureTypeEnabled(this.kObjectPreviewTextureTypes[num]))
         {
             num = 0;
             this.m_SelectedObjectPreviewTexture = LightingWindowObjectTab.Styles.ObjectPreviewTextureOptions[num];
         }
         if (EditorGUI.DropdownButton(position2, this.m_SelectedObjectPreviewTexture, FocusType.Passive, EditorStyles.toolbarPopup))
         {
             GenericMenu genericMenu = new GenericMenu();
             for (int i = 0; i < LightingWindowObjectTab.Styles.ObjectPreviewTextureOptions.Length; i++)
             {
                 if (LightmapVisualizationUtility.IsTextureTypeEnabled(this.kObjectPreviewTextureTypes[i]))
                 {
                     genericMenu.AddItem(LightingWindowObjectTab.Styles.ObjectPreviewTextureOptions[i], num == i, new GenericMenu.MenuFunction2(this.SelectPreviewTextureOption), LightingWindowObjectTab.Styles.ObjectPreviewTextureOptions.ElementAt(i));
                 }
                 else
                 {
                     genericMenu.AddDisabledItem(LightingWindowObjectTab.Styles.ObjectPreviewTextureOptions.ElementAt(i));
                 }
             }
             genericMenu.DropDown(position2);
         }
         GITextureType gITextureType = this.kObjectPreviewTextureTypes[Array.IndexOf <GUIContent>(LightingWindowObjectTab.Styles.ObjectPreviewTextureOptions, this.m_SelectedObjectPreviewTexture)];
         if (this.m_CachedTexture.type != gITextureType || this.m_CachedTexture.contentHash != LightmapVisualizationUtility.GetSelectedObjectGITextureHash(gITextureType) || this.m_CachedTexture.contentHash == default(Hash128))
         {
             this.m_CachedTexture = LightmapVisualizationUtility.GetSelectedObjectGITexture(gITextureType);
         }
         if (this.m_CachedTexture.textureAvailability == GITextureAvailability.GITextureNotAvailable || this.m_CachedTexture.textureAvailability == GITextureAvailability.GITextureUnknown)
         {
             if (LightmapVisualizationUtility.IsBakedTextureType(gITextureType))
             {
                 if (gITextureType == GITextureType.BakedShadowMask)
                 {
                     GUI.Label(rect, LightingWindowObjectTab.Styles.TextureNotAvailableBakedShadowmask);
                 }
                 else
                 {
                     GUI.Label(rect, LightingWindowObjectTab.Styles.TextureNotAvailableBaked);
                 }
             }
             else
             {
                 GUI.Label(rect, LightingWindowObjectTab.Styles.TextureNotAvailableRealtime);
             }
         }
         else if (this.m_CachedTexture.textureAvailability == GITextureAvailability.GITextureLoading && this.m_CachedTexture.texture == null)
         {
             GUI.Label(rect, LightingWindowObjectTab.Styles.TextureLoading);
         }
         else
         {
             LightmapType lightmapType = LightmapVisualizationUtility.GetLightmapType(gITextureType);
             Event        current      = Event.current;
             EventType    type         = current.type;
             if (type != EventType.ValidateCommand && type != EventType.ExecuteCommand)
             {
                 if (type == EventType.Repaint)
                 {
                     Texture2D texture = this.m_CachedTexture.texture;
                     if (texture && Event.current.type == EventType.Repaint)
                     {
                         Rect rect2 = new Rect(0f, 0f, (float)texture.width, (float)texture.height);
                         rect2 = this.ResizeRectToFit(rect2, rect);
                         rect2 = this.CenterToRect(rect2, rect);
                         rect2 = this.ScaleRectByZoomableArea(rect2, this.m_ZoomablePreview);
                         Rect position3 = new Rect(rect2);
                         position3.x += 3f;
                         position3.y += rect.y + 20f;
                         Rect drawableArea = new Rect(rect);
                         drawableArea.y += position2.height + 3f;
                         float num2 = drawableArea.y - 14f;
                         position3.y    -= num2;
                         drawableArea.y -= num2;
                         FilterMode filterMode = texture.filterMode;
                         texture.filterMode = FilterMode.Point;
                         LightmapVisualizationUtility.DrawTextureWithUVOverlay(texture, Selection.activeGameObject, drawableArea, position3, gITextureType);
                         texture.filterMode = filterMode;
                     }
                 }
             }
             else if (Event.current.commandName == "FrameSelected")
             {
                 Vector4 lightmapTilingOffset = LightmapVisualizationUtility.GetLightmapTilingOffset(lightmapType);
                 Vector2 vector = new Vector2(lightmapTilingOffset.z, lightmapTilingOffset.w);
                 Vector2 lhs    = vector + new Vector2(lightmapTilingOffset.x, lightmapTilingOffset.y);
                 vector = Vector2.Max(vector, Vector2.zero);
                 lhs    = Vector2.Min(lhs, Vector2.one);
                 float y = 1f - vector.y;
                 vector.y = 1f - lhs.y;
                 lhs.y    = y;
                 Rect shownArea = new Rect(vector.x, vector.y, lhs.x - vector.x, lhs.y - vector.y);
                 shownArea.x -= Mathf.Clamp(shownArea.height - shownArea.width, 0f, 3.40282347E+38f) / 2f;
                 shownArea.y -= Mathf.Clamp(shownArea.width - shownArea.height, 0f, 3.40282347E+38f) / 2f;
                 float num3 = Mathf.Max(shownArea.width, shownArea.height);
                 shownArea.height = num3;
                 shownArea.width  = num3;
                 this.m_ZoomablePreview.shownArea = shownArea;
                 Event.current.Use();
             }
             if (this.m_PreviousSelection != Selection.activeInstanceID)
             {
                 this.m_PreviousSelection = Selection.activeInstanceID;
                 this.m_ZoomablePreview.SetShownHRange(0f, 1f);
                 this.m_ZoomablePreview.SetShownVRange(0f, 1f);
             }
             Rect rect3 = new Rect(r);
             rect3.yMin += position2.height;
             this.m_ZoomablePreview.rect = rect3;
             this.m_ZoomablePreview.BeginViewGUI();
             this.m_ZoomablePreview.EndViewGUI();
             GUILayoutUtility.GetRect(r.width, r.height);
         }
     }
 }
        void ShowAtlasGUI(int instanceID)
        {
            if (m_LightmapIndex == null)
            {
                return;
            }

            Hash128 contentHash = LightmapVisualizationUtility.GetBakedGITextureHash(m_LightmapIndex.intValue, 0, GITextureType.Baked);

            // if we need to fetch a new texture
            if (m_CachedBakedTexture.texture == null || m_CachedBakedTexture.contentHash != contentHash)
            {
                m_CachedBakedTexture = LightmapVisualizationUtility.GetBakedGITexture(m_LightmapIndex.intValue, 0, GITextureType.Baked);
            }

            if (m_CachedBakedTexture.texture == null)
            {
                return;
            }

            EditorGUI.indentLevel += 1;

            GUILayout.BeginHorizontal();
            GUILayout.Space(30);

            Rect rect = GUILayoutUtility.GetRect(100, 100, EditorStyles.objectField);

            EditorGUI.Toggle(rect, false, EditorStyles.objectFieldThumb);

            if (rect.Contains(Event.current.mousePosition))
            {
                Object    actualTargetObject = m_CachedBakedTexture.texture;
                Component com = actualTargetObject as Component;

                if (com)
                {
                    actualTargetObject = com.gameObject;
                }

                if (Event.current.clickCount == 2)
                {
                    LightmapPreviewWindow.CreateLightmapPreviewWindow(m_Renderers[0].GetInstanceID(), false, false);
                }
                else if (Event.current.clickCount == 1)
                {
                    EditorGUI.PingObjectOrShowPreviewOnClick(actualTargetObject, GUILayoutUtility.GetLastRect());
                }
            }

            if (Event.current.type == EventType.Repaint)
            {
                rect = EditorStyles.objectFieldThumb.padding.Remove(rect);
                EditorGUI.DrawPreviewTexture(rect, m_CachedBakedTexture.texture);
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            EditorGUILayout.LabelField(Styles.AtlasIndex, GUIContent.Temp(m_LightmapIndex.intValue.ToString()));
            EditorGUILayout.LabelField(Styles.AtlasTilingX, GUIContent.Temp(m_LightmapTilingOffsetX.floatValue.ToString()));
            EditorGUILayout.LabelField(Styles.AtlasTilingY, GUIContent.Temp(m_LightmapTilingOffsetY.floatValue.ToString()));
            EditorGUILayout.LabelField(Styles.AtlasOffsetX, GUIContent.Temp(m_LightmapTilingOffsetZ.floatValue.ToString()));
            EditorGUILayout.LabelField(Styles.AtlasOffsetY, GUIContent.Temp(m_LightmapTilingOffsetW.floatValue.ToString()));

            bool showProgressiveInfo = isPrefabAsset || (m_EnabledBakedGI.boolValue && LightmapEditorSettings.lightmapper != LightmapEditorSettings.Lightmapper.Enlighten);

            if (showProgressiveInfo && Unsupported.IsDeveloperMode())
            {
                Hash128 instanceHash;
                LightmapEditorSettings.GetPVRInstanceHash(instanceID, out instanceHash);
                EditorGUILayout.LabelField(Styles.PVRInstanceHash, GUIContent.Temp(instanceHash.ToString()));

                Hash128 atlasHash;
                LightmapEditorSettings.GetPVRAtlasHash(instanceID, out atlasHash);
                EditorGUILayout.LabelField(Styles.PVRAtlasHash, GUIContent.Temp(atlasHash.ToString()));

                int atlasInstanceOffset;
                LightmapEditorSettings.GetPVRAtlasInstanceOffset(instanceID, out atlasInstanceOffset);
                EditorGUILayout.LabelField(Styles.PVRAtlasInstanceOffset, GUIContent.Temp(atlasInstanceOffset.ToString()));
            }

            EditorGUI.indentLevel -= 1;
        }
Example #8
0
        void ShowAtlasGUI(int instanceID)
        {
            if (m_LightmapIndex == null)
            {
                return;
            }

            Hash128 contentHash = LightmapVisualizationUtility.GetBakedGITextureHash(m_LightmapIndex.intValue, 0, GITextureType.Baked);

            // if we need to fetch a new texture
            if (m_CachedBakedTexture.texture == null || m_CachedBakedTexture.contentHash != contentHash)
            {
                m_CachedBakedTexture = LightmapVisualizationUtility.GetBakedGITexture(m_LightmapIndex.intValue, 0, GITextureType.Baked);
            }

            if (m_CachedBakedTexture.texture == null)
            {
                return;
            }

            m_ShowBakedLM.value = EditorGUILayout.Foldout(m_ShowBakedLM.value, Styles.Atlas, true);

            if (!m_ShowBakedLM.value)
            {
                return;
            }

            EditorGUI.indentLevel += 1;

            GUILayout.BeginHorizontal();

            DrawLightmapPreview(m_CachedBakedTexture.texture, false, instanceID);

            GUILayout.BeginVertical();

            GUILayout.Label(Styles.AtlasIndex.text + ": " + m_LightmapIndex.intValue.ToString());
            GUILayout.Label(Styles.AtlasTilingX.text + ": " + m_LightmapTilingOffsetX.floatValue.ToString(CultureInfo.InvariantCulture.NumberFormat));
            GUILayout.Label(Styles.AtlasTilingY.text + ": " + m_LightmapTilingOffsetY.floatValue.ToString(CultureInfo.InvariantCulture.NumberFormat));
            GUILayout.Label(Styles.AtlasOffsetX.text + ": " + m_LightmapTilingOffsetZ.floatValue.ToString(CultureInfo.InvariantCulture.NumberFormat));
            GUILayout.Label(Styles.AtlasOffsetY.text + ": " + m_LightmapTilingOffsetW.floatValue.ToString(CultureInfo.InvariantCulture.NumberFormat));

            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            bool showProgressiveInfo = isPrefabAsset || (m_EnabledBakedGI.boolValue && LightmapEditorSettings.lightmapper != LightmapEditorSettings.Lightmapper.Enlighten);

            if (showProgressiveInfo && Unsupported.IsDeveloperMode())
            {
                Hash128 instanceHash;
                LightmapEditorSettings.GetPVRInstanceHash(instanceID, out instanceHash);
                EditorGUILayout.LabelField(Styles.PVRInstanceHash, GUIContent.Temp(instanceHash.ToString()));

                Hash128 atlasHash;
                LightmapEditorSettings.GetPVRAtlasHash(instanceID, out atlasHash);
                EditorGUILayout.LabelField(Styles.PVRAtlasHash, GUIContent.Temp(atlasHash.ToString()));

                int atlasInstanceOffset;
                LightmapEditorSettings.GetPVRAtlasInstanceOffset(instanceID, out atlasInstanceOffset);
                EditorGUILayout.LabelField(Styles.PVRAtlasInstanceOffset, GUIContent.Temp(atlasInstanceOffset.ToString()));
            }
            EditorGUI.indentLevel -= 1;

            GUILayout.Space(5);
        }
        public void ObjectPreview(Rect r)
        {
            if (r.height <= 0)
            {
                return;
            }

            if (m_ZoomablePreview == null)
            {
                m_ZoomablePreview = new ZoomableArea(true);

                m_ZoomablePreview.hRangeMin = 0.0f;
                m_ZoomablePreview.vRangeMin = 0.0f;

                m_ZoomablePreview.hRangeMax = 1.0f;
                m_ZoomablePreview.vRangeMax = 1.0f;

                m_ZoomablePreview.SetShownHRange(0, 1);
                m_ZoomablePreview.SetShownVRange(0, 1);

                m_ZoomablePreview.uniformScale    = true;
                m_ZoomablePreview.scaleWithWindow = true;
            }

            // Draw background
            GUI.Box(r, "", "PreBackground");

            // Top menu rect
            Rect menuRect = new Rect(r);

            menuRect.y     += 1;
            menuRect.height = 18;
            GUI.Box(menuRect, "", EditorStyles.toolbar);

            // Top menu dropdown
            Rect dropRect = new Rect(r);

            dropRect.y     += 1;
            dropRect.height = 18;
            dropRect.width  = 120;

            // Drawable area
            Rect drawableArea = new Rect(r);

            drawableArea.yMin  += dropRect.height;
            drawableArea.yMax  -= 14;
            drawableArea.width -= 11;

            int index = Array.IndexOf(Styles.ObjectPreviewTextureOptions, m_SelectedObjectPreviewTexture);

            if (index < 0 || !LightmapVisualizationUtility.IsTextureTypeEnabled(kObjectPreviewTextureTypes[index]))
            {
                index = 0;
                m_SelectedObjectPreviewTexture = Styles.ObjectPreviewTextureOptions[index];
            }

            if (EditorGUI.DropdownButton(dropRect, m_SelectedObjectPreviewTexture, FocusType.Passive, EditorStyles.toolbarPopup))
            {
                GenericMenu menu = new GenericMenu();

                for (int i = 0; i < Styles.ObjectPreviewTextureOptions.Length; i++)
                {
                    if (LightmapVisualizationUtility.IsTextureTypeEnabled(kObjectPreviewTextureTypes[i]))
                    {
                        menu.AddItem(Styles.ObjectPreviewTextureOptions[i], index == i, SelectPreviewTextureOption, Styles.ObjectPreviewTextureOptions.ElementAt(i));
                    }
                    else
                    {
                        menu.AddDisabledItem(Styles.ObjectPreviewTextureOptions.ElementAt(i));
                    }
                }
                menu.DropDown(dropRect);
            }

            GITextureType textureType = kObjectPreviewTextureTypes[Array.IndexOf(Styles.ObjectPreviewTextureOptions, m_SelectedObjectPreviewTexture)];

            if (m_CachedTexture.type != textureType || m_CachedTexture.contentHash != LightmapVisualizationUtility.GetSelectedObjectGITextureHash(textureType) || m_CachedTexture.contentHash == new Hash128())
            {
                m_CachedTexture = LightmapVisualizationUtility.GetSelectedObjectGITexture(textureType);
            }

            if (m_CachedTexture.textureAvailability == GITextureAvailability.GITextureNotAvailable || m_CachedTexture.textureAvailability == GITextureAvailability.GITextureUnknown)
            {
                if (LightmapVisualizationUtility.IsBakedTextureType(textureType))
                {
                    if (textureType == GITextureType.BakedShadowMask)
                    {
                        GUI.Label(drawableArea, Styles.TextureNotAvailableBakedShadowmask);
                    }
                    else
                    {
                        GUI.Label(drawableArea, Styles.TextureNotAvailableBaked);
                    }
                }
                else
                {
                    GUI.Label(drawableArea, Styles.TextureNotAvailableRealtime);
                }

                return;
            }

            if (m_CachedTexture.textureAvailability == GITextureAvailability.GITextureLoading && m_CachedTexture.texture == null)
            {
                GUI.Label(drawableArea, Styles.TextureLoading);

                return;
            }

            LightmapType lightmapType = LightmapVisualizationUtility.GetLightmapType(textureType);

            // Framing and drawing
            var evt = Event.current;

            switch (evt.type)
            {
            // 'F' will zoom to uv bounds
            case EventType.ValidateCommand:
            case EventType.ExecuteCommand:

                if (Event.current.commandName == EventCommandNames.FrameSelected)
                {
                    Vector4 lightmapTilingOffset = LightmapVisualizationUtility.GetLightmapTilingOffset(lightmapType);

                    Vector2 min = new Vector2(lightmapTilingOffset.z, lightmapTilingOffset.w);
                    Vector2 max = min + new Vector2(lightmapTilingOffset.x, lightmapTilingOffset.y);

                    min = Vector2.Max(min, Vector2.zero);
                    max = Vector2.Min(max, Vector2.one);

                    float swap = 1f - min.y;
                    min.y = 1f - max.y;
                    max.y = swap;

                    // Make sure that the focus rectangle is a even square
                    Rect rect = new Rect(min.x, min.y, max.x - min.x, max.y - min.y);
                    rect.x    -= Mathf.Clamp(rect.height - rect.width, 0, float.MaxValue) / 2;
                    rect.y    -= Mathf.Clamp(rect.width - rect.height, 0, float.MaxValue) / 2;
                    rect.width = rect.height = Mathf.Max(rect.width, rect.height);

                    m_ZoomablePreview.shownArea = rect;
                    Event.current.Use();
                }
                break;

            // Scale and draw texture and uv's
            case EventType.Repaint:

                Texture2D texture = m_CachedTexture.texture;
                if (texture && Event.current.type == EventType.Repaint)
                {
                    Rect textureRect = new Rect(0, 0, texture.width, texture.height);
                    textureRect = ResizeRectToFit(textureRect, drawableArea);
                    //textureRect.x = -textureRect.width / 2;
                    //textureRect.y = -textureRect.height / 2;
                    textureRect = CenterToRect(textureRect, drawableArea);
                    textureRect = ScaleRectByZoomableArea(textureRect, m_ZoomablePreview);

                    // Draw texture and UV
                    Rect uvRect = new Rect(textureRect);
                    uvRect.x += 3;
                    uvRect.y += drawableArea.y + 20;

                    Rect clipRect = new Rect(drawableArea);
                    clipRect.y += dropRect.height + 3;

                    // fix 635838 - We need to offset the rects for rendering.
                    {
                        float offset = clipRect.y - 14;
                        uvRect.y   -= offset;
                        clipRect.y -= offset;
                    }

                    // Texture shouldn't be filtered since it will make previewing really blurry
                    FilterMode prevMode = texture.filterMode;
                    texture.filterMode = FilterMode.Point;

                    LightmapVisualizationUtility.DrawTextureWithUVOverlay(texture, Selection.activeGameObject, clipRect, uvRect, textureType);
                    texture.filterMode = prevMode;
                }
                break;
            }

            // Reset zoom if selection is changed
            if (m_PreviousSelection != Selection.activeInstanceID)
            {
                m_PreviousSelection = Selection.activeInstanceID;
                m_ZoomablePreview.SetShownHRange(0, 1);
                m_ZoomablePreview.SetShownVRange(0, 1);
            }

            // Handle zoomable area
            Rect zoomRect = new Rect(r);

            zoomRect.yMin         += dropRect.height;
            m_ZoomablePreview.rect = zoomRect;

            m_ZoomablePreview.BeginViewGUI();
            m_ZoomablePreview.EndViewGUI();

            GUILayoutUtility.GetRect(r.width, r.height);
        }
 private static extern void INTERNAL_CALL_GetSelectedObjectGITextureInternal(GITextureType textureType, ref VisualisationGITexture result);
 private static void GetSelectedObjectGITextureInternal(GITextureType textureType, ref VisualisationGITexture result)
 {
     LightmapVisualizationUtility.INTERNAL_CALL_GetSelectedObjectGITextureInternal(textureType, ref result);
 }