コード例 #1
0
    /// <summary>
    /// 增加矿石
    /// </summary>
    /// <param name="randomData"></param>
    /// <param name="addRate"></param>
    /// <param name="blockType"></param>
    /// <param name="startPosition"></param>
    public static void AddOre(uint randomData, float addRate, Vector3Int startPosition)
    {
        //生成概率
        float addRateRandom = WorldRandTools.GetValue(startPosition, randomData);

        if (addRateRandom < addRate)
        {
            //高度
            int range = 2;
            //不能直接用 startPosition 因为addRateRandom 的概率已经决定了他的值
            int randomOre = WorldRandTools.Range(0, arrayBlockOre.Length, new Vector3(startPosition.x, 0, 0));
            for (int x = -range; x < range; x++)
            {
                for (int y = -range; y < range; y++)
                {
                    for (int z = -range; z < range; z++)
                    {
                        Vector3Int blockPosition = new Vector3Int(startPosition.x + x, startPosition.y + y, startPosition.z + z);
                        float      disTemp       = Vector3Int.Distance(blockPosition, startPosition);
                        if (blockPosition.y <= 3 || disTemp >= range - 0.5f)
                        {
                            continue;
                        }
                        WorldCreateHandler.Instance.manager.AddUpdateBlock(blockPosition, arrayBlockOre[randomOre]);
                    }
                }
            }
        }
    }
コード例 #2
0
    /// <summary>
    /// 增加水池
    /// </summary>
    /// <param name="randomData"></param>
    /// <param name="startPosition"></param>
    /// <param name="riverData"></param>
    public static void AddWaterPool(uint randomData, Vector3Int startPosition, BiomeForWaterPoolData riverData)
    {
        //生成概率
        float addRate = WorldRandTools.GetValue(startPosition, randomData);

        if (addRate < riverData.addRate)
        {
            //高度
            int depth = WorldRandTools.Range(riverData.minDepth, riverData.maxDepth, startPosition, 1);
            int size  = WorldRandTools.Range(riverData.minSize, riverData.maxSize, startPosition, 101);

            Vector3Int tempPosition = startPosition;
            for (int z = -size; z <= size; z++)
            {
                for (int y = -depth; y <= 0; y++)
                {
                    for (int x = -size; x <= size; x++)
                    {
                        Vector3Int currentPosition = tempPosition + new Vector3Int(x, y, z);
                        float      dis             = Vector3.Distance(currentPosition, startPosition);
                        if (tempPosition.y <= 0 || dis >= size)
                        {
                            continue;
                        }
                        WorldCreateHandler.Instance.manager.AddUpdateBlock(currentPosition.x, currentPosition.y, currentPosition.z, BlockTypeEnum.None);
                    }
                }
            }
        }
    }
コード例 #3
0
    /// <summary>
    /// 增加普通的树
    /// </summary>
    /// <param name="startPosition"></param>
    /// <param name="treeData"></param>
    public static void AddTree(uint randomData, Vector3Int startPosition, BiomeForTreeData treeData)
    {
        //生成概率
        float addRate = WorldRandTools.GetValue(startPosition, randomData);

        if (addRate < treeData.addRate)
        {
            //高度
            int treeHeight = WorldRandTools.Range(treeData.minHeight, treeData.maxHeight);
            for (int i = 0; i < treeHeight + 2; i++)
            {
                Vector3Int treeTrunkPosition = new(startPosition.x, startPosition.y + (i + 1), startPosition.z);
                //生成树干
                if (i < treeHeight)
                {
                    WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition, treeData.treeTrunk);
                }
                if (i > 2)
                {
                    //最大范围
                    int range = treeData.leavesRange;
                    if (i >= treeHeight)
                    {
                        //叶子在最顶层递减
                        range -= (i - treeHeight);
                        if (range < 0)
                        {
                            range = 0;
                        }
                    }

                    //生成叶子
                    for (int x = -range; x <= range; x++)
                    {
                        for (int z = -range; z <= range; z++)
                        {
                            if (x == startPosition.x && z == startPosition.z)
                            {
                                continue;
                            }
                            if (Math.Abs(x) == range || Math.Abs(z) == range)
                            {
                                //如果是边界 则有几率不生成
                                int randomLeaves = WorldRandTools.Range(0, 3);
                                if (randomLeaves == 0)
                                {
                                    continue;
                                }
                            }
                            WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x + x, treeTrunkPosition.y, treeTrunkPosition.z + z, treeData.treeLeaves);
                        }
                    }
                }
            }
        }
    }
