Skip to content

Instantly share code, notes, and snippets.

@talecrafter
Last active December 29, 2015 10:19
Show Gist options
  • Save talecrafter/7656531 to your computer and use it in GitHub Desktop.
Save talecrafter/7656531 to your computer and use it in GitHub Desktop.
Unity3D Editor Script that renames .atlas files on import to .atlas.txt. Put this script in an "Editor" subfolder.
using UnityEngine;
using UnityEditor;
using System.IO;
/// <summary>
/// editor script that renames imported .atlas files to .atlas.txt files
/// </summary>
public class AtlasFileRenamer : AssetPostprocessor
{
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
bool refresh = false;
foreach (string importedAssetPath in importedAssets)
{
string ext = Path.GetExtension(importedAssetPath);
// rename .atlas file to .atlas.txt
if (ext == ".atlas")
{
string newFileName = Path.ChangeExtension(importedAssetPath, ".atlas.txt");
// delete old file if it exists
AssetDatabase.DeleteAsset(newFileName);
// rename new file
FileUtil.MoveFileOrDirectory(importedAssetPath, newFileName);
// mark editor for refresh after all renamings
refresh = true;
}
}
if (refresh)
{
AssetDatabase.Refresh();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment