Пример #1
0
        void OnGenerateVisualContent(MeshGenerationContext mgc)
        {
            if (m_Context.pickElement)
            {
                m_PickOverlay.Draw(mgc);
            }
            else
            {
                m_TreeViewContainer.DrawOverlay(mgc);
                m_StylesDebuggerContainer.RefreshBoxModelView(mgc);

                if (m_Context.showRepaintOverlay)
                {
                    m_RepaintOverlay.Draw(mgc);
                }
            }

            if (m_Context.showLayoutBound)
            {
                DrawLayoutBounds(mgc);
            }
            if (m_Context.showWireframe)
            {
                DrawWireframe(mgc);
            }
        }
Пример #2
0
        private void DrawLine(MeshGenerationContext ctx, Vector2 startPos, Vector2 endPos, Color color, float thickness)
        {
            var mesh = ctx.Allocate(6, 6);

            var dir = (endPos - startPos).normalized;

            var startCenter = new Vector3(startPos.x, startPos.y, Vertex.nearZ);
            var endCenter   = new Vector3(endPos.x, endPos.y, Vertex.nearZ);
            var normal      = new Vector3(-dir.y, dir.x, 0f);

            var halfThickness = thickness * 0.5f;

            var vertices = new Vertex[6];

            vertices[0].position = startCenter + normal * halfThickness;
            vertices[1].position = startCenter - normal * halfThickness;
            vertices[2].position = endCenter + normal * halfThickness;

            vertices[3].position = startCenter - normal * halfThickness;
            vertices[4].position = endCenter - normal * halfThickness;
            vertices[5].position = endCenter + normal * halfThickness;

            vertices[0].tint = color;
            vertices[1].tint = color;
            vertices[2].tint = color;
            vertices[3].tint = color;
            vertices[4].tint = color;
            vertices[5].tint = color;

            mesh.SetAllVertices(vertices);
            mesh.SetAllIndices(new ushort[] { 0, 1, 2, 3, 4, 5 });
        }
        public void GenerateTickHeadContent(MeshGenerationContext context)
        {
            const float tipY   = 20f;
            const float height = 6f;
            const float width  = 11f;
            const float middle = 6f;

            Color color;

            if (EditorGUIUtility.isProSkin)
            {
                color = m_DebugPlayhead ? ColorUtility.FromHtmlString("#234A6C") : Color.white;
            }
            else
            {
                color = m_DebugPlayhead ? ColorUtility.FromHtmlString("#2E5B8D") : Color.white;
            }

            MeshWriteData mesh = context.Allocate(3, 3);

            Vertex[] vertices = new Vertex[3];
            vertices[0].position = new Vector3(middle, tipY, Vertex.nearZ);
            vertices[1].position = new Vector3(width, tipY - height, Vertex.nearZ);
            vertices[2].position = new Vector3(0, tipY - height, Vertex.nearZ);

            vertices[0].tint = color;
            vertices[1].tint = color;
            vertices[2].tint = color;

            mesh.SetAllVertices(vertices);
            mesh.SetAllIndices(new ushort[] { 0, 2, 1 });
        }
Пример #4
0
        void OnGenerateVisualContent(MeshGenerationContext mgc)
        {
            GraphView gView = GetFirstAncestorOfType <GraphView>();

            if (gView == null)
            {
                return;
            }

            VisualElement container = gView.contentViewContainer;

            foreach (Line2 line in lines)
            {
                Vector2 start  = container.ChangeCoordinatesTo(gView, line.start);
                Vector2 end    = container.ChangeCoordinatesTo(gView, line.end);
                float   x      = Math.Min(start.x, end.x);
                float   y      = Math.Min(start.y, end.y);
                float   width  = Math.Max(1, Math.Abs(start.x - end.x));
                float   height = Math.Max(1, Math.Abs(start.y - end.y));

                var rect = new Rect(x, y, width, height);

                mgc.Rectangle(MeshGenerationContextUtils.RectangleParams.MakeSolid(rect, s_SnappingLineColor, ContextType.Editor));
            }
        }
            void OnGenerateVisualContent(MeshGenerationContext mgc)
            {
                Rect r = contentRect;

                if (r.width < 0.01f || r.height < 0.01f)
                {
                    return; // Skip rendering when too small.
                }
                Color color = resolvedStyle.color;

                k_Vertices[0].tint = Color.black;
                k_Vertices[1].tint = Color.black;
                k_Vertices[2].tint = color;
                k_Vertices[3].tint = color;

                float left   = 0;
                float right  = r.width;
                float top    = 0;
                float bottom = r.height;

                k_Vertices[0].position = new Vector3(left, bottom, Vertex.nearZ);
                k_Vertices[1].position = new Vector3(left, top, Vertex.nearZ);
                k_Vertices[2].position = new Vector3(right, top, Vertex.nearZ);
                k_Vertices[3].position = new Vector3(right, bottom, Vertex.nearZ);

                MeshWriteData mwd = mgc.Allocate(k_Vertices.Length, k_Indices.Length);

                mwd.SetAllVertices(k_Vertices);
                mwd.SetAllIndices(k_Indices);
            }
Пример #6
0
        private void DrawPreviewImage(MeshGenerationContext mgc)
        {
            if (m_PreviewImage == null)
            {
                return;
            }

            ComputePreviewImageHalfSizeAndOffset(out Vector2 halfSize, out Vector2 offset);

            var meshWriteData = mgc.Allocate(4, 6, m_PreviewImage, m_PreviewMaterial, MeshGenerationContext.MeshFlags.None);

            var vertices = new Vertex[4];

            vertices[0].position = new Vector3(-halfSize.x, -halfSize.y, Vertex.nearZ);
            vertices[0].tint     = Color.white;

            vertices[1].position = new Vector3(halfSize.x, -halfSize.y, Vertex.nearZ);
            vertices[1].tint     = Color.white;

            vertices[2].position = new Vector3(halfSize.x, halfSize.y, Vertex.nearZ);
            vertices[2].tint     = Color.white;

            vertices[3].position = new Vector3(-halfSize.x, halfSize.y, Vertex.nearZ);
            vertices[3].tint     = Color.white;

            SimulatorUtilities.SetTextureCoordinates(TargetOrientation, vertices);
            SimulatorUtilities.TransformVertices(m_Rotation, offset, vertices);

            meshWriteData.SetAllVertices(vertices);

            var indices = new ushort[] { 0, 3, 1, 1, 3, 2 };

            meshWriteData.SetAllIndices(indices);
        }
            void OnGenerateVisualContent(MeshGenerationContext mgc)
            {
                Rect r = contentRect;

                if (r.width < 0.01f || r.height < 0.01f)
                {
                    return; // Skip rendering when too small.
                }
                float left   = 0;
                float right  = r.width;
                float top    = 0;
                float bottom = r.height;

                k_Vertices[0].position = new Vector3(left, bottom, Vertex.nearZ);
                k_Vertices[1].position = new Vector3(left, top, Vertex.nearZ);
                k_Vertices[2].position = new Vector3(right, top, Vertex.nearZ);
                k_Vertices[3].position = new Vector3(right, bottom, Vertex.nearZ);

                MeshWriteData mwd = mgc.Allocate(k_Vertices.Length, k_Indices.Length, m_Texture);

                // Remap 0..1 to the uv region.
                Rect uvs = mwd.uvRegion;

                k_Vertices[0].uv = new Vector2(uvs.xMin, uvs.yMin);
                k_Vertices[1].uv = new Vector2(uvs.xMin, uvs.yMax);
                k_Vertices[2].uv = new Vector2(uvs.xMax, uvs.yMax);
                k_Vertices[3].uv = new Vector2(uvs.xMax, uvs.yMin);

                mwd.SetAllVertices(k_Vertices);
                mwd.SetAllIndices(k_Indices);
            }
            void OnGenerateVisualContent(MeshGenerationContext mgc)
            {
                Rect r = contentRect;

                if (r.width < 0.01f || r.height < 0.01f)
                {
                    return; // Skip rendering when too small.
                }
                float radiusX = r.width / 2;
                float radiusY = r.height / 2;

                k_Vertices[0].position = new Vector3(radiusX, radiusY, Vertex.nearZ);

                float angle = 0;

                for (int i = 1; i < 7; ++i)
                {
                    k_Vertices[i].position = new Vector3(
                        radiusX + radiusX * Mathf.Cos(angle),
                        radiusY - radiusY * Mathf.Sin(angle),
                        Vertex.nearZ);
                    angle += 2f * Mathf.PI / 6;
                }

                MeshWriteData mwd = mgc.Allocate(k_Vertices.Length, k_Indices.Length);

                mwd.SetAllVertices(k_Vertices);
                mwd.SetAllIndices(k_Indices);
            }
