Get List of Textures (or their names) used on Terrain?

I have a very similar question to the one that was asked over here:

My issue with the answer that was provided is it makes the assumption that my “Rock” layer will be in a fixed layer of the alphamap. This isn’t my case. I may have levels with 0, 1, or many “Rock” layers. I don’t want to have to constantly keep track of which textures are being used on each level. I’d like to write a simple editor script that keeps track of this for me.

Every time I save the file, I want my script to just get each of my terrains, check the textures used, and store in an array which alphamap layers are “Rock” or not based on the name of the texture.

So my question is - how do I programmatically get the names of the textures used on a given piece of terrain? This is happening in an Editor Script, if that helps. I figure it must be possible, because the Unity Editor keeps track of this (or am I mistaken in thinking that all the pieces of the Unity Editor were built using these same classes that we have access to?)

I have found it. The path to get from a Terrain to the Textures used on it is as follows:

  1. Terrain.terrainData is a TerrainData
  2. TerrainData.splatPrototypes is a SplatPrototype[]
  3. SplatPrototype.texture is a Texture2D
  4. And if you’d like the file name, they have a name property, or you can use ToString() on them.