/// <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); } } } } }
/// <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]); } } } } }
/// <summary> /// 增加山洞 /// </summary> /// <param name="startPosition"></param> /// <param name="caveData"></param> public static void AddCave(Chunk chunk, BiomeMapData[,] mapData, BiomeForCaveData caveData) { float frequency = 2; float amplitude = 1; FastNoise fastNoise = BiomeHandler.Instance.fastNoise; int caveNumber = WorldRandTools.Range(0, 10, chunk.chunkData.positionForWorld); for (int i = 8; i < caveNumber; i++) { int positionX = WorldRandTools.Range(1, chunk.chunkData.chunkWidth); int positionZ = WorldRandTools.Range(1, chunk.chunkData.chunkWidth); BiomeMapData biomeMapData = mapData[positionX, positionZ]; int positionY = WorldRandTools.Range(1, biomeMapData.maxHeight); Vector3Int startPosition = new Vector3Int(positionX, positionY, positionZ) + chunk.chunkData.positionForWorld; int caveDepth = WorldRandTools.Range(caveData.minDepth, caveData.maxDepth); int lastType = 0; for (int f = 0; f < caveDepth; f++) { int caveRange = WorldRandTools.Range(caveData.minSize, caveData.maxSize); if (startPosition.y < 5) { continue; } float offsetX = fastNoise.GetPerlin(0, startPosition.y * frequency, startPosition.z * frequency) * amplitude; float offsetY = fastNoise.GetPerlin(startPosition.x * frequency, 0, startPosition.z * frequency) * amplitude; float offsetZ = fastNoise.GetPerlin(startPosition.x * frequency, startPosition.y * frequency, 0) * amplitude; Vector3 offset = new Vector3(offsetX, offsetY, offsetZ).normalized; Vector3Int offsetInt = new Vector3Int(GetCaveDirection(offset.x), GetCaveDirection(offset.y), GetCaveDirection(offset.z)); startPosition += offsetInt; if (startPosition.y <= 3 || startPosition.y > biomeMapData.maxHeight) { break; } float absOffsetX = Mathf.Abs(offsetX); float absOffsetY = Mathf.Abs(offsetY); float absOffsetZ = Mathf.Abs(offsetZ); if (absOffsetX > absOffsetY && absOffsetX > absOffsetZ) { AddCaveRange(startPosition, caveRange, 1, lastType); lastType = 1; } else if (absOffsetY > absOffsetX && absOffsetY > absOffsetZ) { AddCaveRange(startPosition, caveRange, 2, lastType); lastType = 2; } else if (absOffsetZ > absOffsetX && absOffsetZ > absOffsetY) { AddCaveRange(startPosition, caveRange, 3, lastType); lastType = 3; } } } }
/// <summary> /// 获取主界面时间 /// </summary> /// <returns></returns> public TimeBean GetMainTime() { if (timeForMain == null) { timeForMain = new TimeBean(); timeForMain.SetTimeForHM(WorldRandTools.Range(0, 24), 0); } return(timeForMain); }
/// <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); } } } } } }
/// <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]); } }
/// <summary> /// 处理-随机角色 /// </summary> public void HandleForRandomCharacter() { UnityEngine.Random.InitState(TimeUtil.GetTimeStampForS32()); ui_ViewSelectChange_Hair.RandomSelect(); ui_ViewSelectChange_Eye.RandomSelect(); ui_ViewSelectChange_Mouth.RandomSelect(); ui_ViewSelectChange_Clothes.RandomSelect(); ui_ViewSelectColorChange_Skin.SetRandomColor(); ui_ViewSelectColorChange_Hair.SetRandomColor(); //随机性别 int sexRandom = WorldRandTools.Range(0, 2); ChangeSex(sexRandom == 0 ? SexTypeEnum.Man : SexTypeEnum.Woman); }
/// <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); } } }
/// <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); } } } }
public void InitData(Vector3Int wPos, Vector3Int[] listBiomeCenterPosition, Biome[] listBiome) { //距离该方块最近的生态点距离 float minBiomeDis = float.MaxValue; //距离该方块第二近的生态点距离 float secondMinBiomeDis = float.MaxValue; //最靠近的生态点 Vector3Int minBiomePosition = Vector3Int.zero; //便利中心点,寻找最靠近的生态点(维诺图) for (int i = 0; i < listBiomeCenterPosition.Length; i++) { Vector3Int itemCenterPosition = listBiomeCenterPosition[i]; float tempDis = Vector3Int.Distance(itemCenterPosition, wPos); //如果小于最小距离 if (tempDis <= minBiomeDis) { minBiomePosition = itemCenterPosition; minBiomeDis = tempDis; } //如果大于最小距离 并且小于第二小距离 else if (tempDis > minBiomeDis && tempDis <= secondMinBiomeDis) { secondMinBiomeDis = tempDis; } } //获取该点的生态信息 //int worldSeed = WorldCreateHandler.Instance.manager.GetWorldSeed(); //RandomTools biomeRandom = RandomUtil.GetRandom(worldSeed, biomeCenterPosition.x, biomeCenterPosition.z); //int biomeIndex = biomeRandom.NextInt(listBiome.Count); int biomeIndex = WorldRandTools.Range(listBiome.Length, minBiomePosition); biome = listBiome[biomeIndex]; //获取当前位置方块随机生成的高度值 maxHeight = BiomeHandler.Instance.GetHeightData(wPos, biome.biomeInfo); offsetDis = secondMinBiomeDis - minBiomeDis; }
/// <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); }
/// <summary> /// 获取生态中心点 /// </summary> /// <param name="currentChunk"></param> /// <param name="range">范围</param> /// <param name="rate">倍数</param> /// <returns></returns> public Vector3Int[] GetBiomeCenterPosition(Chunk currentChunk, int range, int rate) { List <Vector3Int> listData = new List <Vector3Int>(); int worldSeed = WorldCreateHandler.Instance.manager.GetWorldSeed(); int unitSize = currentChunk.chunkData.chunkWidth * rate; int startX = Mathf.FloorToInt(currentChunk.chunkData.positionForWorld.x / (float)unitSize) * unitSize; int startZ = Mathf.FloorToInt(currentChunk.chunkData.positionForWorld.z / (float)unitSize) * unitSize; for (int x = -range; x < range; x++) { for (int z = -range; z < range; z++) { Vector3Int currentPosition = new Vector3Int(x * unitSize + startX, 0, z * unitSize + startZ); //RandomTools random = RandomUtil.GetRandom(worldSeed, currentPosition.x, currentPosition.z); //int addRate = random.NextInt(50); int addRate = WorldRandTools.Range(50, currentPosition * worldSeed); if (addRate <= 1) { listData.Add(currentPosition); } } } return(listData.ToArray()); }
/// <summary> /// 增加世界之树 /// </summary> /// <param name="startPosition"></param> /// <param name="treeData"></param> public static void AddTreeForWorld(Vector3Int startPosition, BiomeForTreeData treeData) { //概率小于万分之一的用RandomTools int seed = WorldCreateHandler.Instance.manager.GetWorldSeed(); RandomTools randomTools = RandomUtil.GetRandom(seed, startPosition.x, startPosition.y, startPosition.z); //生成概率 float addRate = randomTools.NextFloat(); //高度 int treeHeight = WorldRandTools.Range(treeData.minHeight, treeData.maxHeight); if (addRate < treeData.addRate) { for (int y = 0; y < treeHeight; y++) { Vector3Int treeTrunkPosition = startPosition + Vector3Int.up * (y + 1); int trunkRange = treeData.trunkRange; for (int x = -trunkRange; x <= trunkRange; x++) { for (int z = -trunkRange; z <= trunkRange; z++) { if ((x == -trunkRange || x == trunkRange) && (z == -trunkRange || z == trunkRange)) { continue; } else if ((x == -trunkRange + 1 || x == trunkRange - 1) && (z == -trunkRange || z == trunkRange)) { continue; } else if ((z == -trunkRange + 1 || z == trunkRange - 1) && (x == -trunkRange || x == trunkRange)) { continue; } else { Vector3Int tempTrunkPosition = new(treeTrunkPosition.x + x, treeTrunkPosition.y, treeTrunkPosition.z + z); //生成树干 WorldCreateHandler.Instance.manager.AddUpdateBlock(tempTrunkPosition, treeData.treeTrunk); } if ((x == -trunkRange || x == trunkRange || z == -trunkRange || z == trunkRange) || ((x == -trunkRange + 1 || x == trunkRange - 1) && (z == -trunkRange || z == trunkRange)) || ((z == -trunkRange + 1 || z == trunkRange - 1) && (x == -trunkRange || x == trunkRange)) || ((x == -trunkRange + 2 || x == trunkRange - 2) && (z == -trunkRange || z == trunkRange)) || ((z == -trunkRange + 2 || z == trunkRange - 2) && (x == -trunkRange || x == trunkRange))) { //树盘 if (y == 0 || y == 1) { Vector3Int baseStartPosition = treeTrunkPosition + new Vector3Int(x, -1, z); int baseWith = WorldRandTools.Range(3, 6); for (int b = 0; b < baseWith; b++) { BlockDirectionEnum baseDirection = (x == -trunkRange ? BlockDirectionEnum.LeftForward : x == trunkRange ? BlockDirectionEnum.RightForward : z == -trunkRange ? BlockDirectionEnum.ForwardForward : z == trunkRange ? BlockDirectionEnum.BackForward : BlockDirectionEnum.LeftForward); int branchDirectionX = WorldRandTools.Range(0, 2); int branchDirectionY = WorldRandTools.Range(0, 2); int branchDirectionZ = WorldRandTools.Range(0, 2); int addPositionX; if (x == -trunkRange || x == trunkRange) { addPositionX = x > 0 ? 1 : -1; } else if (x == -trunkRange + 1 || x == trunkRange - 1 || x == -trunkRange + 2 || x == trunkRange - 2) { int tempRandom = WorldRandTools.Range(0, 2); if (tempRandom == 0) { addPositionX = x > 0 ? 1 : -1; } else { addPositionX = (branchDirectionX == 0 ? -1 : 1); } } else { addPositionX = (branchDirectionX == 0 ? -1 : 1); } int addPositionZ; if (z == -trunkRange || z == trunkRange) { addPositionZ = z > 0 ? 1 : -1; } else if (z == -trunkRange + 1 || z == trunkRange - 1 || z == -trunkRange + 2 || z == trunkRange - 2) { int tempRandom = WorldRandTools.Range(0, 2); if (tempRandom == 0) { addPositionZ = z > 0 ? 1 : -1; } else { addPositionZ = (branchDirectionZ == 0 ? -1 : 1); } } else { addPositionZ = (branchDirectionZ == 0 ? -1 : 1); } int addPositionY = (branchDirectionY == 0 ? -1 : 0); if (addPositionY == -1) { addPositionX = 0; addPositionZ = 0; baseDirection = BlockDirectionEnum.UpForward; } Vector3Int addPosition = new(addPositionX, addPositionY, addPositionZ); baseStartPosition += addPosition; //干 WorldCreateHandler.Instance.manager.AddUpdateBlock(baseStartPosition, treeData.treeTrunk, baseDirection); } } //枝 if (y > treeHeight / 2) { int addBranchRate = WorldRandTools.Range(0, 3); if (addBranchRate == 0) { int branchWith = WorldRandTools.Range(0, treeHeight / 2) + treeHeight / 4; Vector3Int branchStartPosition = treeTrunkPosition + new Vector3Int(x, 0, z); for (int b = 0; b < branchWith; b++) { BlockDirectionEnum branchDirection = (x == -trunkRange ? BlockDirectionEnum.LeftForward : x == trunkRange ? BlockDirectionEnum.RightForward : z == -trunkRange ? BlockDirectionEnum.ForwardForward : z == trunkRange ? BlockDirectionEnum.BackForward : BlockDirectionEnum.LeftForward); int branchDirectionX = WorldRandTools.Range(0, 2); int branchDirectionY = WorldRandTools.Range(0, 4); int branchDirectionZ = WorldRandTools.Range(0, 2); int addPositionX; if (x == -trunkRange || x == trunkRange) { addPositionX = x > 0 ? 1 : -1; } else if (x == -trunkRange + 1 || x == trunkRange - 1 || x == -trunkRange + 2 || x == trunkRange - 2) { int tempRandom = WorldRandTools.Range(0, 2); if (tempRandom == 0) { addPositionX = x > 0 ? 1 : -1; } else { addPositionX = (branchDirectionX == 0 ? -1 : 1); } } else { addPositionX = (branchDirectionX == 0 ? -1 : 1); } int addPositionZ; if (z == -trunkRange || z == trunkRange) { addPositionZ = z > 0 ? 1 : -1; } else if (z == -trunkRange + 1 || z == trunkRange - 1 || z == -trunkRange + 2 || z == trunkRange - 2) { int tempRandom = WorldRandTools.Range(0, 2); if (tempRandom == 0) { addPositionZ = z > 0 ? 1 : -1; } else { addPositionZ = (branchDirectionZ == 0 ? -1 : 1); } } else { addPositionZ = (branchDirectionZ == 0 ? -1 : 1); } int addPositionY = (branchDirectionY == 0 ? 1 : 0); Vector3Int addPosition = new(addPositionX, addPositionY, addPositionZ); branchStartPosition += addPosition; //干 WorldCreateHandler.Instance.manager.AddUpdateBlock(branchStartPosition, treeData.treeTrunk, branchDirection); //叶 if (b % 4 == 0) { int leavesRange = 2; for (int leavesX = -leavesRange; leavesX <= leavesRange; leavesX++) { for (int leavesY = -leavesRange; leavesY <= leavesRange; leavesY++) { for (int leavesZ = -leavesRange; leavesZ <= leavesRange; leavesZ++) { if (((leavesX == leavesRange || leavesX == -leavesRange) && (leavesY == leavesRange || leavesY == -leavesRange)) || ((leavesY == leavesRange || leavesY == -leavesRange) && (leavesZ == leavesRange || leavesZ == -leavesRange)) || ((leavesX == leavesRange || leavesX == -leavesRange) && (leavesZ == leavesRange || leavesZ == -leavesRange))) { continue; } Vector3Int leavesPosition = branchStartPosition + new Vector3Int(leavesX, leavesY, leavesZ); WorldCreateHandler.Instance.manager.AddUpdateBlock(leavesPosition, treeData.treeLeaves); } } } } } } } } } } } } }
/// <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); } } }
/// <summary> /// 死亡 /// </summary> public void Dead() { //获取所有的骨骼节点 //List<Transform> listObjBone = CptUtil.GetAllCptInChildrenByContainName<Transform>(gameObject, "Bone"); //for (int i = 0; i < listObjBone.Count; i++) //{ // Transform itemBone = listObjBone[i]; // Rigidbody boneRB = itemBone.AddComponentEX<Rigidbody>(); //} Vector3 randomRotate; int random = WorldRandTools.Range(0, 4); switch (random) { case 0: randomRotate = new Vector3(90, 0, 0); break; case 1: randomRotate = new Vector3(-90, 0, 0); break; case 2: randomRotate = new Vector3(0, 0, 90); break; case 3: randomRotate = new Vector3(0, 0, -90); break; default: randomRotate = new Vector3(-90, 0, 0); break; } //身体侧翻 transform .DOLocalRotate(randomRotate, 0.5f, RotateMode.Fast) .OnComplete(() => { //查询身体位置 Transform bodyTF = CptUtil.GetCptInChildrenByName <Transform>(gameObject, "BoneBody"); //消失烟雾 EffectBean effectData = new EffectBean(); effectData.effectName = EffectInfo.Effect_Dead_1; effectData.effectType = EffectTypeEnum.Visual; effectData.timeForShow = 5; effectData.effectPosition = bodyTF.position; EffectHandler.Instance.ShowEffect(effectData, (effect) => { effect.PlayEffect(); }); //删除此物体 Destroy(gameObject); }); //关闭动画 creatureAnim.EnabledAnim(false); //关闭刚体 if (rbCreature != null) { rbCreature.isKinematic = true; } //关闭检测 if (colliderCreature != null) { colliderCreature.enabled = false; } }