{"id":13786134,"url":"https://github.com/baba-s/sprite-atlas-name-creator","last_synced_at":"2025-04-12T02:52:25.763Z","repository":{"id":110295030,"uuid":"124730750","full_name":"baba-s/sprite-atlas-name-creator","owner":"baba-s","description":"Editor extension to create a class that can get sprite included in SpriteAtlas by property instead of string.","archived":false,"fork":false,"pushed_at":"2018-03-11T08:54:19.000Z","size":204,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-25T22:36:26.777Z","etag":null,"topics":["ugui","unity","unity-editor","unity3d"],"latest_commit_sha":null,"homepage":"http://baba-s.hatenablog.com/entry/2018/03/16/085900","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/baba-s.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-03-11T06:42:30.000Z","updated_at":"2020-10-06T18:38:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"96962568-f10a-4201-9aae-3e09eb9f7079","html_url":"https://github.com/baba-s/sprite-atlas-name-creator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baba-s%2Fsprite-atlas-name-creator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baba-s%2Fsprite-atlas-name-creator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baba-s%2Fsprite-atlas-name-creator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baba-s%2Fsprite-atlas-name-creator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baba-s","download_url":"https://codeload.github.com/baba-s/sprite-atlas-name-creator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248509725,"owners_count":21116104,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ugui","unity","unity-editor","unity3d"],"created_at":"2024-08-03T19:01:10.215Z","updated_at":"2025-04-12T02:52:25.742Z","avatar_url":"https://github.com/baba-s.png","language":"C#","funding_links":[],"categories":["UI Script"],"sub_categories":[],"readme":"[日本語の Readme はこちら](https://github.com/baba-s/sprite-atlas-name-creator/blob/master/README_JP.md)  \n\n# SpriteAtlasNameCreator\n\nEditor extension to create a class that can get sprite included in SpriteAtlas by property instead of string.\n\n# Feature\n\n## Get a sprite at properties.\n\n```cs\npublic class Example : MonoBehaviour\n{\n    public SpriteAtlas m_atlas;\n    public Image m_image;\n\n    private void Awake()\n    {\n        m_image.sprite = m_atlas.GetSprite( \"button_blue\" );\n    }\n}\n```\n\nFor example, if you want to set a sprite included in SpriteAtlas to Image.sprite,  \nWe use SpriteAtlas.GetSprite( \"hoge\" ),  \nSince this method specifies the sprite name as a character string,  \nThere is a problem of mistyping the input of the sprite name.  \n\n```cs\npublic class Example : MonoBehaviour\n{\n    public CommonAtlas m_atlas;\n    public Image m_image;\n\n    private void Awake()\n    {\n        m_image.sprite = m_atlas.button_blue;\n    }\n}\n```\n\nBy creating a dedicated class using \"SpriteAtlasNameCreator\",  \nAs mention above, you can get sprites as properties,  \nIt is possible to prevent mistyping of sprite name.  \n\n## Acquire a sprite by format specification.\n\n```cs\npublic class Example : MonoBehaviour\n{\n    public SpriteAtlas m_atlas;\n    public Image m_image;\n\n    public void SetImage( PARAM_TYPE paramType )\n    {\n        var name = \"icon_\" + paramType.ToString();\n        m_image.sprite = m_atlas.GetSprite( name );\n    }\n}\n```\n\nFor example, If you want to change sprites with PARAM_TYPE, \nAlthough it may be described as above,  \n\n```cs\npublic class Example : MonoBehaviour\n{\n    public CommonAtlas m_atlas;\n    public Image m_image;\n\n    public void SetImage( PARAM_TYPE paramType )\n    {\n        m_image.sprite = m_atlas.get_icon( paramType.ToString() );\n    }\n}\n```\n\nYou can also get a sprite like this way.  \n\n## Extend functionality with partial class.\n\n```cs\n[Serializable]\npublic partial class CommonAtlas : AtlasBase\n{\n    ...\n}\n```\n\nSince the created class is a partial class,  \n\n```cs\npublic partial class CommonAtlas : AtlasBase\n{\n    public Sprite GetParamIcon( PARAM_TYPE paramType )\n    {\n        return m_atlas.get_icon( paramType.ToString() );\n    }\n}\n```\n\nBy defining frequently used relationships in another file,  \n\n```cs\npublic class Example : MonoBehaviour\n{\n    public CommonAtlas m_atlas;\n    public Image m_image;\n\n    public void SetImage( PARAM_TYPE paramType )\n    {\n        m_image.sprite = m_atlas.GetParamIcon( paramType );\n    }\n}\n```\n\nYou can get sprites more intuitively.  \n\n# Version\n\n- Unity 2017.3.0f3\n\n# Install\n\n1. Go to the following page and download \"SpriteAtlasNameCreator.unitypackage\".  \nhttps://github.com/baba-s/sprite-atlas-name-creator/blob/master/SpriteAtlasNameCreator.unitypackage?raw=true\n2. Import the downloaded \"SpriteAtlasNameCreator.unitypackage\" into the Unity project.  \n\n# Usage\n\n![](https://cdn-ak.f.st-hatena.com/images/fotolife/b/baba_s/20180311/20180311164028.png)\n\nAs mentioned above, if SpriteAtlas exists in the Unity project,  \n\n![](https://cdn-ak.f.st-hatena.com/images/fotolife/b/baba_s/20180311/20180311164104.png)\n\nWhen you select \"Kogane \u003e Create \u003e Sprite Atlas Name\" in the Unity menu,  \n\n![](https://cdn-ak.f.st-hatena.com/images/fotolife/b/baba_s/20180311/20180311164128.png)\n\nA file \"SpriteAtlasName\" is created,   \n\n```cs\nusing System;\nusing UnityEngine;\nusing UnityEngine.U2D;\n\nnamespace KoganeUnityLib.UI\n{\n    [Serializable]\n    public partial class CommonAtlas : AtlasBase\n    {\n        [SerializeField] private SpriteAtlas m_atlas = null;\n        \n        public const string _button_blue = \"button_blue\";\n        public const string _button_yellow = \"button_yellow\";\n        public const string _button_green = \"button_green\";\n        public const string _check_off = \"check_off\";\n        public const string _check_on = \"check_on\";\n        \n        public Sprite button_blue { get { return m_atlas.GetSprite( _button_blue ); } }\n        public Sprite button_yellow { get { return m_atlas.GetSprite( _button_yellow ); } }\n        public Sprite button_green { get { return m_atlas.GetSprite( _button_green ); } }\n        public Sprite check_off { get { return m_atlas.GetSprite( _check_off ); } }\n        public Sprite check_on { get { return m_atlas.GetSprite( _check_on ); } }\n        \n        /// \u003csummary\u003e\"button_{0}\"\u003c/summary\u003e\n        public Sprite get_button( object arg0 ) { return m_atlas.GetSprite( string.Format( \"button_{0}\", arg0 ) ); }\n        /// \u003csummary\u003e\"{0}_{1}\"\u003c/summary\u003e\n        public Sprite get_( object arg0, object arg1 ) { return m_atlas.GetSprite( string.Format( \"{0}_{1}\", arg0, arg1 ) ); }\n        /// \u003csummary\u003e\"check_{0}\"\u003c/summary\u003e\n        public Sprite get_check( object arg0 ) { return m_atlas.GetSprite( string.Format( \"check_{0}\", arg0 ) ); }\n        \n        public CommonAtlas() {}\n        \n        public CommonAtlas( SpriteAtlas atlas ) { m_atlas = atlas; }\n        \n    }\n    \n    [Serializable]\n    public partial class SpaceAtlas : AtlasBase\n    {\n        [SerializeField] private SpriteAtlas m_atlas = null;\n        \n        public const string _dot_blue = \"dot_blue\";\n        public const string _dot_green = \"dot_green\";\n        public const string _dot_yellow = \"dot_yellow\";\n        \n        public Sprite dot_blue { get { return m_atlas.GetSprite( _dot_blue ); } }\n        public Sprite dot_green { get { return m_atlas.GetSprite( _dot_green ); } }\n        public Sprite dot_yellow { get { return m_atlas.GetSprite( _dot_yellow ); } }\n        \n        /// \u003csummary\u003e\"dot_{0}\"\u003c/summary\u003e\n        public Sprite get_dot( object arg0 ) { return m_atlas.GetSprite( string.Format( \"dot_{0}\", arg0 ) ); }\n        \n        public SpaceAtlas() {}\n        \n        public SpaceAtlas( SpriteAtlas atlas ) { m_atlas = atlas; }\n        \n    }\n    \n}\n```\n\nSuch a class is defined.  \nThen, For example, if you want to use a \"CommonAtlas\" class to obtain a sprite,  \n\n```cs\nusing KoganeUnityLib.UI;\nusing UnityEngine;\nusing UnityEngine.UI;\n\npublic class Example : MonoBehaviour\n{\n    public CommonAtlas m_commonAtlas;\n    public Image m_image;\n\n    private void Awake()\n    {\n        m_image.sprite = m_commonAtlas.button_blue;\n    }\n}\n```\n\nBy defining such a class,  \nAttach to the game object of the scene,  \n\n![](https://cdn-ak.f.st-hatena.com/images/fotolife/b/baba_s/20180311/20180311164840.png)\n\nSet SpriteAtlas with Inspector.  ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaba-s%2Fsprite-atlas-name-creator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaba-s%2Fsprite-atlas-name-creator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaba-s%2Fsprite-atlas-name-creator/lists"}