void GUIUpdateTexture(Texture2D tex, int idx, Dictionary<string, int> names)
{
Map m = (Map)target;
string name = "MAP_TEX_"+idx;
names[name] = idx;
GUI.SetNextControlName(name);
Texture2D nextTex = (Texture2D)EditorGUILayout.ObjectField(
tex == specPlaceholderTexture ? null : tex,
typeof(Texture2D),
false,
GUILayout.Height(64),
GUILayout.Width(64)
);
GUI.SetNextControlName("");
if(tex != nextTex) {
if(tex == specPlaceholderTexture && nextTex == null) {
//ignore, no real change
} else {
//are we on the bonus item?
if(idx == m.TileSpecCount) {
//if so, add a new spec
RegisterUndo("Add Tile Spec");
m.AddTileSpec(nextTex);
} else {
//otherwise, just update
RegisterUndo("Change Tile Spec");
m.UpdateTileSpecAt(specSelectedSpec, nextTex);
}
if(nextTex != null) {
string path = AssetDatabase.GetAssetPath(nextTex);
TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
textureImporter.textureType = TextureImporterType.Advanced;
textureImporter.anisoLevel = 1;
textureImporter.filterMode = FilterMode.Bilinear;
textureImporter.maxTextureSize = 1024;
textureImporter.textureFormat = TextureImporterFormat.AutomaticCompressed;
textureImporter.mipmapEnabled = false;
textureImporter.isReadable = true;
AssetDatabase.ImportAsset(path);
}
}
}
}