public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }
            WebCamTexture webCamTexture = base.target as WebCamTexture;
            float         num           = Mathf.Min(Mathf.Min(r.width / (float)webCamTexture.width, r.height / (float)webCamTexture.height), 1f);
            Rect          rect          = new Rect(r.x, r.y, (float)webCamTexture.width * num, (float)webCamTexture.height * num);

            PreviewGUI.BeginScrollView(r, this.m_Pos, rect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
            GUI.DrawTexture(rect, webCamTexture, ScaleMode.StretchToFill, false);
            this.m_Pos = PreviewGUI.EndScrollView();
            if (webCamTexture.isPlaying)
            {
                GUIView.current.Repaint();
            }
            if (Application.isPlaying)
            {
                if (webCamTexture.isPlaying)
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y + 10f, r.width, 20f), "Can't pause preview when in play mode");
                }
                else
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y + 10f, r.width, 20f), "Can't start preview when in play mode");
                }
            }
        }
Ejemplo n.º 2
0
 public override void OnPreviewGUI(Rect r, GUIStyle background)
 {
     if (!ShaderUtil.hardwareSupportsRectRenderTexture || !SystemInfo.supports3DTextures)
     {
         if (Event.current.type != EventType.Repaint)
         {
             return;
         }
         EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40f), "3D texture preview not supported");
     }
     else
     {
         this.m_PreviewDir = PreviewGUI.Drag2D(this.m_PreviewDir, r);
         if (Event.current.type != EventType.Repaint)
         {
             return;
         }
         this.InitPreview();
         this.m_Material.mainTexture = this.target as Texture;
         this.m_PreviewUtility.BeginPreview(r, background);
         bool fog = RenderSettings.fog;
         Unsupported.SetRenderSettingsUseFogNoDirty(false);
         this.m_PreviewUtility.m_Camera.transform.position = -Vector3.forward * 3f;
         this.m_PreviewUtility.m_Camera.transform.rotation = Quaternion.identity;
         this.m_PreviewUtility.DrawMesh(this.m_Mesh, Vector3.zero, Quaternion.Euler(this.m_PreviewDir.y, 0.0f, 0.0f) * Quaternion.Euler(0.0f, this.m_PreviewDir.x, 0.0f), this.m_Material, 0);
         this.m_PreviewUtility.m_Camera.Render();
         Unsupported.SetRenderSettingsUseFogNoDirty(fog);
         this.m_PreviewUtility.EndAndDrawPreview(r);
     }
 }
Ejemplo n.º 3
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (!SystemInfo.supportsCubemapArrayTextures || (m_Material != null && !m_Material.shader.isSupported))
            {
                if (Event.current.type == EventType.Repaint)
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40), "Cubemap array preview is not supported");
                }
                return;
            }

            CubemapArray t = (CubemapArray)target;

            m_Material.mainTexture = t;

            m_PreviewUtility.BeginPreview(r, background);
            const float previewDistance = 6.0f;

            m_PreviewDir = PreviewGUI.Drag2D(m_PreviewDir, r);

            m_PreviewUtility.camera.transform.position = -Vector3.forward * previewDistance;
            m_PreviewUtility.camera.transform.rotation = Quaternion.identity;
            Quaternion rot = Quaternion.Euler(m_PreviewDir.y, 0, 0) * Quaternion.Euler(0, m_PreviewDir.x, 0);

            m_PreviewUtility.DrawMesh(m_Mesh, Vector3.zero, rot, m_Material, 0);
            m_PreviewUtility.Render();
            Texture renderedTexture = m_PreviewUtility.EndPreview();

            GUI.DrawTexture(r, renderedTexture, ScaleMode.StretchToFill, false);

            EditorGUI.DropShadowLabel(new Rect(r.x, r.y + 10, r.width, 30),
                                      "Slice " + m_Slice + "\nMip " + m_Mip);
        }
        public override void OnPreviewSettings()
        {
            MovieTextureInspector.Init();
            EditorGUI.BeginDisabledGroup(Application.isPlaying || base.targets.Length > 1);
            MovieTexture movieTexture = this.target as MovieTexture;
            AudioClip    audioClip    = movieTexture.audioClip;
            bool         flag         = PreviewGUI.CycleButton((!movieTexture.isPlaying) ? 0 : 1, MovieTextureInspector.s_PlayIcons) != 0;

            if (flag != movieTexture.isPlaying)
            {
                if (flag)
                {
                    movieTexture.Stop();
                    movieTexture.Play();
                    if (audioClip != null)
                    {
                        AudioUtil.PlayClip(audioClip);
                    }
                }
                else
                {
                    movieTexture.Pause();
                    if (audioClip != null)
                    {
                        AudioUtil.PauseClip(audioClip);
                    }
                }
            }
            EditorGUI.EndDisabledGroup();
        }
        public override void OnPreviewSettings()
        {
            MovieTextureInspector.Init();
            EditorGUI.BeginDisabledGroup(Application.isPlaying || this.targets.Length > 1);
            MovieTexture target    = this.target as MovieTexture;
            AudioClip    audioClip = target.audioClip;
            bool         flag      = PreviewGUI.CycleButton(!target.isPlaying ? 0 : 1, MovieTextureInspector.s_PlayIcons) != 0;

            if (flag != target.isPlaying)
            {
                if (flag)
                {
                    target.Stop();
                    target.Play();
                    if ((Object)audioClip != (Object)null)
                    {
                        AudioUtil.PlayClip(audioClip);
                    }
                }
                else
                {
                    target.Pause();
                    if ((Object)audioClip != (Object)null)
                    {
                        AudioUtil.PauseClip(audioClip);
                    }
                }
            }
            EditorGUI.EndDisabledGroup();
        }
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }
            MovieTexture target = this.target as MovieTexture;
            float        num    = Mathf.Min(Mathf.Min(r.width / (float)target.width, r.height / (float)target.height), 1f);
            Rect         rect   = new Rect(r.x, r.y, (float)target.width * num, (float)target.height * num);

            PreviewGUI.BeginScrollView(r, this.m_Pos, rect, (GUIStyle)"PreHorizontalScrollbar", (GUIStyle)"PreHorizontalScrollbarThumb");
            EditorGUI.DrawPreviewTexture(rect, (Texture)target, (Material)null, ScaleMode.StretchToFill);
            this.m_Pos = PreviewGUI.EndScrollView();
            if (target.isPlaying)
            {
                GUIView.current.Repaint();
            }
            if (!Application.isPlaying)
            {
                return;
            }
            if (target.isPlaying)
            {
                EditorGUI.DropShadowLabel(new Rect(r.x, r.y + 10f, r.width, 20f), "Can't pause preview when in play mode");
            }
            else
            {
                EditorGUI.DropShadowLabel(new Rect(r.x, r.y + 10f, r.width, 20f), "Can't start preview when in play mode");
            }
        }
