using System.Collections; using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; // Copyright: Jokerminator Ink. // License: Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) public class TerrainLocationsTexturesArrays : MonoBehaviour { public string st_SaveFolder = "LocationsTexturesArrays"; public string st_SlopeHighMedLowPrefix = "SlopeHighMedLow"; public string st_RiverbedVegetationErosionPrefix = "RiverbedVegetationErosion"; private Texture2D t2d_slopeHighMediumLowLocations; private Texture2D t2d_riverbedVegetationErosionLocations; private Texture2D[] t2d_locationsImages = new Texture2D[2]; private void Start( ) { CreateLocationsTexturesArrays( ); } private void CreateLocationsTexturesArrays( ) { int iTexturePostfixIndex1 = 0; int iTexturePostfixIndex2 = 0; for ( int postfixIndex1 = 0; postfixIndex1 <= 15; postfixIndex1++ ) { for ( int postfixIndex2 = 0; postfixIndex2 <= 15; postfixIndex2++ ) { iTexturePostfixIndex1 = postfixIndex2; //flip and invert index to Gimps format iTexturePostfixIndex2 = Mathf.Abs( postfixIndex1 - 15 ); string stTexturePostfixIndex1 = iTexturePostfixIndex1.ToString(); string stTexturePostfixIndex2 = iTexturePostfixIndex2.ToString( ); if ( iTexturePostfixIndex1 < 10 ) { stTexturePostfixIndex1 = "0" + iTexturePostfixIndex1; } if ( iTexturePostfixIndex2 < 10 ) { stTexturePostfixIndex2 = "0" + iTexturePostfixIndex2; } t2d_slopeHighMediumLowLocations = Resources.Load( st_SlopeHighMedLowPrefix + Path.AltDirectorySeparatorChar + st_SlopeHighMedLowPrefix + "-" + stTexturePostfixIndex1 + "-" + stTexturePostfixIndex2 ) as Texture2D; t2d_riverbedVegetationErosionLocations = Resources.Load( st_RiverbedVegetationErosionPrefix + Path.AltDirectorySeparatorChar + st_RiverbedVegetationErosionPrefix + "-" + stTexturePostfixIndex1 + "-" + stTexturePostfixIndex2 ) as Texture2D; t2d_locationsImages[0] = t2d_slopeHighMediumLowLocations; t2d_locationsImages[1] = t2d_riverbedVegetationErosionLocations; string stTextureArrayPostfixIndex1 = postfixIndex1.ToString( ); string stTextureArrayPostfixIndex2 = postfixIndex2.ToString( ); if ( postfixIndex1 < 10 ) { stTextureArrayPostfixIndex1 = "0" + postfixIndex1; } if ( postfixIndex2 < 10 ) { stTextureArrayPostfixIndex2 = "0" + postfixIndex2; } CreateTextureArray( t2d_locationsImages, TextureWrapMode.Clamp, st_SaveFolder, "LocationsT2DArray_" + stTextureArrayPostfixIndex1 + "_" + stTextureArrayPostfixIndex2 ); } } } private void CreateTextureArray( Texture2D[] t2dImages, TextureWrapMode twmImages, string stSaveFolder, string stImagesArrayName ) { Texture2DArray t2dImagesArray = new Texture2DArray( t2dImages[0].width, t2dImages[0].height, t2dImages.Length, TextureFormat.RGB24, false, true ); t2dImagesArray.filterMode = FilterMode.Bilinear; t2dImagesArray.wrapMode = twmImages; for ( int i = 0; i < t2dImages.Length; i++ ) { t2dImagesArray.SetPixels( t2dImages[i].GetPixels( 0 ), i, 0 ); } t2dImagesArray.Apply( ); AssetDatabase.CreateAsset( t2dImagesArray, "Assets" + Path.AltDirectorySeparatorChar + "Resources" + Path.AltDirectorySeparatorChar + stSaveFolder + Path.AltDirectorySeparatorChar + stImagesArrayName + ".asset" ); } }