How to rename individual sprite slice without creating new fileID in meta file using code?
Hi guys, after sliced a sprite sheet, I noticed that if I rename each individual sprite slice manually in Unity, the 'fileIDToRecycleName' session of the meta file for that sprite will stay cool (only name changes, while the fileID remains the same). However, if I do it using code, the 'fileIDToRecycleName' session will expand, reassigning the new name to a new fileID. See below:
fileIDToRecycleName:
21300000: name_0
21300002: name_1
21300004: name_2
//if manually rename in unity the above will change to:
fileIDToRecycleName:
21300000: newname_0
21300002: newname_1
21300004: newname_2
//if rename in code then:
fileIDToRecycleName:
21300000: name_0
21300002: name_1
21300004: name_2
21300006: newname_0
21300008: newname_1
21300010: newname_2
My code is like this, similar to line 215-267 of https://github.com/eppz/Unity.Library.eppz_kit/blob/master/Editor/EPPZEditor_SliceRenamer.cs
...
// Locate asset, get meta.
path = AssetDatabase.GetAssetPath(texture);
textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
SpriteMetaData[] sliceMetaData = textureImporter.spritesheet;
// Naming loop.
for (i...)
{
string eachName = ...;
...
sliceMetaData[i].name = eachName;
}
// Save settings.
textureImporter.spritesheet = sliceMetaData;
EditorUtility.SetDirty(textureImporter);
textureImporter.SaveAndReimport();
// Reimport/refresh asset.
AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
I try to change line 16 to something like:
textureImporter.spritesheet[].name = slice$$anonymous$$etaData[].name;
What is the right way of doing this? And will it work?
Or, is it possible to use Packer.GetAtlasDataForSprite and atlasName variable to rename the slices without creating new fileID?
this can simply change the sliced sprite, but the resources which use the sliced sprite with old name will not change at same time.
Like a prefab A, use sliced sprite named [a_01], but you change it into [a_001],it's will not show the right sliced sprite.
I wonder if there's API work like Sprite Editor, change sliced sprite's name, and click Apply button, and deal with dependencies with Unity itself.