Пример #9
0
        protected void DrawBorder(MeshGenerationContext mgc, Rect rect, Color color, float alpha)
        {
            if (mgc == null)
            {
                throw new NullReferenceException("The MeshGenerationContext is null");
            }

            color.a = alpha;
            rect.xMin++;
            rect.xMax--;
            rect.yMin++;
            rect.yMax--;
            var width  = rect.xMax - rect.xMin;
            var height = rect.yMax - rect.yMin;

            var topRect    = new Rect(rect.xMin, rect.yMin, width, 1);
            var bottomRect = new Rect(rect.xMin, rect.yMax, width, 1);
            var rightRect  = new Rect(rect.xMax, rect.yMin, 1, height);
            var lefRect    = new Rect(rect.xMin, rect.yMin, 1, height);

            var rectParams = MeshGenerationContextUtils.RectangleParams.MakeSolid(topRect, color, mgc.visualElement.panel.contextType);

            mgc.Rectangle(rectParams);

            rectParams = MeshGenerationContextUtils.RectangleParams.MakeSolid(bottomRect, color, mgc.visualElement.panel.contextType);
            mgc.Rectangle(rectParams);

            rectParams = MeshGenerationContextUtils.RectangleParams.MakeSolid(rightRect, color, mgc.visualElement.panel.contextType);
            mgc.Rectangle(rectParams);

            rectParams = MeshGenerationContextUtils.RectangleParams.MakeSolid(lefRect, color, mgc.visualElement.panel.contextType);
            mgc.Rectangle(rectParams);
        }
Пример #10
0
        private void DrawTriangle(MeshGenerationContext ctx, Vector2 startPos, Vector2 endPos, Color color, float thickness)
        {
            var mesh = ctx.Allocate(3, 3);

            var length = thickness * 4f;
            var width  = thickness * 3f;

            var distAlongLine = 1f;

            var dir    = (endPos - startPos).normalized;
            var dist   = (endPos - startPos).magnitude;
            var center = new Vector3(startPos.x + dir.x * (dist * distAlongLine - length), startPos.y + dir.y * (dist * distAlongLine - length), Vertex.nearZ);
            var normal = new Vector3(-dir.y, dir.x, 0f);

            var vertices = new Vertex[3];

            vertices[0].position = center + normal * width;
            vertices[1].position = center - normal * width;
            vertices[2].position = new Vector3(center.x + dir.x * length, center.y + dir.y * length, center.z);

            vertices[0].tint = color;
            vertices[1].tint = color;
            vertices[2].tint = color;

            mesh.SetAllVertices(vertices);
            mesh.SetAllIndices(new ushort[] { 0, 1, 2 });
        }
Пример #11
0
        public static void DrawImmediate(MeshGenerationContext mgc, Action callback)
        {
#if UNITY_2020_1_OR_NEWER
            mgc.painter.DrawImmediate(callback, true);
#else
            mgc.painter.DrawImmediate(callback);
#endif
        }
Пример #12
0
 private void OnGenerateVisualContent(MeshGenerationContext mgc)
 {
     // This control begs to be fully rewritten and it shouldn't use immediate
     // mode rendering at all. It should maintain its vertex/index lists and only
     // update affected vertices when their respective elements are changed. This
     // way the cost of GenerateVisualContent becomes effectively only two memcpys.
     mgc.painter.DrawImmediate(DrawMinimapContent, true);
 }
Пример #13
0
        private void DrawLayoutBounds(MeshGenerationContext mgc)
        {
            m_LayoutOverlay.ClearOverlay();
            m_LayoutOverlay.selectedElement = m_DebuggerSelection.element;
            AddLayoutBoundOverlayRecursive(visualTree);

            m_LayoutOverlay.Draw(mgc);
        }
Пример #14
0
        public override void Draw(MeshGenerationContext mgc)
        {
            base.Draw(mgc);

            if (selectedElement != null)
            {
                DrawBorder(mgc, selectedElement.worldBound, kSelectedBoundColor, kDefaultAlpha);
            }
        }
Пример #15
0
        public override void Draw(MeshGenerationContext mgc)
        {
            base.Draw(mgc);

            if (selectedElement != null)
            {
                DrawWireframe(mgc, selectedElement, kSelectedColor, kDefaultAlpha);
            }
        }
Пример #16
0
        public void Refresh(MeshGenerationContext mgc)
        {
            m_OverlayPainter.Draw(mgc);

            m_MarginBox.SyncValues();
            m_BorderBox.SyncValues();
            m_PaddingBox.SyncValues();
            m_ContentBox.SyncValues();
        }
