/// <summary>
        /// 设置贴图
        /// </summary>
        /// <param name="center">中心点</param>
        /// <param name="radius">半径</param>
        /// <param name="index">layer索引</param>
        /// <param name="strength">力度</param>
        /// <param name="isMix">是否混合, 如果为false 则strength无效</param>
        private void InternalSetTexture(Vector3 center, float radius, int index, float strength, bool isMix, 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.alphamapResolution);
                Vector2Int  mapIndex    = TerrainUtility.GetAlphaMapIndex(terrain, leftDown);
                float[,,] alphaMap = TerrainUtility.GetAlphaMap(terrain, mapIndex.x, mapIndex.y, 2 * mapRadius, 2 * mapRadius);

                if (regesterUndo)
                {
                    TextureCmdData textureCmdData = new TextureCmdData(terrain, mapIndex, alphaMap);
                    RegisterUndo(new TextureCmd(textureCmdData));
                }

                // 修改数据
                if (isMix)
                {
                    ChangeAlphaMap(alphaMap, index, strength);
                }
                else
                {
                    ChangeAlphaMapNoMix(alphaMap, index);
                }

                // 设置数据
                TerrainUtility.SetAlphaMap(terrain, alphaMap, mapIndex.x, mapIndex.y);
            }
        }
        /// <summary>
        /// 设置贴图
        /// </summary>
        /// <param name="point"></param>
        /// <param name="index"></param>
        public void InternalSetTexture(Vector3 center, float radius, int index, float strength)
        {
            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.alphamapResolution);
                Vector2Int  mapIndex    = TerrainUtility.GetAlphaMapIndex(terrain, leftDown);
                float[,,] alphaMap = TerrainUtility.GetAlphaMap(terrain, mapIndex.x, mapIndex.y, 2 * mapRadius, 2 * mapRadius);

                // 修改数据
                ChangeAlphaMap(alphaMap, index, strength);

                // 设置数据
                TerrainUtility.SetAlphaMap(terrain, alphaMap, mapIndex.x, mapIndex.y);
            }
        }
예제 #3
0
 public void Undo(RuntimeTerrainEditor t)
 {
     TerrainUtility.SetAlphaMap(cmd.terrain, cmd.alphaMap, cmd.startMapIndex.x, cmd.startMapIndex.y);
 }