public override void SetInfo(BaseInfo baseInfo)
    {
        TerrainTextureInfo info = (TerrainTextureInfo)baseInfo;

        base.SetInfo(info);
        iconPath    = info.iconPath;
        iconName    = info.iconName;
        terrainType = info.terrainType;
    }
Exemple #2
0
        private void DrawEditTerrainTexturesInspector()
        {
            VegetationSystemPro vegetationSystemPro = _terrainSystemPro.VegetationSystemPro;

            GUILayout.BeginVertical("box");

            if (vegetationSystemPro.VegetationPackageProList.Count == 0)
            {
                EditorGUILayout.HelpBox("You need to add a biome/vegetation package in order to edit splatmap rules.", MessageType.Warning);
                GUILayout.EndVertical();
                return;
            }


            EditorGUILayout.LabelField("Select biome/vegetation package", LabelStyle);
            string[] packageNameList = new string[vegetationSystemPro.VegetationPackageProList.Count];
            for (int i = 0; i <= vegetationSystemPro.VegetationPackageProList.Count - 1; i++)
            {
                if (vegetationSystemPro.VegetationPackageProList[i])
                {
                    packageNameList[i] = (i + 1).ToString() + " " +
                                         vegetationSystemPro.VegetationPackageProList[i].PackageName;
                }
                else
                {
                    packageNameList[i] = "Not found";
                }
            }

            _terrainSystemPro.VegetationPackageIndex = EditorGUILayout.Popup("Selected vegetation package",
                                                                             _terrainSystemPro.VegetationPackageIndex, packageNameList);

            VegetationPackagePro vegetationPackagePro =
                _terrainSystemPro.VegetationSystemPro.VegetationPackageProList[
                    _terrainSystemPro.VegetationPackageIndex];

            GUILayout.BeginVertical("box");
            if (GUILayout.Button("Read textures from terrain"))
            {
                _terrainSystemPro.GetSplatPrototypesFromTerrain(vegetationPackagePro);
                EditorUtility.SetDirty(vegetationPackagePro);
            }
            EditorGUILayout.HelpBox("This will replace textures in the VegetationPackage/biome with the textures from an added Unity Terrain", MessageType.Info);
            GUILayout.EndVertical();

            GUILayout.BeginVertical("box");
            if (GUILayout.Button("Apply textures to terrain"))
            {
                _terrainSystemPro.SetSplatPrototypes(vegetationPackagePro);
            }
            EditorGUILayout.HelpBox("This will replace textures on unity terrains with the textures in the selected biome.", MessageType.Info);
            GUILayout.EndVertical();

            if (vegetationPackagePro.TerrainTextureCount > 0)
            {
                if (_terrainSystemPro.VegetationPackageTextureIndex > vegetationPackagePro.TerrainTextureCount)
                {
                    _terrainSystemPro.VegetationPackageTextureIndex = 0;
                }

                GUILayout.BeginVertical("box");
                EditorGUILayout.LabelField("Select terrain texture", LabelStyle);
                GUIContent[] textureImageButtons =
                    new GUIContent[vegetationPackagePro.TerrainTextureSettingsList.Count];

                for (int i = 0; i <= vegetationPackagePro.TerrainTextureSettingsList.Count - 1; i++)
                {
                    textureImageButtons[i] = new GUIContent
                    {
                        image = AssetPreviewCache.GetAssetPreview(
                            vegetationPackagePro.TerrainTextureList[i].Texture)
                    };
                }

                int imageWidth = 80;
                int columns    = Mathf.FloorToInt((EditorGUIUtility.currentViewWidth - 50) / imageWidth);
                int rows       = Mathf.CeilToInt((float)textureImageButtons.Length / columns);
                int gridHeight = (rows) * imageWidth;

                _terrainSystemPro.VegetationPackageTextureIndex = GUILayout.SelectionGrid(
                    _terrainSystemPro.VegetationPackageTextureIndex, textureImageButtons, columns,
                    GUILayout.MaxWidth(columns * imageWidth), GUILayout.MaxHeight(gridHeight));
                GUILayout.EndVertical();


                TerrainTextureInfo terrainTextureInfo = vegetationPackagePro.TerrainTextureList[_terrainSystemPro.VegetationPackageTextureIndex];

                EditorGUI.BeginChangeCheck();
                GUILayout.BeginVertical("box");
                EditorGUILayout.LabelField("Terrain texture layer " + (_terrainSystemPro.VegetationPackageTextureIndex + 1), LabelStyle);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(new GUIContent("Texture", ""), LabelStyle, GUILayout.Width(64));
                EditorGUILayout.LabelField(new GUIContent("Normal", ""), LabelStyle, GUILayout.Width(64));
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                terrainTextureInfo.Texture        = (Texture2D)EditorGUILayout.ObjectField(terrainTextureInfo.Texture, typeof(Texture2D), false, GUILayout.Height(64), GUILayout.Width(64));
                terrainTextureInfo.TextureNormals = (Texture2D)EditorGUILayout.ObjectField(terrainTextureInfo.TextureNormals, typeof(Texture2D), false, GUILayout.Height(64), GUILayout.Width(64));
                EditorGUILayout.EndHorizontal();

                Rect space = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(18));
                terrainTextureInfo.TileSize = EditorGUI.Vector2Field(space, "Texture tile size", terrainTextureInfo.TileSize);

                if (terrainTextureInfo.TileSize.x < 1 || terrainTextureInfo.TileSize.y < 1)
                {
                    EditorGUILayout.HelpBox("Texture tile size should be set for a higher value, normal is around 15.", MessageType.Warning);
                }

                GUILayout.EndVertical();
                if (EditorGUI.EndChangeCheck())
                {
                    AssetUtility.SetTextureReadable(terrainTextureInfo.Texture, false);
                    AssetUtility.SetTextureReadable(terrainTextureInfo.TextureNormals, true);
                    EditorUtility.SetDirty(vegetationPackagePro);
                }
            }
            GUILayout.EndVertical();
        }