Ejemplo n.º 7
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40), "Preview requires\nrender texture support");
                }
                return;
            }

            InitPreview();

            m_Settings.previewDir = PreviewGUI.Drag2D(m_Settings.previewDir, r);

            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            m_PreviewUtility.BeginPreview(r, background);

            DoRenderPreview(m_PreviewShaded);

            m_PreviewUtility.EndAndDrawPreview(r);
        }
Ejemplo n.º 8
0
 public void OnPreviewGUI(Texture t, Rect r, GUIStyle background)
 {
     if (!(t == null))
     {
         if (!ShaderUtil.hardwareSupportsRectRenderTexture)
         {
             if (Event.current.type == EventType.Repaint)
             {
                 EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40f), "Cubemap preview requires\nrender texture support");
             }
         }
         else
         {
             this.m_PreviewDir = PreviewGUI.Drag2D(this.m_PreviewDir, r);
             if (Event.current.type == EventType.Repaint)
             {
                 this.InitPreview();
                 this.m_PreviewUtility.BeginPreview(r, background);
                 this.RenderCubemap(t, this.m_PreviewDir, 6f);
                 Texture image = this.m_PreviewUtility.EndPreview();
                 GUI.DrawTexture(r, image, ScaleMode.StretchToFill, false);
                 if (this.mipLevel != 0f)
                 {
                     EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20f), "Mip " + this.mipLevel);
                 }
             }
         }
     }
 }
        /// <inheritdoc/>
        protected internal override void Initialize()
        {
            LoadResource();

            SpriteTexture spriteTexture = InspectedObject as SpriteTexture;

            if (spriteTexture == null)
            {
                return;
            }

            genericDrawer = new GenericInspectorDrawer(spriteTexture, this, Layout);

            GUILayout previewLayout = PreviewGUI.AddLayoutY();

            previewTitleLayout = GUILayoutWithBackground.Create <GUILayoutX>(previewLayout, Builtin.WhiteTexture,
                                                                             new Color(0.129f, 0.129f, 0.129f), new RectOffset(11, 0, 2, 0));

            GUILabel title = new GUILabel(new LocEdString("Preview"));

            previewTitleLayout.Layout.AddElement(title);
            previewTitleLayout.Layout.AddFlexibleSpace();

            previewContentLayout = GUILayoutWithBackground.Create <GUILayoutX>(previewLayout, Builtin.WhiteTexture,
                                                                               new Color(0.09f, 0.09f, 0.09f), new RectOffset(5, 5, 5, 5));

            previewContentLayout.MainPanel.SetHeight(250);

            previewTexture = new GUITexture(spriteTexture, GUITextureScaleMode.ScaleToFit,
                                            GUIOption.FlexibleWidth(), GUIOption.FlexibleHeight());
            previewContentLayout.Layout.AddElement(previewTexture);
        }
