/// <summary>
        /// 可跨多块地形的细节修改
        /// </summary>
        /// <param name="terrain"></param>
        /// <param name="center"></param>
        /// <param name="radius"></param>
        /// <param name="layer"></param>
        /// <param name="count"></param>
        private void InternalSetDetail(Vector3 center, float radius, int layer, int count, bool regesterUndo)
        {
            Vector3 leftDown = new Vector3(center.x - radius, 0, center.z - radius);
            Terrain terrain  = Utility.SendRayDown(leftDown, LayerMask.GetMask("Terrain")).collider?.GetComponent <Terrain>();

            if (terrain != null)
            {
                // 获取数据
                TerrainData terrainData = terrain.terrainData;
                int         mapRadius   = (int)(radius / terrainData.size.x * terrainData.detailResolution);
                Vector2Int  mapIndex    = TerrainUtility.GetDetialMapIndex(terrain, leftDown);
                int[,] detailMap = TerrainUtility.GetDetailLayer(terrain, mapIndex.x, mapIndex.y, 2 * mapRadius, 2 * mapRadius, layer);

                if (regesterUndo)
                {
                    DetialCmdData detialCmdData = new DetialCmdData(terrain, mapIndex, layer, detailMap);
                    RegisterUndo(new DetialCmd(detialCmdData));
                }

                // 修改数据
                ChangeDetailMap(detailMap, count);

                // 设置数据
                TerrainUtility.SetDetailLayer(terrain, detailMap, mapIndex.x, mapIndex.y, layer);
            }
        }
Exemple #2
0
 public void Undo(RuntimeTerrainEditor t)
 {
     TerrainUtility.SetDetailLayer(cmd.terrain, cmd.detailMap, cmd.startMapIndex.x, cmd.startMapIndex.y, cmd.layer);
 }