예제 #1
0
        private SpriteEntry ExtractSprite(AtlasTexture atlas, string identifier)
        {
            if (atlas.Texture == null)
            {
                return(null);
            }

            var sd = atlas.GetSpriteData(identifier);

            if (sd == null)
            {
                return(null);
            }

            var se = ExtractSprite(sd, atlas.Texture as Texture2D);

            return(se);
        }
예제 #2
0
        public void Apply()
        {
            if (targetImage == null)
            {
                targetImage = UnityUtility.GetComponent <Image>(gameObject);
            }

            if (targetImage != null && atlas != null)
            {
                var spriteData = atlas.GetSpriteData(spriteGuid);

                if (spriteData != null)
                {
                    spriteName = spriteData.name;
                }

                Sprite = string.IsNullOrEmpty(spriteName) ? null : atlas.GetSprite(spriteName);

                targetImage.sprite = Sprite;
            }
        }
예제 #3
0
        public void CustomInspector()
        {
            EditorLayoutTools.SetLabelWidth(80f);

            var sprite = (atlas != null) ? atlas.GetSpriteData(EditorAtlasPrefs.selectedSprite) : null;

            EditorGUILayout.Separator();

            if (atlas.Texture != null)
            {
                if (sprite == null && atlas.Sprites.Count > 0)
                {
                    string spriteName = EditorAtlasPrefs.selectedSprite;

                    if (!string.IsNullOrEmpty(spriteName))
                    {
                        sprite = atlas.GetSpriteData(spriteName);
                    }

                    if (sprite == null)
                    {
                        sprite = atlas.Sprites[0];
                    }
                }

                if (sprite != null)
                {
                    var tex = atlas.Texture as Texture2D;

                    if (tex != null)
                    {
                        EditorGUILayout.Separator();

                        DrawAdvancedSpriteField(atlas, sprite.name);

                        EditorGUILayout.Separator();

                        EditorLayoutTools.DrawContentTitle("Sprite Size");

                        using (new ContentsScope())
                        {
                            EditorLayoutTools.IntRangeField(null, "Width", "Height", sprite.width, sprite.height, false);
                        }

                        EditorLayoutTools.DrawContentTitle("Sprite Border");

                        using (new ContentsScope())
                        {
                            GUI.changed = false;

                            var borderA = EditorLayoutTools.DelayedIntRangeField(null, "Left", "Right", sprite.borderLeft, sprite.borderRight);
                            var borderB = EditorLayoutTools.DelayedIntRangeField(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop);

                            if (GUI.changed)
                            {
                                UnityEditorUtility.RegisterUndo("Atlas Change", atlas);

                                sprite.borderLeft   = borderA.x;
                                sprite.borderRight  = borderA.y;
                                sprite.borderBottom = borderB.x;
                                sprite.borderTop    = borderB.y;

                                atlas.CacheClear();
                            }
                        }

                        GUILayout.Space(2f);

                        using (new EditorGUILayout.HorizontalScope())
                        {
                            GUILayout.FlexibleSpace();

                            if (GUILayout.Button("Update"))
                            {
                                UnityEditorUtility.SaveAsset(atlas);
                            }
                        }
                    }
                }
            }
        }