Ejemplo n.º 10
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }

            Texture2D mask = (Texture2D)m_DiffuseTexture.objectReferenceValue;

            if (mask == null)
            {
                mask         = EditorGUIUtility.whiteTexture;
                m_HasChanged = true;
            }

            int texWidth  = Mathf.Min(mask.width, 256);
            int texHeight = Mathf.Min(mask.height, 256);

            float zoomLevel  = Mathf.Min(Mathf.Min(r.width / texWidth, r.height / texHeight), 1);
            Rect  wantedRect = new Rect(r.x, r.y, texWidth * zoomLevel, texHeight * zoomLevel);

            PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");

            EditorGUI.DrawPreviewTexture(wantedRect, mask);

            m_Pos = PreviewGUI.EndScrollView();
        }
Ejemplo n.º 11
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }

            TerrainLayer terrainLayer = (TerrainLayer)target;

            Texture2D mask = terrainLayer.diffuseTexture;

            if (mask != null)
            {
                int texWidth  = Mathf.Min(mask.width, 256);
                int texHeight = Mathf.Min(mask.height, 256);

                float zoomLevel  = Mathf.Min(Mathf.Min(r.width / texWidth, r.height / texHeight), 1);
                Rect  wantedRect = new Rect(r.x, r.y, texWidth * zoomLevel, texHeight * zoomLevel);
                PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");

                EditorGUI.DrawPreviewTexture(wantedRect, mask);

                m_Pos = PreviewGUI.EndScrollView();
            }
        }
Ejemplo n.º 12
0
        public override void OnPreviewSettings()
        {
            Init();

            // Disallow playing movie previews in play mode. Better not to interfere
            // with any playback the game does.
            // Also disallow if more than one MovieClip selected (for now).
            using (new EditorGUI.DisabledScope(Application.isPlaying || targets.Length > 1))
            {
                MovieTexture t         = target as MovieTexture;
                AudioClip    ac        = t.audioClip;
                bool         isPlaying = PreviewGUI.CycleButton(t.isPlaying ? 1 : 0, s_PlayIcons) != 0;
                if (isPlaying != t.isPlaying)
                {
                    if (isPlaying)
                    {
                        t.Stop();
                        t.Play();
                        if (ac != null)
                        {
                            AudioUtil.PlayClip(ac);
                        }
                    }
                    else
                    {
                        t.Pause();
                        if (ac != null)
                        {
                            AudioUtil.PauseClip(ac);
                        }
                    }
                }
            }
        }
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }

            // show texture
            WebCamTexture t = target as WebCamTexture;

            float zoomLevel  = Mathf.Min(Mathf.Min(r.width / t.width, r.height / t.height), 1);
            Rect  wantedRect = new Rect(r.x, r.y, t.width * zoomLevel, t.height * zoomLevel);

            PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
            GUI.DrawTexture(wantedRect, t, ScaleMode.StretchToFill, false);
            m_Pos = PreviewGUI.EndScrollView();

            // force update GUI
            if (t.isPlaying)
            {
                GUIView.current.Repaint();
            }

            if (Application.isPlaying)
            {
                if (t.isPlaying)
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y + 10, r.width, 20), "Can't pause preview when in play mode");
                }
                else
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y + 10, r.width, 20), "Can't start preview when in play mode");
                }
            }
        }
Ejemplo n.º 14
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture || !SystemInfo.supports3DTextures)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40), "3D texture preview not supported");
                }
                return;
            }

            InitPreviewUtility();
            Event e = Event.current;

            m_PreviewDir = PreviewGUI.Drag2D(m_PreviewDir, r);

            if (e.type == EventType.ScrollWheel)
            {
                m_ViewDistance = Mathf.Clamp(m_ViewDistance + e.delta.y * (0.01f + Mathf.Sqrt(m_ViewDistance) / 20), s_MinViewDistance, s_MaxViewDistance);
                e.Use();
                Repaint();
            }

            if (e.type != EventType.Repaint)
            {
                return;
            }

            m_PreviewUtility.BeginPreview(r, background);
            DrawPreview();
            m_PreviewUtility.EndAndDrawPreview(r);
        }
 public override void OnPreviewSettings()
 {
     Init();
     using (new EditorGUI.DisabledScope(Application.isPlaying || (base.targets.Length > 1)))
     {
         MovieTexture target    = base.target as MovieTexture;
         AudioClip    audioClip = target.audioClip;
         bool         flag      = PreviewGUI.CycleButton(!target.isPlaying ? 0 : 1, s_PlayIcons) != 0;
         if (flag != target.isPlaying)
         {
             if (flag)
             {
                 target.Stop();
                 target.Play();
                 if (audioClip != null)
                 {
                     AudioUtil.PlayClip(audioClip);
                 }
             }
             else
             {
                 target.Pause();
                 if (audioClip != null)
                 {
                     AudioUtil.PauseClip(audioClip);
                 }
             }
         }
     }
 }
        public override void OnPreviewSettings()
        {
            VideoClipImporter videoClipImporter = (VideoClipImporter)base.target;

            EditorGUI.BeginDisabledGroup(Application.isPlaying || this.HasModified() || videoClipImporter.useLegacyImporter);
            this.m_IsPlaying = (PreviewGUI.CycleButton((!this.m_IsPlaying) ? 0 : 1, VideoClipImporterInspector.s_Styles.playIcons) != 0);
            EditorGUI.EndDisabledGroup();
        }
        public override void OnPreviewSettings()
        {
            VideoClipImporter importer = (VideoClipImporter)target;

            EditorGUI.BeginDisabledGroup(Application.isPlaying);
            m_IsPlaying = PreviewGUI.CycleButton(m_IsPlaying ? 1 : 0, s_Styles.playIcons) != 0;
            EditorGUI.EndDisabledGroup();
        }
