Drag2D() public static method

public static Drag2D ( Vector2 scrollPosition, Rect position ) : Vector2
scrollPosition Vector2
position Rect
return Vector2
Example #1
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);
        }
Example #2
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);
        }
Example #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 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);
                 }
             }
         }
     }
 }
 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);
     }
 }
Example #6
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);
        }
Example #7
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);
        }
Example #8
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);
        }
        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);
            }
        }
Example #11
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);
    }
Example #12
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);
        }
Example #13
0
        public void OnPreviewGUI(Texture t, Rect r, GUIStyle background)
        {
            if (t == null)
            {
                return;
            }
            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");
                }
                return;
            }
            this.InitPreview();
            this.m_PreviewDir = PreviewGUI.Drag2D(this.m_PreviewDir, r);
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            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;
            Quaternion quaternion = Quaternion.Euler(this.m_PreviewDir.y, 0f, 0f) * Quaternion.Euler(0f, this.m_PreviewDir.x, 0f);
            Material   material   = EditorGUIUtility.LoadRequired("Previews/PreviewCubemapMaterial.mat") as Material;

            material.mainTexture = t;
            material.SetMatrix("_CubemapRotation", Matrix4x4.TRS(Vector3.zero, quaternion, Vector3.one));
            float mipLevelForRendering = this.GetMipLevelForRendering(t);

            material.SetFloat("_Mip", mipLevelForRendering);
            material.SetFloat("_Alpha", (this.m_PreviewType != CubemapPreview.PreviewType.Alpha) ? 0f : 1f);
            material.SetFloat("_Intensity", this.m_Intensity);
            this.m_PreviewUtility.DrawMesh(this.m_Mesh, Vector3.zero, quaternion, material, 0);
            this.m_PreviewUtility.m_Camera.Render();
            Unsupported.SetRenderSettingsUseFogNoDirty(fog);
            Texture image = this.m_PreviewUtility.EndPreview();

            GUI.DrawTexture(r, image, ScaleMode.StretchToFill, false);
            if (mipLevelForRendering != 0f)
            {
                EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20f), "Mip " + mipLevelForRendering);
            }
        }
 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, 40f), "Preview requires\nrender texture support");
         }
     }
     else
     {
         this.previewDir = PreviewGUI.Drag2D(this.previewDir, r);
         if (Event.current.type == EventType.Repaint)
         {
             PreviewRenderUtility renderUtility = this.GetPreviewData().renderUtility;
             renderUtility.BeginPreview(r, background);
             this.DoRenderPreview();
             renderUtility.EndAndDrawPreview(r);
         }
     }
 }
Example #15
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),
                                              "Mesh preview requires\nrender texture support");
                }
                return;
            }

            Init();

            if (m_Settings.displayMode != DisplayMode.UVLayout)
            {
                m_Settings.previewDir = PreviewGUI.Drag2D(m_Settings.previewDir, r);
            }

            if (Event.current.type == EventType.ScrollWheel && m_Settings.displayMode == DisplayMode.UVLayout)
            {
                MeshPreviewZoom(r, Event.current);
            }

            if (Event.current.type == EventType.MouseDrag && m_Settings.displayMode == DisplayMode.UVLayout)
            {
                MeshPreviewPan(r, Event.current);
            }

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

            m_PreviewUtility.BeginPreview(r, background);

            DoRenderPreview();

            m_PreviewUtility.EndAndDrawPreview(r);
        }
        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, 40f), "Preview requires\nrender texture support");
                }
                return;
            }
            this.InitPreview();
            this.m_PreviewDir = PreviewGUI.Drag2D(this.m_PreviewDir, r);
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            this.m_PreviewUtility.BeginPreview(r, background);
            this.DoRenderPreview(this.m_PreviewShaded);
            Texture image = this.m_PreviewUtility.EndPreview();

            GUI.DrawTexture(r, image, ScaleMode.StretchToFill, false);
        }
Example #17
0
        public void OnPreviewGUI(Texture t, Rect r, GUIStyle background, float exposure)
        {
            if (t == null)
            {
                return;
            }

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

            m_PreviewDir = PreviewGUI.Drag2D(m_PreviewDir, r);

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

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

            RenderCubemap(t, m_PreviewDir, previewDistance, exposure);

            Texture renderedTexture = m_PreviewUtility.EndPreview();

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

            if (mipLevel != 0)
            {
                EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20), "Mip " + mipLevel);
            }
        }