Giter VIP home page Giter VIP logo

atlasimage's Introduction

Atlas Image

A graphic component use SpriteAtlas for uGUI.
In addition, add useful sprite picker and border editor to the inspector.

image

PRs Welcome

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





Description

Are you still fatigued with SpriteAtlas and Image?

  • No interface for SpriteAtlas
    • Support only Sprite.
    • We pack sprites for drawing call optimization, but there is no interface.
  • Confusing sprite picker
    • You can select sprites using object picker.
    • Opject picker displays all 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 use SpriteAtlas for UI!

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

atlasImage.spriteAtlas = Resources.Load("A SpriteAtlas name") as SpriteAtlas;
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

Convert Image to AtlasImage by context menu.





Demo





Installation

Requirement

  • Unity 2017.1 or later

(For Unity 2018.3 or later) Using OpenUPM

This package is available on OpenUPM.
You can install it via openupm-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 to dependencies 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, use UpmGitExtension to install and update the package.

For Unity 2018.2 or earlier

  1. Download a source code zip file from Releases 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 to Edit > 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. Add AtlasImage component instead of Image component from Add Component in inspector.
  3. Select the SpriteAtlas 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.
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 });
}
  1. Add label <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];
}
  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.
See sandbox/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

atlasimage's People

Contributors

mob-sakai avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

atlasimage's Issues

Package renaming request

Hi @mob-sakai,

Favo from OpenUPM - a platform collects open-source UPM packages. First of all, thanks for creating this awesome open-source package. I am writing to you because OpenUPM is preparing to comply with Unity's Terms of Services (TOS) Updates. Your package is available on our platform, and I need your help to make some changes.

According to the Unity Package Manager Naming Convention, the package name should use reverse domain name notation, at least 3 sections joined by a dot: tld.org-name.package-name. For example com.littlebigfun.addressable-importer.

  • tld is the top-level domain, like com, org and so on. If you're not sure about what to use, please use com.
  • org-name is your organization name. With tld together it makes sure the organization name is globally unique to its registered owner. You should avoid using a tld and org-name combination that may be confusing to users, like com.unity or com.github.
  • package-name is your package name.

Your package name is AtlasImage. I recommend you to update it to comply with the naming convention by,

  • change the package name in package.json.
  • bump the version field of package.json.
  • create a Git tag.

Please reply to me if you've made the change, I will update the OpenUPM side to make it live.

If you do not respond to the issue, It will be closed by the end of Jan 2021, and your package will be removed from our platform. Please notice that Unity Package Guiding Principles & Guidelines do not apply to you when you host Packages on GitHub for Unity users to download and put the Packages in their projects, as long as the hosted Package does not, directly or indirectly, leverage the Unity Editor as a marketing or distribution platform. Thus, you don't have to change anything if you don't intend to publish the package on a scoped registry (like OpenUPM).

Sorry for the inconvenience, feel free to discuss with me if you have any questions.

BR
Favo

Is it a bug? Is it misused?

Hi.
Using your AtlasImage, I created two AtlasImages in samplescene.
Then, the following error is occurring. How should I fix it? Maybe it's a bug?

Could not extract GUID in text file Assets/Scenes/SampleScene.unity at line 404.
Could not extract GUID in text file Assets/Scenes/SampleScene.unity at line 864.
Broken text PPtr. GUID 00000000000000000000000000000000 fileID 2 is invalid!
Broken text PPtr. GUID 00000000000000000000000000000000 fileID 2 is invalid!

I use Unity 2019.4.14f.

1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.