Ejemplo n.º 18
0
        private bool DrawEventMesh(int curEventIndex, FrameDebuggerEvent curEvent)
        {
            int frameEventMeshID = FrameDebuggerUtility.GetFrameEventMeshID(curEventIndex);

            if (frameEventMeshID == 0)
            {
                return(false);
            }
            UnityEngine.Object @object = EditorUtility.InstanceIDToObject(frameEventMeshID);
            Mesh mesh = @object as Mesh;

            if (mesh == null)
            {
                return(false);
            }
            Rect rect = GUILayoutUtility.GetRect(10f, 10f, new GUILayoutOption[]
            {
                GUILayout.ExpandHeight(true)
            });

            if (rect.width < 64f || rect.height < 64f)
            {
                return(true);
            }
            GameObject gameObjectForEvent = FrameDebuggerWindow.GetGameObjectForEvent(curEventIndex);
            Rect       rect2 = rect;

            rect2.yMin = rect2.yMax - EditorGUIUtility.singleLineHeight * 2f;
            Rect position = rect2;

            rect2.xMin    = rect2.center.x;
            position.xMax = position.center.x;
            if (Event.current.type == EventType.MouseDown)
            {
                if (rect2.Contains(Event.current.mousePosition))
                {
                    EditorGUIUtility.PingObject(frameEventMeshID);
                    Event.current.Use();
                }
                if (gameObjectForEvent != null && position.Contains(Event.current.mousePosition))
                {
                    EditorGUIUtility.PingObject(gameObjectForEvent.GetInstanceID());
                    Event.current.Use();
                }
            }
            this.m_PreviewDir = PreviewGUI.Drag2D(this.m_PreviewDir, rect);
            if (Event.current.type == EventType.Repaint)
            {
                int frameEventMeshSubset = FrameDebuggerUtility.GetFrameEventMeshSubset(curEventIndex);
                this.DrawMeshPreview(curEvent, rect, rect2, mesh, frameEventMeshSubset);
                if (gameObjectForEvent != null)
                {
                    EditorGUI.DropShadowLabel(position, gameObjectForEvent.name);
                }
            }
            return(true);
        }
Ejemplo n.º 19
0
        private bool DrawEventMesh(FrameDebuggerEventData curEventData)
        {
            Mesh mesh = curEventData.mesh;
            bool result;

            if (mesh == null)
            {
                result = false;
            }
            else
            {
                Rect rect = GUILayoutUtility.GetRect(10f, 10f, new GUILayoutOption[]
                {
                    GUILayout.ExpandHeight(true)
                });
                if (rect.width < 64f || rect.height < 64f)
                {
                    result = true;
                }
                else
                {
                    GameObject frameEventGameObject = FrameDebuggerUtility.GetFrameEventGameObject(curEventData.frameEventIndex);
                    Rect       rect2 = rect;
                    rect2.yMin = rect2.yMax - EditorGUIUtility.singleLineHeight * 2f;
                    Rect position = rect2;
                    rect2.xMin    = rect2.center.x;
                    position.xMax = position.center.x;
                    if (Event.current.type == EventType.MouseDown)
                    {
                        if (rect2.Contains(Event.current.mousePosition))
                        {
                            EditorGUIUtility.PingObject(mesh);
                            Event.current.Use();
                        }
                        if (frameEventGameObject != null && position.Contains(Event.current.mousePosition))
                        {
                            EditorGUIUtility.PingObject(frameEventGameObject.GetInstanceID());
                            Event.current.Use();
                        }
                    }
                    this.m_PreviewDir = PreviewGUI.Drag2D(this.m_PreviewDir, rect);
                    if (Event.current.type == EventType.Repaint)
                    {
                        int meshSubset = curEventData.meshSubset;
                        this.DrawMeshPreview(curEventData, rect, rect2, mesh, meshSubset);
                        if (frameEventGameObject != null)
                        {
                            EditorGUI.DropShadowLabel(position, frameEventGameObject.name);
                        }
                    }
                    result = true;
                }
            }
            return(result);
        }
