Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

AtlasImage is a graphic component use SpriteAtlas for uGUI. In addition, add useful sprite selector and border editor to the inspector.

License

NotificationsYou must be signed in to change notification settings

mob-sakai/AtlasImage

Repository files navigation

A graphic component useSpriteAtlas for uGUI.
In addition, add usefulsprite picker andborder editor to the inspector.

image

PRs Welcome

<<Description |Demo |Installation |Usage |Development Note |Change log >>





Description

Are you still fatigued withSpriteAtlas andImage?

  • No interface for SpriteAtlas
    • Support onlySprite.
    • We pack sprites for drawing call optimization, but there is no interface.
  • Confusing sprite picker
    • You can select sprites using object picker.
    • Opject picker displaysall sprites in the project...
    • Do you know which sprite is included in atlas?
  • Troublesome border setting
    • You can edit sprite border using sprite editor.
    • It is troublesome to select a sprite, open a sprite editor, and edit the border.

AtlasImage provides useful feature to useSpriteAtlas for UI!

Sprite for renderring can be changed with a SpriteAtlas or a sprite name.

atlasImage.spriteAtlas=Resources.Load("A SpriteAtlas name")asSpriteAtlas;atlasImage.spriteName="A sprite name in the SpriteAtlas";

In the inspector, sprite picker displays only sprites in the SpriteAtlas.

image

You can edit the border in the preview window.

image

ConvertImage toAtlasImage by context menu.





Demo





Installation

Requirement

  • Unity 2017.1 or later

(For Unity 2018.3 or later) Using OpenUPM

This package is available onOpenUPM.
You can install it viaopenupm-cli.

openupm add com.coffee.atlas-image

(For Unity 2018.3 or later) Using Git

Find the manifest.json file in the Packages folder of your project and add a line todependencies field.

  • Major version:
    "com.coffee.atlas-image": "https://github.com/mob-sakai/AtlasImage.git"

To update the package, change suffix#{version} to the target version.

  • e.g."com.coffee.atlas-image": "https://github.com/mob-sakai/AtlasImage.git#1.0.0",

Or, useUpmGitExtension to install and update the package.

For Unity 2018.2 or earlier

  1. Download a source code zip file fromReleases page
  2. Extract it
  3. Import it into the following directory in your Unity project
    • Packages (It works as an embedded package. For Unity 2018.1 or later)
    • Assets (Legacy way. For Unity 2017.1 or later)





Usage

  1. Enable SpriteAtlas. Go toEdit > Project Settings > Editor, and change the sprite packing mode from Disabled to either:
    • Enabled for Builds, when you want to use packing for builds only and not when in Play mode.
    • Always Enabled when you want the packed Sprite to resolve its texture from the Sprite Atlas during Play mode, but resolve its texture from the original Texture during Edit mode.
  2. AddAtlasImage component instead ofImage component fromAdd Component in inspector.
  3. Select theSpriteAtlas by dropdown manu, and select the sprite with object piker.
  4. Enjoy!





Development Note

How to work?

  1. Pack atlas on open select sprite window.
staticvoidPackAtlas(SpriteAtlasatlas){System.Type.GetType("UnityEditor.U2D.SpriteAtlasUtility, UnityEditor").GetMethod("PackAtlases",BindingFlags.NonPublic|BindingFlags.Static).Invoke(null,newobject[]{new[]{atlas},EditorUserBuildSettings.activeBuildTarget});}
  1. Add label<atlas-guid> to sprites in atlas.
staticstringSetAtlasLabelToSprites(SpriteAtlasatlas,booladd){// GUID for the atlas.string[]atlasLabel={AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(atlas))};// Packed sprites in atlas.SerializedPropertyspPackedSprites=newSerializedObject(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(varsinsprites){string[]newLabels=add?AssetDatabase.GetLabels(s).Union(atlasLabel).ToArray():AssetDatabase.GetLabels(s).Except(atlasLabel).ToArray();AssetDatabase.SetLabels(s,newLabels);}returnatlasLabel[0];}
  1. Open the object picker with label. It filter the sprites to display.
EditorGUIUtility.ShowObjectPicker<Sprite>(atlas.GetSprite(spriteName),false,"l:"+atlasLabel,controlID);
  1. On closed the object picker, remove label from sprites in atlas.





Contributing

Issues

Issues are very valuable to this project.

  • Ideas are a valuable source of contributions others can make
  • Problems show where this project is lacking
  • With a question you show where contributors can improve the user experience

Pull Requests

Pull requests are, a great way to get your ideas into this repository.
Seesandbox/README.md.

Support

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. :)






License

  • MIT

Author

See Also

About

AtlasImage is a graphic component use SpriteAtlas for uGUI. In addition, add useful sprite selector and border editor to the inspector.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp