protected override void Build(PolygonCollider2D collider, List <Vector3> positions)
        {
            collider.points = to2DArray(positions);

            if (IsMeshGenerationOn)
            {
                var renderer   = Get <MeshRenderer>();
                var filter     = Get <MeshFilter>();
                var filterMesh = filter.sharedMesh;
                if (filterMesh == null)
                {
                    filterMesh = new Mesh();
                }
                if (triangulator == null)
                {
                    triangulator = new BGTriangulator2D();
                }
                triangulator.Bind(filterMesh, positions, new BGTriangulator2D.Config
                {
                    Closed       = Curve.Closed,
                    Mode2D       = Curve.Mode2D,
                    Flip         = false,
                    ScaleUV      = Vector2.one,
                    OffsetUV     = Vector2.zero,
                    DoubleSided  = false,
                    ScaleBackUV  = Vector2.one,
                    OffsetBackUV = Vector2.zero,
                });

                filter.sharedMesh = filterMesh;
            }
        }
Exemple #2
0
        protected override void Build(MeshCollider collider, List <Vector3> positions)
        {
            //collider
            var mesh = collider.sharedMesh;

            if (mesh == null)
            {
                mesh = new Mesh();
            }

            if (triangulator == null)
            {
                triangulator = new BGTriangulator2D();
            }

            triangulator.Bind(mesh, positions, new BGTriangulator2D.Config
            {
                Closed       = Curve.Closed,
                Mode2D       = Curve.Mode2D,
                Flip         = flip,
                ScaleUV      = Vector2.one,
                OffsetUV     = Vector2.zero,
                DoubleSided  = doubleSided,
                ScaleBackUV  = Vector2.one,
                OffsetBackUV = Vector2.zero,
            });
            collider.sharedMesh = mesh;

            //mesh
            if (IsMeshGenerationOn)
            {
                var renderer   = Get <MeshRenderer>();
                var filter     = Get <MeshFilter>();
                var filterMesh = filter.sharedMesh;
                if (filterMesh == null)
                {
                    filterMesh = new Mesh();
                }

                triangulator.Bind(filterMesh, positions, new BGTriangulator2D.Config
                {
                    Closed       = Curve.Closed,
                    Mode2D       = Curve.Mode2D,
                    Flip         = meshFlip,
                    ScaleUV      = Vector2.one,
                    OffsetUV     = Vector2.zero,
                    DoubleSided  = meshDoubleSided,
                    ScaleBackUV  = Vector2.one,
                    OffsetBackUV = Vector2.zero,
                });

                filter.sharedMesh = filterMesh;
            }
        }
        //===============================================================================================
        //                                                    Public Functions
        //===============================================================================================
        public void UpdateUI()
        {
            updateAtFrame = Time.frameCount;

            if (!Curve.Mode2DOn)
            {
                return;
            }

            var positions = Positions;

            MeshFilter meshFilter;

            try
            {
                meshFilter = MeshFilter;
            }
            catch (MissingReferenceException)
            {
                RemoveListeners();
                return;
            }
            var mesh = meshFilter.sharedMesh;

            if (mesh == null)
            {
                mesh            = new Mesh();
                meshFilter.mesh = mesh;
            }

            if (triangulator == null)
            {
                triangulator = new BGTriangulator2D();
            }

            triangulator.Bind(mesh, positions, new BGTriangulator2D.Config
            {
                Closed       = Curve.Closed,
                Mode2D       = Curve.Mode2D,
                Flip         = flip,
                ScaleUV      = scaleUV,
                OffsetUV     = offsetUV,
                DoubleSided  = doubleSided,
                ScaleBackUV  = scaleBackUV,
                OffsetBackUV = offsetBackUV,
            });
        }