Exemple #1
0
 public static void ShowSelected()
 {
     if (EditorAtlasPrefs.atlas != null)
     {
         Show(delegate(string sel) { AtlasTextureInspector.SelectSprite(sel); });
     }
 }
Exemple #2
0
        private AtlasAction DrawSpriteList(SpriteInfo[] spriteInfos)
        {
            var action = AtlasAction.None;

            if (spriteInfos.Any())
            {
                EditorLayoutTools.DrawLabelWithBackground("Sprites", EditorLayoutTools.BackgroundColor, EditorLayoutTools.LabelColor);

                EditorGUILayout.Separator();

                using (new EditorGUILayout.VerticalScope())
                {
                    using (var scrollViewScope = new EditorGUILayout.ScrollViewScope(scrollPos))
                    {
                        var delete = false;

                        int index = 0;

                        foreach (var spriteInfo in spriteInfos)
                        {
                            ++index;

                            GUILayout.Space(-1f);

                            var highlight = (AtlasTextureInspector.instance != null) && (EditorAtlasPrefs.selectedSprite == spriteInfo.name);

                            GUI.backgroundColor = highlight ? Color.white : new Color(0.8f, 0.8f, 0.8f);

                            using (new EditorGUILayout.HorizontalScope(EditorLayoutTools.TextAreaStyle, GUILayout.MinHeight(20f)))
                            {
                                GUI.backgroundColor = Color.white;
                                GUILayout.Label(index.ToString(), GUILayout.Width(24f));

                                if (GUILayout.Button(spriteInfo.name, EditorStyles.label, GUILayout.Height(20f)))
                                {
                                    selection = spriteInfo.name;
                                }

                                if (spriteInfo.action == SpriteAction.Add)
                                {
                                    GUI.color = Color.green;
                                    GUILayout.Label("Add", GUILayout.Width(27f));
                                    GUI.color = defaultColor;
                                }
                                else if (spriteInfo.action == SpriteAction.Update)
                                {
                                    GUI.color = Color.cyan;
                                    GUILayout.Label("Update", GUILayout.Width(45f));
                                    GUI.color = defaultColor;
                                }
                                else
                                {
                                    if (deleteNames.Contains(spriteInfo.name))
                                    {
                                        GUI.backgroundColor = Color.red;

                                        if (GUILayout.Button("Delete", GUILayout.Width(60f)))
                                        {
                                            delete = true;
                                        }

                                        GUI.backgroundColor = Color.green;

                                        if (GUILayout.Button("X", GUILayout.Width(22f)))
                                        {
                                            deleteNames.Remove(spriteInfo.name);
                                            delete = false;
                                        }
                                    }
                                    else
                                    {
                                        if (GUILayout.Button("X", GUILayout.Width(22f)))
                                        {
                                            if (!deleteNames.Contains(spriteInfo.name))
                                            {
                                                deleteNames.Add(spriteInfo.name);
                                            }
                                        }
                                    }
                                }

                                GUILayout.Space(5f);

                                if (delete)
                                {
                                    action |= AtlasAction.Delete;
                                }
                            }
                        }

                        scrollPos = scrollViewScope.scrollPosition;
                    }
                }
            }

            if (EditorAtlasPrefs.atlas != null && !string.IsNullOrEmpty(selection))
            {
                AtlasTextureInspector.SelectSprite(selection);
                selection = null;
            }

            return(action);
        }