Ejemplo n.º 20
0
        public override void OnPreviewSettings()
        {
            if (s_DefaultIcon == null)
            {
                Init();
            }

            AudioClip clip = target as AudioClip;

            using (new EditorGUI.DisabledScope(AudioUtil.IsMovieAudio(clip)))
            {
                bool isEditingMultipleObjects = targets.Length > 1;

                using (new EditorGUI.DisabledScope(isEditingMultipleObjects))
                {
                    bool oldAutoPlay = isEditingMultipleObjects ? false : m_bAutoPlay;
                    bool newAutoPlay = PreviewGUI.CycleButton(oldAutoPlay ? 1 : 0, s_AutoPlayIcons) != 0;
                    if (oldAutoPlay != newAutoPlay)
                    {
                        m_bAutoPlay = newAutoPlay;
                        InspectorWindow.RepaintAllInspectors();
                    }

                    bool oldLoop = isEditingMultipleObjects ? false : m_bLoop;
                    bool newLoop = PreviewGUI.CycleButton(oldLoop ? 1 : 0, s_LoopIcons) != 0;
                    if (oldLoop != newLoop)
                    {
                        m_bLoop = newLoop;
                        if (playing)
                        {
                            AudioUtil.LoopClip(clip, newLoop);
                        }
                        InspectorWindow.RepaintAllInspectors();
                    }
                }

                using (new EditorGUI.DisabledScope(isEditingMultipleObjects && !playing && m_PlayingInspector != this))
                {
                    bool curPlaying = m_PlayingInspector == this && playing;
                    bool newPlaying = PreviewGUI.CycleButton(curPlaying ? 1 : 0, s_PlayIcons) != 0;

                    if (newPlaying != curPlaying)
                    {
                        AudioUtil.StopAllClips();

                        if (newPlaying)
                        {
                            AudioUtil.PlayClip(clip, 0, m_bLoop);
                            m_PlayingClip      = clip;
                            m_PlayingInspector = this;
                        }
                    }
                }
            }
        }
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            bool flag = Event.current.type == EventType.Repaint;

            if (flag)
            {
                background.Draw(r, false, false, false, false);
            }
            VideoClipImporter videoClipImporter = (VideoClipImporter)base.target;

            if (this.m_IsPlaying && !videoClipImporter.isPlayingPreview)
            {
                videoClipImporter.PlayPreview();
            }
            else if (!this.m_IsPlaying && videoClipImporter.isPlayingPreview)
            {
                videoClipImporter.StopPreview();
            }
            Texture previewTexture = videoClipImporter.GetPreviewTexture();

            if (previewTexture && previewTexture.width != 0 && previewTexture.height != 0)
            {
                float num  = (float)previewTexture.width;
                float num2 = (float)previewTexture.height;
                if (videoClipImporter.defaultTargetSettings.enableTranscoding)
                {
                    VideoResizeMode resizeMode = videoClipImporter.defaultTargetSettings.resizeMode;
                    num  = (float)videoClipImporter.GetResizeWidth(resizeMode);
                    num2 = (float)videoClipImporter.GetResizeHeight(resizeMode);
                }
                if (videoClipImporter.pixelAspectRatioDenominator > 0)
                {
                    num *= (float)videoClipImporter.pixelAspectRatioNumerator / (float)videoClipImporter.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 = new Rect(r.x, r.y, num * num3, num2 * num3);
                PreviewGUI.BeginScrollView(r, this.m_Position, rect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
                EditorGUI.DrawTextureTransparent(rect, previewTexture, ScaleMode.StretchToFill);
                this.m_Position = PreviewGUI.EndScrollView();
                if (this.m_IsPlaying && flag)
                {
                    GUIView.current.Repaint();
                }
            }
        }
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (!SystemInfo.supports2DArrayTextures)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40), "2D texture array preview not supported");
                }
                return;
            }

            Texture2DArray t = (Texture2DArray)target;

            Rect scrubberRect = r;

            scrubberRect.height = kScrubberHeight;
            r.yMin += kScrubberHeight + kScrubberMargin;

            DoSliceScrubber(scrubberRect, t);

            if (Event.current.type == EventType.Repaint)
            {
                InitPreview();
                m_Material.mainTexture = t;

                // If multiple objects are selected, we might be using a slice level before the maximum
                int effectiveSlice = Mathf.Clamp(m_Slice, 0, t.depth - 1);

                m_Material.SetInt("_SliceIndex", effectiveSlice);
                m_Material.SetInt("_AlphaOnly", showAlpha ? 1 : 0);

                int texWidth  = Mathf.Max(t.width, 1);
                int texHeight = Mathf.Max(t.height, 1);

                float effectiveMipLevel = GetMipLevelForRendering();
                float zoomLevel         = Mathf.Min(Mathf.Min(r.width / texWidth, r.height / texHeight), 1);
                Rect  wantedRect        = new Rect(r.x, r.y, texWidth * zoomLevel, texHeight * zoomLevel);
                PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar",
                                           "PreHorizontalScrollbarThumb");
                FilterMode oldFilter = t.filterMode;
                TextureUtil.SetFilterModeNoDirty(t, FilterMode.Point);

                EditorGUI.DrawPreviewTexture(wantedRect, t, m_Material, ScaleMode.StretchToFill, 0, effectiveMipLevel);

                TextureUtil.SetFilterModeNoDirty(t, oldFilter);

                m_Pos = PreviewGUI.EndScrollView();
                if (effectiveSlice != 0 || (int)effectiveMipLevel != 0)
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y + 10, r.width, 30),
                                              "Slice " + effectiveSlice + "\nMip " + effectiveMipLevel);
                }
            }
        }
