UnityEditor.LightingWindowObjectTab.ObjectPreview C# (CSharp) Method

ObjectPreview() public method

public ObjectPreview ( Rect r ) : void
r UnityEngine.Rect
return void
        public void ObjectPreview(Rect r)
        {
            if (r.height > 0f)
            {
                if (s_Styles == null)
                {
                    s_Styles = new Styles();
                }
                List<Texture2D> list = new List<Texture2D>();
                foreach (GITextureType type in this.kObjectPreviewTextureTypes)
                {
                    list.Add(LightmapVisualizationUtility.GetGITexture(type));
                }
                if (list.Count != 0)
                {
                    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++;
                    position.height = 18f;
                    GUI.Box(position, "", EditorStyles.toolbar);
                    Rect rect2 = new Rect(r);
                    rect2.y++;
                    rect2.height = 18f;
                    rect2.width = 120f;
                    Rect to = new Rect(r);
                    to.yMin += rect2.height;
                    to.yMax -= 14f;
                    to.width -= 11f;
                    int index = Array.IndexOf<GUIContent>(kObjectPreviewTextureOptions, this.m_SelectedObjectPreviewTexture);
                    if (index < 0)
                    {
                        index = 0;
                    }
                    index = EditorGUI.Popup(rect2, index, kObjectPreviewTextureOptions, EditorStyles.toolbarPopup);
                    if (index >= kObjectPreviewTextureOptions.Length)
                    {
                        index = 0;
                    }
                    this.m_SelectedObjectPreviewTexture = kObjectPreviewTextureOptions[index];
                    LightmapType lightmapType = ((this.kObjectPreviewTextureTypes[index] != GITextureType.Baked) && (this.kObjectPreviewTextureTypes[index] != GITextureType.BakedDirectional)) ? LightmapType.DynamicLightmap : LightmapType.StaticLightmap;
                    bool flag = ((this.kObjectPreviewTextureTypes[index] == GITextureType.Baked) || (this.kObjectPreviewTextureTypes[index] == GITextureType.BakedDirectional)) && (LightmapSettings.lightmapsMode == LightmapsMode.SeparateDirectional);
                    if (flag)
                    {
                        GUIContent content = GUIContent.Temp("Indirect");
                        Rect rect4 = rect2;
                        rect4.x += rect2.width;
                        rect4.width = EditorStyles.toolbarButton.CalcSize(content).x;
                        this.m_HasSeparateIndirectUV = GUI.Toggle(rect4, this.m_HasSeparateIndirectUV, content.text, EditorStyles.toolbarButton);
                    }
                    switch (Event.current.type)
                    {
                        case EventType.ValidateCommand:
                        case EventType.ExecuteCommand:
                            if (Event.current.commandName == "FrameSelected")
                            {
                                Vector4 lightmapTilingOffset = LightmapVisualizationUtility.GetLightmapTilingOffset(lightmapType);
                                Vector2 lhs = new Vector2(lightmapTilingOffset.z, lightmapTilingOffset.w);
                                Vector2 vector4 = lhs + new Vector2(lightmapTilingOffset.x, lightmapTilingOffset.y);
                                lhs = Vector2.Max(lhs, Vector2.zero);
                                vector4 = Vector2.Min(vector4, Vector2.one);
                                float num3 = 1f - lhs.y;
                                lhs.y = 1f - vector4.y;
                                vector4.y = num3;
                                Rect rect5 = new Rect(lhs.x, lhs.y, vector4.x - lhs.x, vector4.y - lhs.y);
                                rect5.x -= Mathf.Clamp(rect5.height - rect5.width, 0f, float.MaxValue) / 2f;
                                rect5.y -= Mathf.Clamp(rect5.width - rect5.height, 0f, float.MaxValue) / 2f;
                                float num4 = Mathf.Max(rect5.width, rect5.height);
                                rect5.height = num4;
                                rect5.width = num4;
                                if (flag && this.m_HasSeparateIndirectUV)
                                {
                                    rect5.x += 0.5f;
                                }
                                this.m_ZoomablePreview.shownArea = rect5;
                                Event.current.Use();
                            }
                            break;

                        case EventType.Repaint:
                        {
                            Texture2D texture = list[index];
                            if ((texture != null) && (Event.current.type == EventType.Repaint))
                            {
                                Rect rect = new Rect(0f, 0f, (float) texture.width, (float) texture.height);
                                rect = this.ResizeRectToFit(rect, to);
                                rect = this.CenterToRect(rect, to);
                                rect = this.ScaleRectByZoomableArea(rect, this.m_ZoomablePreview);
                                Rect rect7 = new Rect(rect);
                                rect7.x += 3f;
                                rect7.y += to.y + 20f;
                                Rect drawableArea = new Rect(to);
                                drawableArea.y += rect2.height + 3f;
                                float num5 = drawableArea.y - 14f;
                                rect7.y -= num5;
                                drawableArea.y -= num5;
                                FilterMode filterMode = texture.filterMode;
                                texture.filterMode = FilterMode.Point;
                                GITextureType textureType = this.kObjectPreviewTextureTypes[index];
                                bool drawSpecularUV = flag && this.m_HasSeparateIndirectUV;
                                LightmapVisualizationUtility.DrawTextureWithUVOverlay(texture, Selection.activeGameObject, drawableArea, rect7, textureType, drawSpecularUV);
                                texture.filterMode = filterMode;
                            }
                            break;
                        }
                    }
                    if (this.m_PreviousSelection != Selection.activeInstanceID)
                    {
                        this.m_PreviousSelection = Selection.activeInstanceID;
                        this.m_ZoomablePreview.SetShownHRange(0f, 1f);
                        this.m_ZoomablePreview.SetShownVRange(0f, 1f);
                    }
                    Rect rect9 = new Rect(r);
                    rect9.yMin += rect2.height;
                    this.m_ZoomablePreview.rect = rect9;
                    this.m_ZoomablePreview.BeginViewGUI();
                    this.m_ZoomablePreview.EndViewGUI();
                    GUILayoutUtility.GetRect(r.width, r.height);
                }
            }
        }