コード例 #4
0
    /// <summary>
    /// 增加鲜花
    /// </summary>
    /// <param name="randomData"></param>
    /// <param name="startPosition"></param>
    /// <param name="flowerData"></param>
    public static void AddFlower(uint randomData, Vector3Int startPosition, BiomeForPlantData flowerData)
    {
        float addRate          = WorldRandTools.GetValue(startPosition, randomData);
        int   flowerTypeNumber = WorldRandTools.Range(0, flowerData.listPlantType.Count);

        if (addRate < flowerData.addRate)
        {
            WorldCreateHandler.Instance.manager.AddUpdateBlock(startPosition.x, startPosition.y + 1, startPosition.z, flowerData.listPlantType[flowerTypeNumber]);
        }
    }
コード例 #5
0
    /// <summary>
    /// 生成枯木
    /// </summary>
    /// <param name="randomData"></param>
    /// <param name="startPosition"></param>
    public static void AddDeadwood(uint randomData, float addRate, Vector3Int startPosition)
    {
        //生成概率
        float addRateRandom = WorldRandTools.GetValue(startPosition, randomData);

        if (addRateRandom < addRate)
        {
            //高度
            int treeHeight = WorldRandTools.Range(1, 4);

            Vector3Int treeDataPosition = startPosition;
            for (int i = 0; i < treeHeight; i++)
            {
                WorldCreateHandler.Instance.manager.AddUpdateBlock(treeDataPosition.x, treeDataPosition.y + i + 1, treeDataPosition.z, BlockTypeEnum.WoodDead, BlockDirectionEnum.UpForward);
            }
        }
    }
コード例 #6
0
    /// <summary>
    ///  增加仙人掌
    /// </summary>
    /// <param name="randomData"></param>
    /// <param name="startPosition"></param>
    /// <param name="cactusData"></param>
    public static void AddCactus(uint randomData, Vector3Int startPosition, BiomeForTreeData cactusData)
    {
        //生成概率
        float addRate = WorldRandTools.GetValue(startPosition, randomData);
        //高度
        int treeHeight = WorldRandTools.Range(cactusData.minHeight, cactusData.maxHeight);

        if (addRate < cactusData.addRate)
        {
            for (int i = 0; i < treeHeight; i++)
            {
                Vector3Int treeTrunkPosition = startPosition + Vector3Int.up * (i + 1);
                //生成树干
                if (i < treeHeight)
                {
                    WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition, cactusData.treeTrunk);
                }
            }
        }
    }
コード例 #7
0
    /// <summary>
    /// 增加建筑
    /// </summary>
    /// <param name="addRate"></param>
    /// <param name="randomData"></param>
    /// <param name="startPosition"></param>
    /// <param name="buildingType"></param>
    public static bool AddBuilding(float addRate, uint randomData, Vector3Int startPosition, BuildingTypeEnum buildingType)
    {
        float randomRate;

        if (addRate < 0.00001f)
        {
            //概率小于万分之一的用RandomTools
            int         seed        = WorldCreateHandler.Instance.manager.GetWorldSeed();
            RandomTools randomTools = RandomUtil.GetRandom(seed, startPosition.x, startPosition.y, startPosition.z);
            //生成概率
            randomRate = randomTools.NextFloat();
        }
        else
        {
            randomRate = WorldRandTools.GetValue(startPosition, randomData);
        }
        if (randomRate < addRate)
        {
            BuildingInfoBean buildingInfo = BiomeHandler.Instance.manager.GetBuildingInfo(buildingType);

            List <BuildingBean> listBuildingData = buildingInfo.listBuildingData;

            int randomAngle = WorldRandTools.Range(0, 4, startPosition) * 90;

            for (int i = 0; i < listBuildingData.Count; i++)
            {
                BuildingBean buildingData   = listBuildingData[i];
                Vector3Int   targetPosition = startPosition + buildingData.GetPosition();
                float        createRate     = WorldRandTools.GetValue(targetPosition);

                if (buildingData.randomRate == 0 || createRate < buildingData.randomRate)
                {
                    VectorUtil.GetRotatedPosition(startPosition, targetPosition, new Vector3(0, randomAngle, 0));
                    WorldCreateHandler.Instance.manager.AddUpdateBlock(targetPosition, buildingData.blockId, (BlockDirectionEnum)buildingData.direction);
                }
            }
            return(true);
        }
        return(false);
    }
