private void LightmapField(Texture2D lightmap, int index, Hash128 hash)
        {
            Rect rect = GUILayoutUtility.GetRect(100, 100, EditorStyles.objectField);

            if (EditorGUI.Toggle(rect, index == m_SelectedLightmapIndex, EditorStyles.objectFieldThumb))
            {
                m_SelectedLightmapIndex = index;

                if (rect.Contains(Event.current.mousePosition))
                {
                    Object    actualTargetObject = lightmap;
                    Component com = actualTargetObject as Component;
                    if (com)
                    {
                        actualTargetObject = com.gameObject;
                    }

                    if (Event.current.clickCount == 1)
                    {
                        EditorGUI.PingObjectOrShowPreviewOnClick(actualTargetObject, GUILayoutUtility.GetLastRect());
                    }

                    if (Event.current.clickCount == 2)
                    {
                        if (isRealtimeLightmap)
                        {
                            LightmapPreviewWindow.CreateLightmapPreviewWindow(m_SelectedLightmapIndex, true, true);
                        }
                        else
                        {
                            LightmapPreviewWindow.CreateLightmapPreviewWindow(m_SelectedLightmapIndex, false, true);
                        }
                    }
                }
            }

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

                if ((!isRealtimeLightmap && index == m_ActiveGameObjectLightmapIndex) || (isRealtimeLightmap && hash == m_ActiveGameObjectTextureHash))
                {
                    Styles.SelectedLightmapHighlight.Draw(rect, false, false, false, false);

                    if (m_ShouldScrollToLightmapIndex)
                    {
                        GUI.ScrollTo(rect);

                        m_ShouldScrollToLightmapIndex = false;
                        GUIView.current.Repaint();
                    }
                }
            }
        }
        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();
        }
예제 #3
0
        private void DrawLightmapPreview(Texture2D texture, bool realtimeLightmap, int instanceId)
        {
            GUILayout.Space(Styles.previewPadding);

            int previewWidth = Styles.previewWidth - 4; // padding

            Rect rect       = GUILayoutUtility.GetRect(previewWidth, previewWidth, EditorStyles.objectField);
            Rect buttonRect = new Rect(rect.xMax - 70, rect.yMax - 14, 70, 14);

            if (Event.current.type == EventType.MouseDown)
            {
                if ((buttonRect.Contains(Event.current.mousePosition) && Event.current.clickCount == 1) ||
                    (rect.Contains(Event.current.mousePosition) && Event.current.clickCount == 2))
                {
                    LightmapPreviewWindow.CreateLightmapPreviewWindow(instanceId, realtimeLightmap, false);
                }
                else if (rect.Contains(Event.current.mousePosition) && Event.current.clickCount == 1)
                {
                    Object    actualTargetObject = texture;
                    Component com = actualTargetObject as Component;

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

                    EditorGUI.PingObjectOrShowPreviewOnClick(actualTargetObject, rect);
                }
            }

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

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

                Styles.openPreviewStyle.Draw(rect, Styles.openPreview, false, false, false, false);
            }

            float spacing = Mathf.Max(5.0f, EditorGUIUtility.labelWidth - Styles.previewPadding - Styles.previewWidth);

            GUILayout.Space(spacing);
        }
        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;
        }