private void PlayPreview() { m_PreviewID = VideoUtil.StartPreview(m_PlayingClip); VideoUtil.PlayPreview(m_PreviewID, true); }
public override void OnPreviewGUI(Rect r, GUIStyle background) { VideoClip clip = target as VideoClip; Event evt = Event.current; if (evt.type != EventType.Repaint && evt.type != EventType.Layout && evt.type != EventType.Used) { switch (evt.type) { case EventType.MouseDown: { if (r.Contains(evt.mousePosition)) { if (m_PlayingClip != null) { if (m_PreviewID.Empty() || !VideoUtil.IsPreviewPlaying(m_PreviewID)) { PlayPreview(); } else { StopPreview(); } } evt.Use(); } } break; } return; } if (clip != m_PlayingClip) { StopPreview(); m_PlayingClip = clip; } Texture image = null; if (!m_PreviewID.Empty() && VideoUtil.IsPreviewPlaying(m_PreviewID)) { image = VideoUtil.GetPreviewTexture(m_PreviewID); if (image != null && m_UseAssetPreview) { m_UseAssetPreview = false; } } else { image = GetAssetPreviewTexture(); } if (image != null && image.width != 0 && image.height != 0) { m_Texture = image; } if (!m_Texture) { return; } if (Event.current.type == EventType.Repaint) { background.Draw(r, false, false, false, false); } float previewWidth = m_Texture.width; float previewHeight = m_Texture.height; if (m_PlayingClip.pixelAspectRatioDenominator > 0) { float pixelAspectRatio = (float)m_PlayingClip.pixelAspectRatioNumerator / (float)m_PlayingClip.pixelAspectRatioDenominator; if (pixelAspectRatio > 1.0F) { previewWidth *= pixelAspectRatio; } else { previewHeight /= pixelAspectRatio; } } float zoomLevel = 1.0f; if ((r.width / previewWidth * previewHeight) > r.height) { zoomLevel = r.height / previewHeight; } else { zoomLevel = r.width / previewWidth; } zoomLevel = Mathf.Clamp01(zoomLevel); Rect wantedRect = !m_UseAssetPreview ? new Rect(r.x, r.y, previewWidth * zoomLevel, m_Texture.height * zoomLevel) : r; PreviewGUI.BeginScrollView( r, m_Position, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb"); if (!m_UseAssetPreview) { EditorGUI.DrawTextureTransparent(wantedRect, m_Texture, ScaleMode.StretchToFill); } else { GUI.DrawTexture(wantedRect, m_Texture, ScaleMode.ScaleToFit); } m_Position = PreviewGUI.EndScrollView(); if (!m_PreviewID.Empty() && VideoUtil.IsPreviewPlaying(m_PreviewID) && Event.current.type == EventType.Repaint) { GUIView.current.Repaint(); } }
public override void OnPreviewGUI(Rect r, GUIStyle background) { VideoClip videoClip = base.target as VideoClip; Event current = Event.current; if (current.type != EventType.Repaint && current.type != EventType.Layout && current.type != EventType.Used) { EventType type = current.type; if (type == EventType.MouseDown) { if (r.Contains(current.mousePosition)) { if (this.m_PlayingClip != null) { if (this.m_PreviewID.Empty() || !VideoUtil.IsPreviewPlaying(this.m_PreviewID)) { this.PlayPreview(); } else { this.StopPreview(); } } current.Use(); } } } else { bool flag = true; bool flag2 = videoClip != this.m_PlayingClip || (!this.m_PreviewID.Empty() && VideoUtil.IsPreviewPlaying(this.m_PreviewID)); if (videoClip != this.m_PlayingClip) { this.StopPreview(); this.m_PlayingClip = videoClip; } Texture texture = null; if (!this.m_PreviewID.Empty()) { texture = VideoUtil.GetPreviewTexture(this.m_PreviewID); } if (texture == null || texture.width == 0 || texture.height == 0) { texture = this.GetAssetPreviewTexture(); flag = false; } if (!(texture == null) && texture.width != 0 && texture.height != 0) { if (Event.current.type == EventType.Repaint) { background.Draw(r, false, false, false, false); } float num = (float)texture.width; float num2 = (float)texture.height; if (this.m_PlayingClip.pixelAspectRatioDenominator > 0u) { num *= this.m_PlayingClip.pixelAspectRatioNumerator / this.m_PlayingClip.pixelAspectRatioDenominator; } float num3; if (r.width / num * num2 > r.height) { num3 = r.height / num2; } else { num3 = r.width / num; } num3 = Mathf.Clamp01(num3); Rect rect = (!flag) ? r : new Rect(r.x, r.y, num * num3, (float)texture.height * num3); PreviewGUI.BeginScrollView(r, this.m_Position, rect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb"); if (flag) { EditorGUI.DrawTextureTransparent(rect, texture, ScaleMode.StretchToFill); } else { GUI.DrawTexture(rect, texture, ScaleMode.ScaleToFit); } this.m_Position = PreviewGUI.EndScrollView(); if (flag2) { GUIView.current.Repaint(); } } } }