コード例 #8
0
    /// <summary>
    /// 生成大树
    /// </summary>
    /// <param name="startPosition"></param>
    /// <param name="treeData"></param>
    public static void AddTreeForBig(uint randomData, Vector3Int startPosition, BiomeForTreeData treeData)
    {
        //生成概率
        float addRate = WorldRandTools.GetValue(startPosition, randomData);

        if (addRate < treeData.addRate)
        {
            //高度
            int treeHeight = WorldRandTools.Range(treeData.minHeight, treeData.maxHeight);
            for (int i = 5; i < treeHeight + 3; i++)
            {
                //生成树叶
                Vector3Int treeTrunkPosition = startPosition + Vector3Int.up * (i + 1);
                int        range             = treeData.leavesRange;
                if (i == treeHeight + 2)
                {
                    range -= 1;
                }
                else if (i == 5)
                {
                    range -= 1;
                }

                for (int x = -range; x <= range; x++)
                {
                    for (int z = -range; z <= range; z++)
                    {
                        //生成概率
                        if (x == -range || x == range || z == -range || z == range)
                        {
                            int leavesRate = WorldRandTools.Range(0, 4);
                            if (leavesRate == 0)
                            {
                                continue;
                            }
                        }
                        WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x + x, treeTrunkPosition.y, treeTrunkPosition.z + z, treeData.treeLeaves);
                    }
                }
            }


            //生成树干
            for (int i = 0; i < treeHeight; i++)
            {
                Vector3Int treeTrunkPosition = startPosition + Vector3Int.up * (i + 1);

                if (i == 0 || i == 1)
                {
                    if (i == 0)
                    {
                        WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x - 2, treeTrunkPosition.y, treeTrunkPosition.z, treeData.treeTrunk, BlockDirectionEnum.LeftForward);
                        WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x + 2, treeTrunkPosition.y, treeTrunkPosition.z, treeData.treeTrunk, BlockDirectionEnum.RightForward);
                        WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x - 2, treeTrunkPosition.y, treeTrunkPosition.z + 2, treeData.treeTrunk, BlockDirectionEnum.ForwardForward);
                        WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x - 2, treeTrunkPosition.y, treeTrunkPosition.z - 2, treeData.treeTrunk, BlockDirectionEnum.BackForward);
                    }
                    WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x + 1, treeTrunkPosition.y, treeTrunkPosition.z + 1, treeData.treeTrunk);
                    WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x - 1, treeTrunkPosition.y, treeTrunkPosition.z - 1, treeData.treeTrunk);
                    WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x + 1, treeTrunkPosition.y, treeTrunkPosition.z - 1, treeData.treeTrunk);
                    WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x - 1, treeTrunkPosition.y, treeTrunkPosition.z + 1, treeData.treeTrunk);
                }

                if (i > treeHeight - 3)
                {
                    int isCreate = WorldRandTools.Range(0, 4);
                    if (isCreate == 1)
                    {
                        WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x - 2, treeTrunkPosition.y, treeTrunkPosition.z, treeData.treeTrunk, BlockDirectionEnum.LeftForward);
                    }
                    isCreate = WorldRandTools.Range(0, 4);
                    if (isCreate == 1)
                    {
                        WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x + 2, treeTrunkPosition.y, treeTrunkPosition.z, treeData.treeTrunk, BlockDirectionEnum.RightForward);
                    }
                    isCreate = WorldRandTools.Range(0, 4);
                    if (isCreate == 1)
                    {
                        WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x, treeTrunkPosition.y, treeTrunkPosition.z + 2, treeData.treeTrunk, BlockDirectionEnum.ForwardForward);
                    }
                    isCreate = WorldRandTools.Range(0, 4);
                    if (isCreate == 1)
                    {
                        WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x, treeTrunkPosition.y, treeTrunkPosition.z - 2, treeData.treeTrunk, BlockDirectionEnum.BackForward);
                    }
                }
                WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x, treeTrunkPosition.y, treeTrunkPosition.z, treeData.treeTrunk);
                WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x - 1, treeTrunkPosition.y, treeTrunkPosition.z, treeData.treeTrunk);
                WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x + 1, treeTrunkPosition.y, treeTrunkPosition.z + 1, treeData.treeTrunk);
                WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x, treeTrunkPosition.y, treeTrunkPosition.z + 1, treeData.treeTrunk);
                WorldCreateHandler.Instance.manager.AddUpdateBlock(treeTrunkPosition.x, treeTrunkPosition.y, treeTrunkPosition.z - 1, treeData.treeTrunk);
            }
        }
    }