Пример #1
0
    void OnGUI()
    {
        EditorGUILayout.BeginVertical();

        float posX = 10;
        float posY = 10;

        Rect rect = new Rect(posX, posY, 500, 20);

        uiAtlas = EditorGUI.ObjectField(rect, "Atlas", uiAtlas, typeof(UIAtlas), false) as UIAtlas;

        if (uiAtlas)
        {
            Dictionary <string, Sprite> cur = uiAtlas.GetSprites();
            foreach (var sprite in cur.Values)
            {
                if (!sprites.ContainsKey(sprite.name))
                {
                    sprites.Add(sprite.name, new SpriteData(sprite.name, sprite));
                }
            }

            if (Selection.activeObject)
            {
                Sprite sprite = Selection.activeObject as Sprite;
                if (sprite && !sprites.ContainsKey(sprite.name))
                {
                    sprites.Add(sprite.name, new SpriteData(sprite.name, sprite));
                }
            }
        }
        else
        {
            sprites.Clear();
        }

        posY += 20;
        rect  = new Rect(posX, posY, 100, 50);
        GUILayout.BeginArea(rect);
        using (var h = new EditorGUILayout.HorizontalScope("Button"))
        {
            if (GUI.Button(h.rect, GUIContent.none))
            {
                CreateNewAtlas();
            }
            GUILayout.Label("New Atlas");
        }
        GUILayout.EndArea();

        posY += 50;

        pos = EditorGUILayout.BeginScrollView(new Vector2(posX, posY));

        GUILayout.BeginArea(new Rect(pos, new Vector2(600, 250)));

        EditorGUILayout.BeginVertical();
        List <SpriteData> tempSprites = new List <SpriteData>(sprites.Values);
        List <string>     deletes     = new List <string>();

        foreach (var sp in tempSprites)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.TextField("Sprite:", sp.Name, GUILayout.Width(500));
            if (GUILayout.Button("Delete"))
            {
                if (sprites.ContainsKey(sp.Name))
                {
                    deletes.Add(sp.Name);

                    DeleteSprite(sp.Name);
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        foreach (var item in deletes)
        {
            sprites.Remove(item);
        }

        EditorGUILayout.EndVertical();

        GUILayout.EndArea();
        EditorGUILayout.EndScrollView();

        using (var h = new EditorGUILayout.HorizontalScope("Button"))
        {
            if (GUI.Button(h.rect, GUIContent.none))
            {
                AddOrUpdateAtlas(uiAtlas.name);
            }
            GUIStyle style = new GUIStyle();
            style.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label("Add/Update", style);
        }
        EditorGUILayout.EndVertical();

        this.Repaint();
    }
Пример #2
0
    void OnGUI()
    {
        if (Selection.activeObject)
        {
            Sprite sprite = Selection.activeObject as Sprite;
            if (sprite)
            {
                if (!sprites.ContainsKey(sprite.name))
                {
                    sprites.Add(sprite.name, new SpriteData(sprite.name, sprite));
                }
                else
                {
                    if (sprites[sprite.name].Sprite != sprite)
                    {
                        sprites[sprite.name].Sprite   = sprite;
                        sprites[sprite.name].IsChange = true;
                    }
                }
            }
        }

        EditorGUILayout.BeginVertical();

        float posX = 10;
        float posY = 10;

        Rect rect = new Rect(posX, posY, 500, 20);

        uiAtlas = EditorGUI.ObjectField(rect, new GUIContent("Atlas:"), uiAtlas, typeof(UIAtlas), false) as UIAtlas;

        if (uiAtlas)
        {
            foreach (var item in uiAtlas.GetSprites())
            {
                if (!sprites.ContainsKey(item.Key))
                {
                    sprites.Add(item.Key, new SpriteData(item.Key, item.Value));
                }
            }
        }
        else
        {
            sprites.Clear();
        }

        posY += 20;
        rect  = new Rect(posX, posY, 100, 50);
        GUILayout.BeginArea(rect);
        using (var h = new EditorGUILayout.HorizontalScope("Button"))
        {
            if (GUI.Button(h.rect, GUIContent.none))
            {
                CreateNewAtlas();
            }
            GUIStyle style = new GUIStyle();
            style.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label("New Atlas", style);
        }
        GUILayout.EndArea();

        posY += 50;

        pos = EditorGUILayout.BeginScrollView(new Vector2(posX, posY));

        GUILayout.BeginArea(new Rect(pos, new Vector2(600, 250)));

        EditorGUILayout.BeginVertical();

        List <string> curSprites = new List <string>(sprites.Keys);

        foreach (var sp in curSprites)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.TextField("Sprite:", sp, GUILayout.Width(500));

            if (GUILayout.Button(new GUIContent("Delete")))
            {
                sprites.Remove(sp);
                DeleteSprite(sp);
            }
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.EndVertical();

        GUILayout.EndArea();

        EditorGUILayout.EndScrollView();

        using (var h = new EditorGUILayout.HorizontalScope("Button"))
        {
            if (GUI.Button(h.rect, GUIContent.none))
            {
                if (uiAtlas)
                {
                    AddOrUpdateAtlas(uiAtlas.name);
                }
                else
                {
                    Debug.LogError("Atlas can't be null!");
                }
            }
            GUIStyle style = new GUIStyle();
            style.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label("Add/Update", style);
        }

        EditorGUILayout.EndVertical();

        this.Repaint();
    }