예제 #1
0
    private List <ColoredBorders> ColorRegionBorders()
    {
        //Setup
        List <List <ColoredVector2Int> > regionList = GetRegions();
        List <ColoredBorders>            cBorders   = new List <ColoredBorders>();

        for (int i = 0; i < regionList.Count; i++)
        {
            List <ColoredVector2Int> l       = regionList[i];
            ColoredBorders           cBorder = new ColoredBorders(regionList[i][0].color);

            for (int r = 0; r < l.Count; r++)
            {
                ColoredVector2Int currentCVec = l[r];
                List <Vector2Int> n           = currentCVec.vector2Int.GetDirectNeighbours(mapSize);

                //Check if it's next to mapborder
                if (n.Count < 4)
                {
                    cBorder.outerBorder.Add(currentCVec.vector2Int);
                    continue;
                }

                //Checks if it's next to another color
                for (int t = 0; t < n.Count; t++)
                {
                    if (pix.Exists(x => (x.vector2Int == n[t]) && (x.color != currentCVec.color)))
                    {
                        cBorder.outerBorder.Add(currentCVec.vector2Int);
                        break;
                    }
                }
            }

            for (int r = 0; r < l.Count; r++)
            {
                ColoredVector2Int currentCVec = l[r];
                List <Vector2Int> n           = currentCVec.vector2Int.GetDirectNeighbours(mapSize);

                //Checks if it's next to another color
                for (int t = 0; t < n.Count; t++)
                {
                    if (pix.Exists(x => (x.vector2Int == n[t]) && (x.color != currentCVec.color)))
                    {
                        cBorder.innerBorder.Add(currentCVec.vector2Int);
                        break;
                    }
                }
            }

            cBorders.Add(cBorder);
        }

        return(cBorders);
    }
예제 #2
0
    private void PerlinNoiseBorder()
    {
        var coloredBorders = ColorRegionBorders();

        //Disable some part of the border
        for (int i = 0; i < coloredBorders.Count; i++)
        {
            ColoredBorders cBorder = coloredBorders[i];

            for (int r = 0; r < cBorder.innerBorder.Count; r++)
            {
                float value = Random.value;
                SetPixColor((value > 0.5f)? cBorder.innerBorder[r] : cBorder.outerBorder[r], cBorder.color);
            }

            for (int r = 0; r < cBorder.outerBorder.Count; r++)
            {
                SetPixColor(cBorder.outerBorder[r], (Random.value > 0.5f) ? cBorder.color : Color.black);
            }
        }

        ApplyPixColorsToTexture();
    }