private void DrawWireframe(SpriteCache sprite)
        {
            Debug.Assert(Event.current.type == EventType.Repaint);
            Debug.Assert(sprite != null);

            var meshPreview = sprite.GetMeshPreview();

            Debug.Assert(meshPreview != null);

            m_Material.mainTexture = null;
            m_Material.SetFloat("_Opacity", 0.35f);
            m_Material.SetFloat("_VertexColorBlend", 0f);
            m_Material.color = Color.white;

            GL.wireframe = true;
            DrawingUtility.DrawMesh(meshPreview.mesh, m_Material, sprite.GetLocalToWorldMatrixFromMode());
            GL.wireframe = false;
        }
        private void DrawDefaultSpriteMesh(SpriteCache sprite)
        {
            Debug.Assert(m_Material != null);

            var meshPreview = sprite.GetMeshPreview();
            var meshCache   = sprite.GetMesh();
            var skeleton    = skinningCache.GetEffectiveSkeleton(sprite);

            Debug.Assert(meshPreview != null);

            if (meshPreview.canSkin == false || skeleton.isPosePreview == false)
            {
                m_Material.mainTexture = meshCache.textureDataProvider.texture;
                m_Material.SetFloat("_Opacity", 1f);
                m_Material.SetFloat("_VertexColorBlend", 0f);
                m_Material.color = new Color(1f, 1f, 1f, 1f);

                DrawingUtility.DrawMesh(meshPreview.defaultMesh, m_Material, sprite.GetLocalToWorldMatrixFromMode());
            }
        }
Esempio n. 3
0
        internal void RenderSpriteOutline(ISpriteEditor spriteEditor, SpriteCache sprite)
        {
            if (sprite == null)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                UnityEngine.Profiling.Profiler.BeginSample("SpriteOutlineRenderer::RenderSpriteOutline");
                m_OutlineMaterial.SetColor("_OutlineColor", SelectionOutlineSettings.outlineColor);
                m_OutlineMaterial.SetFloat("_AdjustLinearForGamma", PlayerSettings.colorSpace == ColorSpace.Linear ? 1.0f : 0.0f);
                var   texture     = spriteEditor.GetDataProvider <ITextureDataProvider>().texture;
                float outlineSize = Mathf.Max(texture.width, texture.height) * SelectionOutlineSettings.selectedSpriteOutlineSize / 1024.0f;
                m_OutlineMaterial.SetFloat("_OutlineSize", outlineSize);
                var mesh = GetMesh(sprite);
                m_OutlineMaterial.SetPass(0);
                GL.PushMatrix();
                GL.MultMatrix(Handles.matrix * sprite.GetLocalToWorldMatrixFromMode());

                Rect r = new Rect(mesh.bounds.min.x, mesh.bounds.min.y, mesh.bounds.size.x, mesh.bounds.size.y);
                GL.Begin(GL.QUADS);
                GL.Color(Color.white);
                GL.TexCoord(new Vector3(0, 0, 0));
                GL.Vertex3(r.xMin, r.yMin, 0);

                GL.TexCoord(new Vector3(1, 0, 0));
                GL.Vertex3(r.xMax, r.yMin, 0);

                GL.TexCoord(new Vector3(1, 1, 0));
                GL.Vertex3(r.xMax, r.yMax, 0);

                GL.TexCoord(new Vector3(0, 1, 0));
                GL.Vertex3(r.xMin, r.yMax, 0);
                GL.End();
                GL.PopMatrix();
                UnityEngine.Profiling.Profiler.EndSample();
            }
        }
        private void DrawSpriteMesh(SpriteCache sprite, float weightMapOpacity)
        {
            Debug.Assert(m_Material != null);

            var meshPreview = sprite.GetMeshPreview();
            var meshCache   = sprite.GetMesh();

            Debug.Assert(meshPreview != null);

            if (meshPreview.mesh == null || meshPreview.mesh.vertexCount == 0)
            {
                DrawDefaultSpriteMesh(sprite);
            }
            else
            {
                m_Material.mainTexture = meshCache.textureDataProvider.texture;
                m_Material.SetFloat("_Opacity", 1f);
                m_Material.SetFloat("_VertexColorBlend", weightMapOpacity);

                m_Material.color = Color.white;

                DrawingUtility.DrawMesh(meshPreview.mesh, m_Material, sprite.GetLocalToWorldMatrixFromMode());
            }
        }