Skip to content

Commit

Permalink
display texture without AssetImporter
Browse files Browse the repository at this point in the history
  • Loading branch information
vyshnovka committed Feb 26, 2024
1 parent 075b0a7 commit 56b29a2
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions Assets/Scripts/Managers/TerrainGenerationManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Linq;
using UnityEditor;
using UnityEngine;
using TerrainGeneration.Algorithms;
using Utils;
Expand Down Expand Up @@ -27,8 +26,6 @@ public class TerrainGenerationManager : MonoBehaviour
private Size selectedSize = Size._256;
private ColorScheme selectedColorScheme = ColorScheme.Grayscale;

private string texturePath;

public string SelectedAlgorithmTypeAsName
{
get => selectedAlgorithmType.ToString();
Expand All @@ -55,8 +52,6 @@ public int SelectedColorSchemeAsNumber

void Start()
{
texturePath = AssetDatabase.GetAssetPath(texture);

ResetTerrain();
}

Expand Down Expand Up @@ -98,9 +93,7 @@ private void GenerateTerrain()
private void ApplyTexture()
{
// Reimport texture with corresponding max size.
TextureImporter importer = AssetImporter.GetAtPath(texturePath) as TextureImporter;
importer.maxTextureSize = SelectedSizeAsNumber;
AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate);
texture.Reinitialize(SelectedSizeAsNumber, SelectedSizeAsNumber);

for (int x = 0; x < SelectedSizeAsNumber; x++)
{
Expand Down Expand Up @@ -174,7 +167,7 @@ private void PaintTerrain()
private void ResetTerrain()
{
terrain.terrainData.heightmapResolution = SelectedSizeAsNumber;
AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate);
texture.Reinitialize(SelectedSizeAsNumber, SelectedSizeAsNumber);
TerrainSizeChanged?.Invoke(SelectedSizeAsNumber);
}
#endregion
Expand Down

0 comments on commit 56b29a2

Please sign in to comment.