Пример #17
0
        private void DrawHighlightSafeArea(MeshGenerationContext mgc)
        {
            if (!m_HighlightSafeArea)
            {
                return;
            }

            var safeAreaInScreen = GetSafeAreaInScreen();
            var halfImageWidth   = safeAreaInScreen.width / 2;
            var halfImageHeight  = safeAreaInScreen.height / 2;

            const int vertexCount = 8, indexCount = 24;
            var       meshWriteData = mgc.Allocate(vertexCount, indexCount);
            var       vertices      = new Vertex[vertexCount];

            var       highlightColor     = Color.green;
            const int highlightLineWidth = 2;

            vertices[0].position = new Vector3(-halfImageWidth, -halfImageHeight, Vertex.nearZ);
            vertices[0].tint     = highlightColor;

            vertices[1].position = new Vector3(halfImageWidth, -halfImageHeight, Vertex.nearZ);
            vertices[1].tint     = highlightColor;

            vertices[2].position = new Vector3(halfImageWidth, halfImageHeight, Vertex.nearZ);
            vertices[2].tint     = highlightColor;

            vertices[3].position = new Vector3(-halfImageWidth, halfImageHeight, Vertex.nearZ);
            vertices[3].tint     = highlightColor;

            vertices[4].position = new Vector3(-halfImageWidth + highlightLineWidth, -halfImageHeight + highlightLineWidth, Vertex.nearZ);
            vertices[4].tint     = highlightColor;

            vertices[5].position = new Vector3(halfImageWidth - highlightLineWidth, -halfImageHeight + highlightLineWidth, Vertex.nearZ);
            vertices[5].tint     = highlightColor;

            vertices[6].position = new Vector3(halfImageWidth - highlightLineWidth, halfImageHeight - highlightLineWidth, Vertex.nearZ);
            vertices[6].tint     = highlightColor;

            vertices[7].position = new Vector3(-halfImageWidth + highlightLineWidth, halfImageHeight - highlightLineWidth, Vertex.nearZ);
            vertices[7].tint     = highlightColor;

            var offset = new Vector2(m_Offset.x + safeAreaInScreen.x / 2, m_Offset.y + safeAreaInScreen.y / 2);

            offset = ComputeOffsetForScreenMode(offset, true);

            SimulatorUtilities.TransformVertices(ComputeRotationForHighlightSafeArea(), offset, vertices);

            meshWriteData.SetAllVertices(vertices);

            var indices = new ushort[]
            {
                0, 4, 1, 1, 4, 5, 1, 5, 6, 1, 6, 2, 6, 7, 2, 7, 3, 2, 0, 3, 4, 3, 7, 4
            };

            meshWriteData.SetAllIndices(indices);
        }
Пример #18
0
        void GenerateVisualContent(MeshGenerationContext obj)
        {
            if (m_Texture == null)
            {
                RegenerateTexture();
            }

            Quad(contentRect.position, contentRect.size, Color.white, m_Texture, obj);
        }
Пример #19
0
        private void OnGenerateVisualContent(MeshGenerationContext mgc)
        {
            var center = PieChart.GetChartCenter(localBound);

            if (m_ChartRadius < 0)
            {
                return;
            }
            ChartUtilities.Circle(center, m_ChartRadius, m_StartAngle, m_EndAngle, Data.Color, mgc);
        }
Пример #20
0
        public virtual void Draw(MeshGenerationContext mgc)
        {
            PaintAllOverlay(mgc);

            foreach (var ve in m_CleanUpOverlay)
            {
                m_OverlayData.Remove(ve);
            }
            m_CleanUpOverlay.Clear();
        }
Пример #21
0
 private void OnGenerateVisualContent(MeshGenerationContext mgc)
 {
     if (renderMode == RenderMode.Mesh)
     {
         SetupMeshRepaint();
     }
     else
     {
         SetupStandardRepaint();
     }
 }
        void OnGenerateVisualContent(MeshGenerationContext context)
        {
            var quadSize = localBound.size / k_NumberOfQuadsInRow;

            for (var x = 0; x < k_NumberOfQuadsInRow; x++)
            {
                for (var y = 0; y < k_NumberOfQuadsInRow; y++)
                {
                    Quad(new Vector2(x * quadSize.x, y * quadSize.y), quadSize, Color.white, m_Texture, context);
                }
            }
        }