Ejemplo n.º 23
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            var evt = Event.current;

            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                if (evt.type == EventType.Repaint)
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40),
                                              "Mesh preview requires\nrender texture support");
                }
                return;
            }

            Init();

            if ((evt.type == EventType.ValidateCommand || evt.type == EventType.ExecuteCommand) && evt.commandName == EventCommandNames.FrameSelected)
            {
                FrameObject();
                evt.Use();
            }

            if (evt.button <= 0 && m_Settings.displayMode != DisplayMode.UVLayout)
            {
                m_Settings.previewDir = PreviewGUI.Drag2D(m_Settings.previewDir, r);
            }

            if (evt.button == 1 && m_Settings.displayMode != DisplayMode.UVLayout)
            {
                m_Settings.lightDir = PreviewGUI.Drag2D(m_Settings.lightDir, r);
            }

            if (evt.type == EventType.ScrollWheel)
            {
                MeshPreviewZoom(r, evt);
            }

            if (evt.type == EventType.MouseDrag && (m_Settings.displayMode == DisplayMode.UVLayout || evt.button == 2))
            {
                MeshPreviewPan(r, evt);
            }

            if (evt.type != EventType.Repaint)
            {
                return;
            }

            m_PreviewUtility.BeginPreview(r, background);

            DoRenderPreview();

            m_PreviewUtility.EndAndDrawPreview(r);
        }
Ejemplo n.º 24
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (m_Dimension.intValue == (int)UnityEngine.Rendering.TextureDimension.Tex2DArray)
            {
                if (!SystemInfo.supports2DArrayTextures)
                {
                    if (Event.current.type == EventType.Repaint)
                    {
                        EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40), "2D texture array preview not supported");
                    }
                    return;
                }

                RenderTexture rt = (RenderTexture)target;

                if (Event.current.type == EventType.Repaint)
                {
                    InitPreview();
                    m_Material.mainTexture = rt;

                    // If multiple objects are selected, we might be using a slice level before the maximum
                    int effectiveSlice = Mathf.Clamp(m_Slice, 0, rt.volumeDepth - 1);

                    m_Material.SetInt(s_ShaderSliceIndex, effectiveSlice);
                    m_Material.SetInt(s_ShaderToSrgb, QualitySettings.activeColorSpace == ColorSpace.Linear ? 1 : 0);

                    int texWidth  = Mathf.Max(rt.width, 1);
                    int texHeight = Mathf.Max(rt.height, 1);

                    float zoomLevel  = Mathf.Min(Mathf.Min(r.width / texWidth, r.height / texHeight), 1);
                    Rect  wantedRect = new Rect(r.x, r.y, texWidth * zoomLevel, texHeight * zoomLevel);
                    PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
                    FilterMode oldFilter = rt.filterMode;
                    TextureUtil.SetFilterModeNoDirty(rt, FilterMode.Point);

                    EditorGUI.DrawPreviewTexture(wantedRect, rt, m_Material, ScaleMode.StretchToFill, 0, mipLevel);

                    TextureUtil.SetFilterModeNoDirty(rt, oldFilter);

                    m_Pos = PreviewGUI.EndScrollView();
                    if (effectiveSlice != 0 || (int)mipLevel != 0)
                    {
                        EditorGUI.DropShadowLabel(new Rect(r.x, r.y + 10, r.width, 30),
                                                  "Slice " + effectiveSlice + "\nMip " + mipLevel);
                    }
                }
            }
            else
            {
                base.OnPreviewGUI(r, background);
            }
        }
