/// <summary> /// Updates the preview coroutine, using the preview relative settings like guides. /// </summary> public IEnumerator UpdatePreviewCoroutine() { if (m_IsCapturing) { yield break; } m_IsCapturing = true; // Delegate call onCaptureBeginDelegate(); // Update resolutions m_PreviewList.Clear(); m_PreviewList.Add(m_Config.GetFirstActiveResolution()); m_Config.UpdateGameviewResolution(); // Update overlays & guides m_PreviewOverlayList.Clear(); m_PreviewOverlayList.AddRange(m_Config.m_Overlays); if (m_Config.m_ShowGuidesInPreview) { m_GuidesOverlay = new ScreenshotOverlay(m_Config.m_GuideCanvas); m_PreviewOverlayList.Add(m_GuidesOverlay); ShowGuides(); } // Capture preview InitScreenshotTaker(); yield return(StartCoroutine(m_ScreenshotTaker.CaptureAllCoroutine(m_PreviewList, m_Config.GetActiveCameras(), m_PreviewOverlayList, (m_Config.m_CaptureMode == ScreenshotTaker.CaptureMode.GAMEVIEW_RESIZING && m_Config.m_ResolutionCaptureMode == ScreenshotConfig.ResolutionMode.GAME_VIEW) ? ScreenshotTaker.CaptureMode.FIXED_GAMEVIEW : m_Config.m_CaptureMode, (int)m_Config.m_MultisamplingAntiAliasing, m_Config.m_CaptureActiveUICanvas, m_Config.m_ColorFormat, m_Config.m_RecomputeAlphaLayer, m_Config.m_StopTimeOnCapture))); // Restore guides if (Application.isPlaying && m_Config.m_PreviewInGameViewWhilePlaying && m_Config.m_ShowGuidesInPreview) { ShowGuides(); } else { HideGuides(); } // Delegate call onCaptureEndDelegate(); m_IsCapturing = false; }
public void DrawPreviewGUI() { // Title m_Config.m_ShowPreviewGUI = EditorGUILayout.Foldout(m_Config.m_ShowPreviewGUI, "Preview".ToUpper()); if (m_Config.m_ShowPreviewGUI == false) { return; } EditorGUILayout.Separator(); EditorGUILayout.PropertyField(m_PreviewInGameViewWhilePlaying); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.PropertyField(m_ShowGuidesInPreview); EditorGUILayout.PropertyField(m_GuideCanvas); EditorGUILayout.PropertyField(m_GuidesColor); EditorGUILayout.Separator(); EditorGUILayout.PropertyField(m_ShowPreview); if (m_Config.m_ShowPreview) { EditorGUILayout.Slider(m_PreviewSize, 0.05f, 1f); // Draw preview texture if any if (m_Config.GetFirstActiveResolution().m_Texture != null) { // On repaint event, compute the preview dimensions and update the texture if needed #if UNITY_2017_3_OR_NEWER if (Event.current.type == EventType.Repaint) { #else if (Event.current.type == EventType.repaint) { #endif if (m_Config.GetFirstActiveResolution().IsValid()) { m_PreviewWidth = m_Config.m_PreviewSize * GUILayoutUtility.GetLastRect().width; m_PreviewHeight = m_PreviewWidth * m_Config.GetFirstActiveResolution().m_Texture.height / m_Config.GetFirstActiveResolution().m_Texture.width; } } // Draw an empty label to make some place to display the preview texture EditorGUILayout.LabelField("", GUILayout.Height(m_PreviewHeight)); Rect previewRect = GUILayoutUtility.GetLastRect(); previewRect.x = previewRect.x + previewRect.width / 2 - m_PreviewWidth / 2; previewRect.width = m_PreviewWidth; previewRect.height = m_PreviewHeight; EditorGUI.DrawPreviewTexture(previewRect, m_Config.GetFirstActiveResolution().m_Texture); } else { EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Press update to create the preview image.", UIStyle.centeredGreyTextStyle); EditorGUILayout.Separator(); } } }