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; }
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); }
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); } }
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(); } }
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(); }
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(); }
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(); }
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 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(); } }
public static void AddToAtlas(MadAtlas atlas, Texture2D texture) { AddToAtlas(atlas, new Texture2D[] { texture }); }
// =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== void OnEnable() { atlas = target as MadAtlas; textureDragDrop = Resources.Load("Mad2D/Textures/icon_drag_drop") as Texture; }
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); } }
private static List <MadAtlas.Item> LiveItems(MadAtlas atlas) { return((from item in atlas.items where MadAtlasUtil.GetItemOrigin(item) != null select item).ToList()); }
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; } }
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 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); }
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(); } }
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; }
private static List<MadAtlas.Item> LiveItems(MadAtlas atlas) { return (from item in atlas.items where MadAtlasUtil.GetItemOrigin(item) != null select item).ToList(); }
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; }
// =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== public static string GetItemOriginPath(MadAtlas.Item item) { var path = AssetDatabase.GUIDToAssetPath(item.textureGUID); return path; }