Ejemplo n.º 25
0
        private bool DrawEventMesh(int curEventIndex, FrameDebuggerEvent curEvent)
        {
            int frameEventMeshID = FrameDebuggerUtility.GetFrameEventMeshID(curEventIndex);

            if (frameEventMeshID == 0)
            {
                return(false);
            }
            Mesh mesh = EditorUtility.InstanceIDToObject(frameEventMeshID) as Mesh;

            if (mesh == null)
            {
                return(false);
            }
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.ExpandHeight(true) };
            Rect position             = GUILayoutUtility.GetRect((float)10f, (float)10f, options);

            if ((position.width >= 64f) && (position.height >= 64f))
            {
                GameObject gameObjectForEvent = GetGameObjectForEvent(curEventIndex);
                Rect       meshInfoRect       = position;
                meshInfoRect.yMin = meshInfoRect.yMax - (EditorGUIUtility.singleLineHeight * 2f);
                Rect rect3 = meshInfoRect;
                meshInfoRect.xMin = meshInfoRect.center.x;
                rect3.xMax        = rect3.center.x;
                if (Event.current.type == EventType.MouseDown)
                {
                    if (meshInfoRect.Contains(Event.current.mousePosition))
                    {
                        EditorGUIUtility.PingObject(frameEventMeshID);
                        Event.current.Use();
                    }
                    if ((gameObjectForEvent != null) && rect3.Contains(Event.current.mousePosition))
                    {
                        EditorGUIUtility.PingObject(gameObjectForEvent.GetInstanceID());
                        Event.current.Use();
                    }
                }
                this.m_PreviewDir = PreviewGUI.Drag2D(this.m_PreviewDir, position);
                if (Event.current.type == EventType.Repaint)
                {
                    int frameEventMeshSubset = FrameDebuggerUtility.GetFrameEventMeshSubset(curEventIndex);
                    this.DrawMeshPreview(curEvent, position, meshInfoRect, mesh, frameEventMeshSubset);
                    if (gameObjectForEvent != null)
                    {
                        EditorGUI.DropShadowLabel(rect3, gameObjectForEvent.name);
                    }
                }
            }
            return(true);
        }
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40), "Preview requires\nrender texture support");
                }
                return;
            }

            var direction = PreviewGUI.Drag2D(m_PreviewDir, r);

            if (direction != m_PreviewDir)
            {
                // None of the preview are valid since the camera position has changed.
                ClearPreviewCache();
                m_PreviewDir = direction;
            }

            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            if (m_PreviewRect != r)
            {
                ClearPreviewCache();
                m_PreviewRect = r;
            }

            var     previewUtility = GetPreviewData().renderUtility;
            Texture previewTexture;

            if (m_PreviewCache.TryGetValue(referenceTargetIndex, out previewTexture))
            {
                PreviewRenderUtility.DrawPreview(r, previewTexture);
            }
            else
            {
                previewUtility.BeginPreview(r, background);
                DoRenderPreview();
                previewUtility.EndAndDrawPreview(r);
                var copy     = new RenderTexture(previewUtility.renderTexture);
                var previous = RenderTexture.active;
                Graphics.Blit(previewUtility.renderTexture, copy);
                RenderTexture.active = previous;
                m_PreviewCache.Add(referenceTargetIndex, copy);
            }
        }
Ejemplo n.º 27
0
    public override void OnPreviewGUI(Rect r, GUIStyle background)
    {
        this.Init();

        previewDir = PreviewGUI.Drag2D(previewDir, r);
        if (Event.current.type != EventType.Repaint)
        {
            return;
        }

        m_PreviewUtility.BeginPreview(r, background);
        DoRenderPreview();
        m_PreviewUtility.EndAndDrawPreview(r);
    }
Ejemplo n.º 28
0
        public override void OnPreviewSettings()
        {
            if (AudioClipInspector.s_DefaultIcon == null)
            {
                AudioClipInspector.Init();
            }
            AudioClip audioClip = base.target as AudioClip;

            using (new EditorGUI.DisabledScope(AudioUtil.IsMovieAudio(audioClip)))
            {
                bool flag = base.targets.Length > 1;
                using (new EditorGUI.DisabledScope(flag))
                {
                    bool flag2 = !flag && AudioClipInspector.m_bAutoPlay;
                    bool flag3 = PreviewGUI.CycleButton((!flag2) ? 0 : 1, AudioClipInspector.s_AutoPlayIcons) != 0;
                    if (flag2 != flag3)
                    {
                        AudioClipInspector.m_bAutoPlay = flag3;
                        InspectorWindow.RepaintAllInspectors();
                    }
                    bool flag4 = !flag && AudioClipInspector.m_bLoop;
                    bool flag5 = PreviewGUI.CycleButton((!flag4) ? 0 : 1, AudioClipInspector.s_LoopIcons) != 0;
                    if (flag4 != flag5)
                    {
                        AudioClipInspector.m_bLoop = flag5;
                        if (AudioClipInspector.playing)
                        {
                            AudioUtil.LoopClip(audioClip, flag5);
                        }
                        InspectorWindow.RepaintAllInspectors();
                    }
                }
                using (new EditorGUI.DisabledScope(flag && !AudioClipInspector.playing && AudioClipInspector.m_PlayingInspector != this))
                {
                    bool flag6 = AudioClipInspector.m_PlayingInspector == this && AudioClipInspector.playing;
                    bool flag7 = PreviewGUI.CycleButton((!flag6) ? 0 : 1, AudioClipInspector.s_PlayIcons) != 0;
                    if (flag7 != flag6)
                    {
                        AudioUtil.StopAllClips();
                        if (flag7)
                        {
                            AudioUtil.PlayClip(audioClip, 0, AudioClipInspector.m_bLoop);
                            AudioClipInspector.m_PlayingClip      = audioClip;
                            AudioClipInspector.m_PlayingInspector = this;
                        }
                    }
                }
            }
        }
