AtlasImage is a graphic component use SpriteAtlas for uGUI. In addition, add useful sprite selector and border editor to the inspector.
A graphic component use SpriteAtlas
for uGUI.
In addition, add useful sprite picker and border editor to the inspector.
<< Description | Demo | Installation | Usage | Development Note | Change log >>
Are you still fatigued with SpriteAtlas
and Image
?
Sprite
.AtlasImage
provides useful feature to use SpriteAtlas
for UI!
atlasImage.spriteAtlas = Resources.Load("A SpriteAtlas name") as SpriteAtlas;
atlasImage.spriteName = "A sprite name in the SpriteAtlas";
Image
to AtlasImage
by context menu.This package is available on OpenUPM.
You can install it via openupm-cli.
openupm add com.coffee.atlas-image
Find the manifest.json file in the Packages folder of your project and add a line to dependencies
field.
"com.coffee.atlas-image": "https://github.com/mob-sakai/AtlasImage.git"
To update the package, change suffix #{version}
to the target version.
"com.coffee.atlas-image": "https://github.com/mob-sakai/AtlasImage.git#1.0.0",
Or, use UpmGitExtension to install and update the package.
Packages
(It works as an embedded package. For Unity 2018.1 or later)Assets
(Legacy way. For Unity 2017.1 or later)Edit > Project Settings > Editor
, and change the sprite packing mode from Disabled to either:
AtlasImage
component instead of Image
component from Add Component
in inspector.SpriteAtlas
by dropdown manu, and select the sprite with object piker.static void PackAtlas(SpriteAtlas atlas)
{
System.Type
.GetType("UnityEditor.U2D.SpriteAtlasUtility, UnityEditor")
.GetMethod("PackAtlases", BindingFlags.NonPublic | BindingFlags.Static)
.Invoke(null, new object[]{ new []{ atlas }, EditorUserBuildSettings.activeBuildTarget });
}
<atlas-guid>
to sprites in atlas.static string SetAtlasLabelToSprites(SpriteAtlas atlas, bool add)
{
// GUID for the atlas.
string[] atlasLabel = { AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(atlas)) };
// Packed sprites in atlas.
SerializedProperty spPackedSprites = new SerializedObject(atlas).FindProperty("m_PackedSprites");
Sprite[] sprites = Enumerable.Range(0, spPackedSprites.arraySize)
.Select(index => spPackedSprites.GetArrayElementAtIndex(index).objectReferenceValue)
.OfType<Sprite>()
.ToArray();
// Add/remove label to sprites.
foreach (var s in sprites)
{
string[] newLabels = add
? AssetDatabase.GetLabels(s).Union(atlasLabel).ToArray()
: AssetDatabase.GetLabels(s).Except(atlasLabel).ToArray();
AssetDatabase.SetLabels(s, newLabels);
}
return atlasLabel[0];
}
EditorGUIUtility.ShowObjectPicker<Sprite>(atlas.GetSprite(spriteName), false, "l:" + atlasLabel, controlID);
Issues are very valuable to this project.
Pull requests are, a great way to get your ideas into this repository.
See sandbox/README.md.
This is an open source project that I am developing in my spare time.
If you like it, please support me.
With your support, I can spend more time on development. :)