Beispiel #1
0
    void DrawInfoPanel()
    {
        var rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(74), GUILayout.Width(Screen.width));

        string name = "";
        string size = "";
        string path = "";

        if (!string.IsNullOrEmpty(selectedItemGUID))
        {
            var item = atlas.GetItem(selectedItemGUID);

            if (item != null)
            {
                name = item.name;
                size = item.pixelsWidth + "x" + item.pixelsHeight;
                path = MadAtlasUtil.GetItemOriginPath(item);

                GUI.DrawTextureWithTexCoords(new Rect(rect.x + 5, rect.y + 5, 64, 64), atlas.atlasTexture, item.region);
            }
        }

        GUILayout.Space(74);
        GUILayout.BeginVertical();

        GUILayout.Label(name);
        GUILayout.Label(size);
        GUILayout.Label(path);

        GUILayout.EndVertical();


        EditorGUILayout.EndHorizontal();
    }
    public static void RebuildAtlas(MadAtlas atlas)
    {
        List <MadAtlas.Item> liveItems = LiveItems(atlas);

        List <Texture2D> allTextures = new List <Texture2D>();

        allTextures.AddRange(from i in liveItems select MadAtlasUtil.GetItemOrigin(i));

        RebuildAtlas(atlas, allTextures, liveItems);
    }
Beispiel #3
0
    public static void RemoveFromAtlas(MadAtlas atlas, MadAtlas.Item item)
    {
        var liveItems = LiveItems(atlas);
        var newItems  = (from el in liveItems where el != item select el).ToList();

        atlas.ClearItems();

        var allTextures = from el in newItems select MadAtlasUtil.GetItemOrigin(el);

        string atlasTexturePath = AssetDatabase.GetAssetPath(atlas.atlasTexture);

        PackTextures(allTextures.ToArray(), atlasTexturePath, ref newItems);

        atlas.ClearItems();
        atlas.AddItemRange(newItems);
    }
Beispiel #4
0
    public static void AddToAtlas(MadAtlas atlas, Texture2D[] textures)
    {
        List <MadAtlas.Item> liveItems   = LiveItems(atlas);
        List <Texture2D>     allTextures = new List <Texture2D>();

        allTextures.AddRange(from i in liveItems select MadAtlasUtil.GetItemOrigin(i));
        allTextures.AddRange(textures);

        var modified = MakeReadable(allTextures);

        try {
            string atlasTexturePath = AssetDatabase.GetAssetPath(atlas.atlasTexture);
            PackTextures(allTextures.ToArray(), atlasTexturePath, ref liveItems);

            atlas.ClearItems();
            atlas.AddItemRange(liveItems);

            EditorUtility.SetDirty(atlas);
        } finally {
            RevertReadable(modified);
            AssetDatabase.Refresh();
        }
    }
    public static void RemoveFromAtlas(MadAtlas atlas, MadAtlas.Item item)
    {
        var liveItems = LiveItems(atlas);
        var newItems  = (from el in liveItems where el != item select el).ToList();

        atlas.ClearItems();

        var allTextures = from el in newItems select MadAtlasUtil.GetItemOrigin(el);

        var modified = MakeReadable(allTextures);

        try {
            string atlasTexturePath = AssetDatabase.GetAssetPath(atlas.atlasTexture);
            PackTextures(allTextures.ToArray(), atlasTexturePath, ref newItems);

            atlas.ClearItems();
            atlas.AddItemRange(newItems);

            EditorUtility.SetDirty(atlas);
        } finally {
            RevertReadable(modified);
            AssetDatabase.Refresh();
        }
    }
Beispiel #6
0
 private static List <MadAtlas.Item> LiveItems(MadAtlas atlas)
 {
     return((from item in atlas.items where MadAtlasUtil.GetItemOrigin(item) != null select item).ToList());
 }
    protected void SectionSprite(DisplayFlag flags)
    {
        serializedObject.Update();
        GUIDepthCheck();

        MadGUI.PropertyField(panel, "Panel", MadGUI.ObjectIsSet);
        EditorGUILayout.Space();

        MadGUI.PropertyField(visible, "Visible");

        if ((flags & DisplayFlag.WithoutMaterial) == 0)
        {
            MadGUI.PropertyFieldEnumPopup(inputType, "Input Type");
            MadGUI.Indent(() => {
                switch (sprite.inputType)
                {
                case MadSprite.InputType.SingleTexture:
                    MadGUI.PropertyField(texture, "Texture", MadGUI.ObjectIsSet);
                    MadGUI.Indent(() => {
                        MadGUI.PropertyFieldVector2(textureRepeat, "Repeat");
                        MadGUI.PropertyFieldVector2(textureOffset, "Offset");
                    });
                    break;

                case MadSprite.InputType.TextureAtlas:
                    MadGUI.PropertyField(textureAtlas, "Texture Atlas", MadGUI.ObjectIsSet);

                    if (sprite.textureAtlas != null)
                    {
                        MadAtlasUtil.AtlasField(textureAtlasSpriteGUID, sprite.textureAtlas, "Sprite", this);
                    }

                    break;

                default:
                    Debug.LogError("Unknown input type: " + sprite.inputType);
                    break;
                }
            });
        }

        MadGUI.PropertyField(hasPremultipliedAlpha, "Has Pre-Alpha");

        MadGUI.PropertyField(tint, "Tint");

        EditorGUILayout.Space();

        if ((flags & DisplayFlag.WithoutSize) == 0)
        {
            EditorGUILayout.Space();
            GUI.backgroundColor = Color.yellow;
            if (GUILayout.Button(new GUIContent("Resize To Texture",
                                                "Resizes this sprite to match texture size")))
            {
                MadUndo.RecordObject2(sprite, "Resize To Texture");
                sprite.ResizeToTexture();
                EditorUtility.SetDirty(sprite);
            }
            GUI.backgroundColor = Color.white;
            EditorGUILayout.Space();
        }

        EditorGUILayout.Space();

        MadGUI.PropertyField(pivotPoint, "Pivot Point");
        if (sprite.pivotPoint == MadSprite.PivotPoint.Custom)
        {
            MadGUI.Indent(() => {
                MadGUI.PropertyFieldVector2(customPivotPoint, "Custom Pivot Point");
            });
        }

        MadGUI.PropertyField(guiDepth, "GUI Depth");

        EditorGUILayout.Space();

        if ((flags & DisplayFlag.WithoutFill) == 0)
        {
            MadGUI.PropertyField(fillType, "Fill Type");
            EditorGUILayout.Slider(fillValue, 0, 1, "Fill Value");

            if (sprite.fillType == MadSprite.FillType.RadialCCW || sprite.fillType == MadSprite.FillType.RadialCW)
            {
                MadGUI.PropertyFieldSlider(radialFillOffset, -1, 1, "Offset");
                MadGUI.PropertyFieldSlider(radialFillLength, 0, 1, "Length");
            }
        }

        if (showLiveBounds)
        {
            GUILayout.Label("Sprite Border", "HeaderLabel");
            EditorGUILayout.Space();
            if (sprite.CanDraw())
            {
                FieldLiveBounds();
            }
            else
            {
                MadGUI.Info("More settings will be available when the sprite texture or atlas is set.");
            }
        }

        serializedObject.ApplyModifiedProperties();
    }