Пример #1
0
    GameObject GenerateSingleHex(int x, int y, float height, int prefabNum)
    {
        GameObject temp = (GameObject)GameObject.Instantiate(hexagonPrefabs[prefabNum]);

        temp.transform.parent        = closeHolder;
        temp.transform.localRotation = Quaternion.identity;
        Vector2 toVec3 = HexHelp.GetRelativePosition(new Vector2(y, x), rings);

        temp.transform.localPosition = new Vector3(toVec3.x, height, toVec3.y);
        return(temp);
    }
Пример #2
0
    public Vector3 GetLegitSpot(float heightIncrease, bool localOffset)
    {
        while (true)
        {
            int  randX         = Random.Range(0, tiles.GetLength(2));
            int  randY         = Random.Range(0, tiles.GetLength(1));
            int  randLayer     = Random.Range(0, tiles.GetLength(0) - 1);
            bool badFoundation = tiles[randLayer, randY, randX] == HexType.None ||
                                 tiles[randLayer, randY, randX] == HexType.Stairs0 ||
                                 tiles[randLayer, randY, randX] == HexType.Stairs90 ||
                                 tiles[randLayer, randY, randX] == HexType.Stairs180 ||
                                 tiles[randLayer, randY, randX] == HexType.Stairs270;

            if (!badFoundation && !HexHelp.CheckAboveMinusHuts(randX, randY, randLayer, tiles))
            {
                Vector2 toVec3 = HexHelp.GetRelativePosition(new Vector2(randY, randX), rings);
                //
                float height = baseHeightStats.GetAt(randX, randY) - baseHeightStats.GetAvgHeight();
                height += 2 * Mathf.Min(iStats.layerStats.Count, randLayer + 1);
                height += 4 * Mathf.Max(0, randLayer + 1 - iStats.layerStats.Count);
                height += heightIncrease;

                Vector3 toReturn = Vector3.zero;
                if (localOffset)
                {
                    toReturn = new Vector3(toVec3.x, height, toVec3.y);
                }
                else
                {
                    GameObject marker = new GameObject();
                    marker.transform.parent        = transform;
                    marker.transform.localPosition = new Vector3(toVec3.x, height, toVec3.y);
                    toReturn = marker.transform.position;
                    GameObject.Destroy(marker);
                }


                return(toReturn);
            }
        }
    }