Exemple #3
0
        public void SetSplatPrototypes(VegetationPackagePro vegetationPackage)
        {
#if UNITY_2018_3_OR_NEWER
            TerrainLayer[] terrainLayers = new TerrainLayer[vegetationPackage.TerrainTextureList.Count];
            for (int i = 0; i <= vegetationPackage.TerrainTextureList.Count - 1; i++)
            {
                TerrainTextureInfo terrainTextureInfo = vegetationPackage.TerrainTextureList[i];
                TerrainLayer       terrainLayer       = terrainTextureInfo.TerrainLayer;

                if (terrainLayer == null)
                {
                    terrainLayer = new TerrainLayer
                    {
                        diffuseTexture   = terrainTextureInfo.Texture,
                        normalMapTexture = terrainTextureInfo.TextureNormals,
                        tileSize         = terrainTextureInfo.TileSize,
                        tileOffset       = terrainTextureInfo.Offset
                    };
#if UNITY_EDITOR
                    if (!Application.isPlaying)
                    {
                        terrainLayer = SaveTerrainLayer(terrainLayer, vegetationPackage);
                    }
                    EditorUtility.SetDirty(vegetationPackage);
#endif
                    terrainTextureInfo.TerrainLayer = terrainLayer;
                }
                else
                {
                    terrainLayer.diffuseTexture   = terrainTextureInfo.Texture;
                    terrainLayer.normalMapTexture = terrainTextureInfo.TextureNormals;
                    terrainLayer.tileSize         = terrainTextureInfo.TileSize;
                    terrainLayer.tileOffset       = terrainTextureInfo.Offset;
#if UNITY_EDITOR
                    EditorUtility.SetDirty(terrainLayer);
#endif
                }
                terrainLayers[i] = terrainLayer;
            }

            for (int i = 0; i <= VegetationSystemPro.VegetationStudioTerrainList.Count - 1; i++)
            {
                IVegetationStudioTerrain iVegetationStudioTerrain = VegetationSystemPro.VegetationStudioTerrainList[i];
                if (iVegetationStudioTerrain.HasTerrainTextures())
                {
                    iVegetationStudioTerrain.SetTerrainLayers(terrainLayers);
                }
            }
#else
            SplatPrototype[] splatPrototypes = new SplatPrototype[vegetationPackage.TerrainTextureList.Count];
            for (int i = 0; i <= vegetationPackage.TerrainTextureList.Count - 1; i++)
            {
                TerrainTextureInfo terrainTextureInfo = vegetationPackage.TerrainTextureList[i];

                SplatPrototype splatPrototype = new SplatPrototype
                {
                    texture    = terrainTextureInfo.Texture,
                    normalMap  = terrainTextureInfo.TextureNormals,
                    tileSize   = terrainTextureInfo.TileSize,
                    tileOffset = terrainTextureInfo.Offset
                };
                splatPrototypes[i] = splatPrototype;
            }

            for (int i = 0; i <= VegetationSystemPro.VegetationStudioTerrainList.Count - 1; i++)
            {
                IVegetationStudioTerrain iVegetationStudioTerrain = VegetationSystemPro.VegetationStudioTerrainList[i];
                if (iVegetationStudioTerrain.HasTerrainTextures())
                {
                    iVegetationStudioTerrain.SetSplatPrototypes(splatPrototypes);
                }
            }
#endif
        }