示例#1
0
    private List <PlatformGroup> GroupSpaces(List <Vector3> availableSpacesToGroup)
    {
        List <PlatformGroup> groups = new List <PlatformGroup>();

        if (settings.amountOfGroups < 1)
        {
            settings.amountOfGroups = 1;
        }

        int maxBaseGroupSize = (int)(availableSpacesToGroup.Count / settings.amountOfGroups);

        Dictionary <PlatformGroup, bool> platformRisen = new Dictionary <PlatformGroup, bool>();

        float maxDistance = 1.5f * Math.Max(hexFieldGenerator.GetTileSize().width, hexFieldGenerator.GetTileSize().height);

        for (float j = 0; j < settings.amountOfGroups; j++)
        {
            PlatformGroup pg = new PlatformGroup();
            groups.Add(pg);
            platformRisen.Add(pg, Random.value < settings.chanceToRisePlatform);

            int     size   = 1;
            Vector3 center = availableSpacesToGroup[Random.Range(0, availableSpacesToGroup.Count)];
            availableSpacesToGroup.Remove(center);
            for (int i = 0; i < availableSpacesToGroup.Count; i++)
            {
                if (maxBaseGroupSize <= size)
                {
                    break;
                }

                if (Vector3.Distance(center, availableSpacesToGroup[i]) <= maxDistance)
                {
                    Vector3 v = availableSpacesToGroup[i];
                    availableSpacesToGroup.Remove(v);
                    i--;

                    v.y = platformRisen[pg] ? settings.risenPlatformHeight : 0;
                    pg.AddSpace(v);
                    size++;
                }
            }
        }

        while (settings.maxAmount > (hexFieldGenerator.GetSpacesCount() - availableSpacesToGroup.Count) && availableSpacesToGroup.Count > 0)
        {
            //TODO not do bs
            Vector3 space            = availableSpacesToGroup[0];
            int     randomGroupIndex = Random.Range(0, groups.Count);
            groups[randomGroupIndex].AddSpace(space);
            availableSpacesToGroup.Remove(space);
        }

        return(groups);
    }
示例#2
0
    private List <PlatformGroup> GroupSpaces(List <Vector3> availableSpacesToGroup)
    {
        List <PlatformGroup> groups = new List <PlatformGroup>();

        if (amountOfGroups < 1)
        {
            amountOfGroups = 1;
        }

        int maxBaseGroupSize = (int)(availableSpacesToGroup.Count / amountOfGroups);

        Dictionary <PlatformGroup, bool> platformRisen = new Dictionary <PlatformGroup, bool>();

        float maxDistance = 1.5f * tileSize.magnitude;

        for (float j = 0; j < amountOfGroups; j++)
        {
            PlatformGroup pg = new PlatformGroup();
            groups.Add(pg);
            platformRisen.Add(pg, Random.value < chanceToRisePlatform);

            int     size   = 1;
            Vector3 center = availableSpacesToGroup[Random.Range(0, availableSpacesToGroup.Count)];
            availableSpacesToGroup.Remove(center);
            for (int i = 0; i < availableSpacesToGroup.Count; i++)
            {
                if (maxBaseGroupSize <= size)
                {
                    break;
                }

                if (Vector3.Distance(center, availableSpacesToGroup[i]) <= maxDistance)
                {
                    Vector3 v = availableSpacesToGroup[i];
                    availableSpacesToGroup.Remove(v);
                    i--;

                    v.y = platformRisen[pg] ? risenPlatformHeight : 0;
                    pg.AddSpace(v);
                    size++;
                }
            }
        }

        while (maxAmount > (maxFreeSpaces - availableSpacesToGroup.Count) && availableSpacesToGroup.Count > 0)
        {
            //TODO not do bs
            Vector3 space            = availableSpacesToGroup[0];
            int     randomGroupIndex = Random.Range(0, groups.Count);
            groups[randomGroupIndex].AddSpace(space);
            availableSpacesToGroup.Remove(space);
        }

        return(groups);
    }