Esempio n. 1
0
 public static Texture2D GetItemOrigin(MadAtlas.Item item) {
     var path = AssetDatabase.GUIDToAssetPath(item.textureGUID);
     if (string.IsNullOrEmpty(path)) {
         return null;
     }
     
     return AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D;
 }
Esempio n. 2
0
    public static void Show(MadAtlas atlas, string currentGUID, Changed changedCallback)
    {
        //var window = ScriptableObject.CreateInstance<MadAtlasBrowser>();
        var browser = EditorWindow.GetWindow <MadAtlasBrowser>(true, "Atlas Browser", true);

        browser.atlas            = atlas;
        browser.changedCallback  = changedCallback;
        browser.selectedItemGUID = currentGUID;
    }
    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);
    }
Esempio n. 4
0
 public static void Show(MadAtlas atlas, SerializedProperty property)
 {
     if (property != null)
     {
         var currentGUID = property.stringValue;
         Show(atlas, currentGUID, (guid) => {
             property.serializedObject.UpdateIfDirtyOrScript();
             property.stringValue = guid;
             property.serializedObject.ApplyModifiedProperties();
         });
     }
     else
     {
         Show(atlas, "", null);
     }
 }
Esempio n. 5
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);
    }
    private static void RebuildAtlas(MadAtlas atlas, List <Texture2D> allTextures, List <MadAtlas.Item> liveItems)
    {
        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();
        }
    }
Esempio n. 7
0
    public static void AtlasField(string guid, MadAtlas atlas, string label, MadAtlasBrowser.Changed callback) {
        string spriteName = "";
        if (!string.IsNullOrEmpty(guid)) {
            var guids = atlas.ListItemGUIDs();
            var index = guids.FindIndex((s) => s == guid);

            if (index != -1) {
                spriteName = atlas.items[index].name;
            }
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.TextField(label, spriteName);
        if (GUILayout.Button("Browse", GUILayout.Width(55))) {
            MadAtlasBrowser.Show(atlas, guid, callback);
        }
        EditorGUILayout.EndHorizontal();
    }
Esempio n. 8
0
    public static void AtlasField(SerializedProperty textureField, MadAtlas atlas, string label) {
        string guid = textureField.stringValue;
        string spriteName = "";
        if (!string.IsNullOrEmpty(guid) && atlas != null) {
            var item = atlas.GetItem(guid);
            if (item != null) {
                spriteName = item.name;
            }
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.TextField(label, spriteName);
        MadGUI.ConditionallyEnabled(atlas != null, () => {
            if (GUILayout.Button("Browse", GUILayout.Width(55))) {
                MadAtlasBrowser.Show(atlas, textureField);
            }
        });
        EditorGUILayout.EndHorizontal();
    }
Esempio n. 9
0
    public static void AtlasField(string guid, MadAtlas atlas, string label, MadAtlasBrowser.Changed callback, ScriptableObject parent)
    {
        string spriteName = "";

        if (!string.IsNullOrEmpty(guid))
        {
            var guids = atlas.ListItemGUIDs();
            var index = guids.FindIndex((s) => s == guid);

            if (index != -1)
            {
                spriteName = atlas.items[index].name;
            }
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.TextField(label, spriteName);
        if (GUILayout.Button("Browse", GUILayout.Width(55)))
        {
            MadAtlasBrowser.Show(atlas, guid, callback, parent);
        }
        EditorGUILayout.EndHorizontal();
    }
Esempio n. 10
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();
        }
    }
Esempio n. 11
0
    public static void AtlasField(SerializedProperty textureField, MadAtlas atlas, string label, ScriptableObject parent)
    {
        string guid       = textureField.stringValue;
        string spriteName = "";

        if (!string.IsNullOrEmpty(guid) && atlas != null)
        {
            var item = atlas.GetItem(guid);
            if (item != null)
            {
                spriteName = item.name;
            }
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.TextField(label, spriteName);
        MadGUI.ConditionallyEnabled(atlas != null, () => {
            if (GUILayout.Button("Browse", GUILayout.Width(55)))
            {
                MadAtlasBrowser.Show(atlas, textureField, parent);
            }
        });
        EditorGUILayout.EndHorizontal();
    }
    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();
        }
    }
Esempio n. 13
0
 public static void AddToAtlas(MadAtlas atlas, Texture2D texture) {
     AddToAtlas(atlas, new Texture2D[] { texture });
 }
Esempio n. 14
0
    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    // ===========================================================
    // Methods
    // ===========================================================
    
    void OnEnable() {
        atlas = target as MadAtlas;
    
        textureDragDrop = Resources.Load("Mad2D/Textures/icon_drag_drop") as Texture;
    }