Ejemplo n.º 29
0
        private bool DrawEventMesh(FrameDebuggerEventData curEventData)
        {
            Mesh mesh = curEventData.mesh;

            if ((UnityEngine.Object)mesh == (UnityEngine.Object)null)
            {
                return(false);
            }
            Rect rect = GUILayoutUtility.GetRect(10f, 10f, new GUILayoutOption[1] {
                GUILayout.ExpandHeight(true)
            });

            if ((double)rect.width < 64.0 || (double)rect.height < 64.0)
            {
                return(true);
            }
            GameObject frameEventGameObject = FrameDebuggerUtility.GetFrameEventGameObject(curEventData.frameEventIndex);
            Rect       meshInfoRect         = rect;

            meshInfoRect.yMin = meshInfoRect.yMax - EditorGUIUtility.singleLineHeight * 2f;
            Rect position = meshInfoRect;

            meshInfoRect.xMin = meshInfoRect.center.x;
            position.xMax     = position.center.x;
            if (Event.current.type == EventType.MouseDown)
            {
                if (meshInfoRect.Contains(Event.current.mousePosition))
                {
                    EditorGUIUtility.PingObject((UnityEngine.Object)mesh);
                    Event.current.Use();
                }
                if ((UnityEngine.Object)frameEventGameObject != (UnityEngine.Object)null && position.Contains(Event.current.mousePosition))
                {
                    EditorGUIUtility.PingObject(frameEventGameObject.GetInstanceID());
                    Event.current.Use();
                }
            }
            this.m_PreviewDir = PreviewGUI.Drag2D(this.m_PreviewDir, rect);
            if (Event.current.type == EventType.Repaint)
            {
                int meshSubset = curEventData.meshSubset;
                this.DrawMeshPreview(curEventData, rect, meshInfoRect, mesh, meshSubset);
                if ((UnityEngine.Object)frameEventGameObject != (UnityEngine.Object)null)
                {
                    EditorGUI.DropShadowLabel(position, frameEventGameObject.name);
                }
            }
            return(true);
        }
        public void OnPreviewGUI(Texture t, Rect r, GUIStyle background, float exposure, TextureInspector.PreviewMode previewMode, float mipLevel)
        {
            if (t == null)
            {
                return;
            }

            if (!SystemInfo.supports2DArrayTextures)
            {
                EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40), "2D texture array preview not supported");
                return;
            }

            InitPreviewMaterialIfNeeded();
            m_Material.mainTexture = t;

            int effectiveSlice = GetEffectiveSlice(t);

            m_Material.SetFloat(s_ShaderSliceIndex, (float)effectiveSlice);
            m_Material.SetFloat(s_ShaderToSrgb, QualitySettings.activeColorSpace == ColorSpace.Linear ? 1.0f : 0.0f);
            m_Material.SetFloat(s_ShaderIsNormalMap, TextureInspector.IsNormalMap(t) ? 1.0f : 0.0f);

            SetShaderColorMask(previewMode);

            int texWidth  = Mathf.Max(t.width, 1);
            int texHeight = Mathf.Max(t.height, 1);

            float effectiveMipLevel = GetMipLevelForRendering(t, mipLevel);
            float zoomLevel         = Mathf.Min(Mathf.Min(r.width / texWidth, r.height / texHeight), 1);
            Rect  wantedRect        = new Rect(r.x, r.y, texWidth * zoomLevel, texHeight * zoomLevel);

            PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar",
                                       "PreHorizontalScrollbarThumb");
            FilterMode oldFilter = t.filterMode;

            TextureUtil.SetFilterModeNoDirty(t, FilterMode.Point);

            EditorGUI.DrawPreviewTexture(wantedRect, t, m_Material, ScaleMode.StretchToFill, 0, effectiveMipLevel, UnityEngine.Rendering.ColorWriteMask.All, exposure);

            TextureUtil.SetFilterModeNoDirty(t, oldFilter);

            m_Pos = PreviewGUI.EndScrollView();
            if (effectiveSlice != 0 || (int)effectiveMipLevel != 0)
            {
                EditorGUI.DropShadowLabel(new Rect(r.x, r.y + 10, r.width, 30),
                                          "Slice " + effectiveSlice + "\nMip " + effectiveMipLevel);
            }
        }