Delaunay.Voronoi.Regions C# (CSharp) Method

Regions() public method

public Regions ( ) : List>
return List>
		public List<List<Vector2>> Regions ()
		{
			return _sites.Regions (_plotBounds);
		}
		

Usage Example

Example #1
0
    public static List <GameObject> GenerateVoronoiPieces(GameObject source, int extraPoints = 0, int subshatterSteps = 0, Material mat = null)
    {
        List <GameObject> pieces = new List <GameObject>();

        if (mat == null)
        {
            mat = createFragmentMaterial(source);
        }

        //get transform information
        Vector3 origScale = source.transform.localScale;

        source.transform.localScale = Vector3.one;
        Quaternion origRotation = source.transform.localRotation;

        source.transform.localRotation = Quaternion.identity;

        //get rigidbody information
        Rigidbody2D rigbody      = source.GetComponent <Rigidbody2D>(); //Я добавил
        Vector2     origVelocity = rigbody.velocity;

        //get collider information
        PolygonCollider2D sourcePolyCollider = source.GetComponent <PolygonCollider2D>();
        BoxCollider2D     sourceBoxCollider  = source.GetComponent <BoxCollider2D>();
        List <Vector2>    points             = new List <Vector2>();
        List <Vector2>    borderPoints       = new List <Vector2>();

        if (sourcePolyCollider != null)
        {
            points       = getPoints(sourcePolyCollider);
            borderPoints = getPoints(sourcePolyCollider);
        }
        else if (sourceBoxCollider != null)
        {
            points       = getPoints(sourceBoxCollider);
            borderPoints = getPoints(sourceBoxCollider);
        }

        Rect rect = getRect(source);

        for (int i = 0; i < extraPoints; i++)
        {
            points.Add(new Vector2(Random.Range(rect.width / -2, rect.width / 2), Random.Range(rect.height / -2, rect.height / 2)));
        }


        Voronoi voronoi = new Delaunay.Voronoi(points, null, rect);
        List <List <Vector2> > clippedRegions = new List <List <Vector2> >();

        foreach (List <Vector2> region in voronoi.Regions())
        {
            clippedRegions = ClipperHelper.clip(borderPoints, region);
            foreach (List <Vector2> clippedRegion in clippedRegions)
            {
                pieces.Add(generateVoronoiPiece(source, clippedRegion, origVelocity, origScale, origRotation, mat, rigbody));
            }
        }

        List <GameObject> morePieces = new List <GameObject>();

        if (subshatterSteps > 0)
        {
            subshatterSteps--;
            foreach (GameObject piece in pieces)
            {
                morePieces.AddRange(SpriteExploder.GenerateVoronoiPieces(piece, extraPoints, subshatterSteps));
                GameObject.DestroyImmediate(piece);
            }
        }
        else
        {
            morePieces = pieces;
        }

        //reset transform information
        source.transform.localScale    = origScale;
        source.transform.localRotation = origRotation;

        Resources.UnloadUnusedAssets();

        return(morePieces);
    }
All Usage Examples Of Delaunay.Voronoi::Regions