Пример #23
0
        private void DrawEdge(MeshGenerationContext cxt)
        {
            if (state == State.None)
            {
                return;
            }
            uint vertexCount = RENDER_POINT_COUNT * 2;
            uint indexCount  = (vertexCount - 2) * 3;
            var  mesh        = cxt.Allocate((int)vertexCount, (int)indexCount, null);

            Vector3 normal = default;

            for (int i = 0;
                 i < RENDER_POINT_COUNT;
                 i++)
            {
                if (i < RENDER_POINT_COUNT - 1)
                {
                    if (i > 0)
                    {
                        normal = (renderPoints[i + 1].position - renderPoints[i - 1].position).normalized *
                                 actualHalfWidth;
                    }
                    else
                    {
                        normal = (renderPoints[i + 1].position - renderPoints[i].position).normalized * actualHalfWidth;
                    }

                    var tmp = normal.x;
                    normal.x = normal.y;
                    normal.y = -tmp;
                }

                var p = renderPoints[i];

                var v0 = GetVertex(p.position + normal, p.color);
                var v1 = GetVertex(p.position - normal, p.color);

                mesh.SetNextVertex(v0);
                mesh.SetNextVertex(v1);
            }

            for (int i = 0; i < RENDER_POINT_COUNT - 1; i++)
            {
                mesh.SetNextIndex((ushort)(0 + i * 2));
                mesh.SetNextIndex((ushort)(2 + i * 2));
                mesh.SetNextIndex((ushort)(1 + i * 2));
                mesh.SetNextIndex((ushort)(1 + i * 2));
                mesh.SetNextIndex((ushort)(2 + i * 2));
                mesh.SetNextIndex((ushort)(3 + i * 2));
            }
        }
Пример #24
0
            public void Do(MeshGenerationContext contex)
            {
                if (contex.Check() != 0)
                {
                    return;
                }

                if (node.UsedObject != null)
                {
                    node.UsedObject.Do(contex);
                }
                contex.stackSize++;
            }
Пример #25
0
        protected void DrawRect(MeshGenerationContext mgc, Rect rect, Color color, float alpha)
        {
            if (mgc == null)
            {
                throw new NullReferenceException("The MeshGenerationContext is null");
            }

            color.a = alpha;

            var rectParams = MeshGenerationContextUtils.RectangleParams.MakeSolid(rect, color, mgc.visualElement.panel.contextType);

            mgc.Rectangle(rectParams);
        }
Пример #26
0
        private void PaintAllOverlay(MeshGenerationContext mgc)
        {
            foreach (var kvp in m_OverlayData)
            {
                var overlayData = kvp.Value;

                DrawOverlayData(mgc, overlayData);
                if (overlayData.alpha < Mathf.Epsilon)
                {
                    m_CleanUpOverlay.Add(kvp.Key);
                }
            }
        }
Пример #27
0
        private void DrawLine(MeshGenerationContext ctx, Vector2 startPos, Vector2 endPos, Color color, float thickness, bool isGlowEnabled)
        {
            if (isGlowEnabled)
            {
                var colorBase = new Color(color.r, color.g, color.b, color.a * 0.3f);
                var colorNear = new Color(color.r, color.g, color.b, color.a * 0.5f);
                DrawLine(ctx, startPos, endPos, colorBase, thickness * 3f);
                DrawLine(ctx, startPos, endPos, colorNear, thickness * 1.5f);
            }

            DrawLine(ctx, startPos, endPos, color, thickness);
            DrawTriangle(ctx, startPos, endPos, color, thickness);
        }
Пример #28
0
            public void Do(MeshGenerationContext contex)
            {
                int start     = contex.LatestEdgeStartVertexIndex;
                var polyShape = contex.LatestEdge.polyShape;
                int count     = polyShape.Count;
                var mesh      = contex.mesh;
                var trises    = polyShape.Trises;

                for (int i = 0; i < trises.Count; i++)
                {
                    mesh.triangles.Add(trises[i] + start);
                }
            }
Пример #29
0
        void DrawTriangles(MeshGenerationContext mgc, List <Vector2> verts, Color wireColor, float alpha)
        {
            var count = verts.Count;

            for (int i = 0; i < count; i += 3)
            {
                var v0 = verts[i];
                var v1 = verts[i + 1];
                var v2 = verts[i + 2];
                DrawLine(mgc, v0, v1, wireColor, alpha);
                DrawLine(mgc, v1, v2, wireColor, alpha);
                DrawLine(mgc, v2, v0, wireColor, alpha);
            }
        }
Пример #30
0
 private void OnGenerateVisualContent(MeshGenerationContext mgc)
 {
     if (renderMode == RenderMode.Mesh)
     {
         SetupMeshRepaint();
     }
     else
     {
         SetupStandardRepaint();
         if (m_Texture != null)
         {
             var rectParams = MeshGenerationContextUtils.RectangleParams.MakeTextured(
                 new Rect(0, 0, m_Texture.width, m_Texture.height), new Rect(0, 0, 1, 1), m_Texture, ScaleMode.StretchToFill, panel.contextType);
             MeshGenerationContextUtils.Rectangle(mgc, rectParams);
         }
     }
 }