Esempio n. 15
0
 public static void Show(MadAtlas atlas, SerializedProperty property, ScriptableObject parent) {
     if (property != null) {
         var currentGUID = property.stringValue;
         Show(atlas, currentGUID, (guid) => {
             if (parent != null) {
                 property.serializedObject.UpdateIfDirtyOrScript();
                 property.stringValue = guid;
                 property.serializedObject.ApplyModifiedProperties();
             }}, parent);
     } else {
         Show(atlas, "", null, parent);
     }
 }
Esempio n. 16
0
 private static List <MadAtlas.Item> LiveItems(MadAtlas atlas)
 {
     return((from item in atlas.items where MadAtlasUtil.GetItemOrigin(item) != null select item).ToList());
 }
Esempio n. 17
0
 Vector2 FixUV(Vector2 uv, MadAtlas.Item item) {
     if (item != null) {
         var region = item.region;
         return new Vector2(region.x + region.width * uv.x, region.y + region.height * uv.y);
     } else {
         return uv;
     }
 }
Esempio n. 18
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);
 }
Esempio n. 19
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();
        }
    }
Esempio n. 20
0
 public static void AddToAtlas(MadAtlas atlas, Texture2D texture)
 {
     AddToAtlas(atlas, new Texture2D[] { texture });
 }
Esempio n. 21
0
    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);
    }
Esempio n. 22
0
    private static void RebuildAtlas(MadAtlas atlas, List<Texture2D> allTextures, List<MadAtlas.Item> liveItems) {
        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();
        }
    }
Esempio n. 23
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);

        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();
        }
    }
Esempio n. 24
0
    Vector2 DrawTile(MadAtlas.Item item, Vector2 position, ref Vector2 bounds) {
        // apply search filter
        if (!string.IsNullOrEmpty(searchFilter)) {
            if (!item.name.ToUpper().Contains(searchFilter.ToUpper())) {
                return position;
            }
        }

        // check for click event
        var allRect = new Rect(position.x, position.y, tileSize.x, tileSize.y);

        if (Event.current.type == EventType.MouseDown && Event.current.button == 0) {
            if (allRect.Contains(Event.current.mousePosition)) {

                // handle double click
                if (selectedItemGUID == item.textureGUID && (DateTime.Now - lastClickTime).TotalMilliseconds < 200) {
                    Close();
                }
                lastClickTime = DateTime.Now;

                Select(item.textureGUID);
            }
        }

        // draw texture
        if (item != noneItem) {
            var textureRect = new Rect(position.x, position.y, textureSize.x, textureSize.y);
            var texturesCoords = item.region;

            textureRect = KeepRatio(textureRect, item.pixelsWidth, item.pixelsHeight);

            GUI.DrawTextureWithTexCoords(textureRect, atlas.atlasTexture, texturesCoords);
        }

        // draw label
        var labelRect = new Rect(position.x, position.y + textureSize.y, labelSize.x, labelSize.y);

        if (selectedItemGUID == item.textureGUID) {
            if (EditorGUIUtility.isProSkin) {
                GUI.color = new Color(63 / 255f, 92 / 255f, 133 / 255f);
            } else {
                GUI.color = new Color(63 / 255f, 132 / 255f, 230 / 255f);
            }
            
            GUI.DrawTexture(labelRect, whiteTexture);
            GUI.color = Color.white;
        }

        GUI.Label(labelRect, item.name);

        // update bounds
        bounds = new Vector2(Mathf.Max(bounds.x, labelRect.xMax), Mathf.Max(bounds.y, labelRect.yMax));

        // calculate next position
        Vector2 newPosition = position + new Vector2(tileSize.x + tileMargin.x, 0);
        if (newPosition.x + tileSize.x > Screen.width) {
            newPosition = new Vector2(0, position.y + tileSize.y + tileMargin.y);
        }

        return newPosition;
    }
Esempio n. 25
0
 private static List<MadAtlas.Item> LiveItems(MadAtlas atlas) {
     return (from item in atlas.items where MadAtlasUtil.GetItemOrigin(item) != null select item).ToList();
 }
Esempio n. 26
0
 public static void Show(MadAtlas atlas, string currentGUID, Changed changedCallback, ScriptableObject parent) {
     //var window = ScriptableObject.CreateInstance<MadAtlasBrowser>();
     var browser = EditorWindow.GetWindow<MadAtlasBrowser>(true, "Atlas Browser", true);
     browser.atlas = atlas;
     browser.changedCallback = changedCallback;
     browser.selectedItemGUID = currentGUID;
     browser.parent = parent;
 }
Esempio n. 27
0
    // ===========================================================
    // Constants
    // ===========================================================

    // ===========================================================
    // Fields
    // ===========================================================

    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    // ===========================================================
    // Methods
    // ===========================================================

    public static string GetItemOriginPath(MadAtlas.Item item) {
        var path = AssetDatabase.GUIDToAssetPath(item.textureGUID);
        return path;
    }