void SpriteList() { GUILayout.Label("Sprites", "HeaderLabel"); bool hasMissingTextures = false; EditorGUI.BeginChangeCheck(); MadGUI.Indent(() => { for (int i = 0; i < atlas.ListItems().Count; ++i) { MadAtlas.Item item = atlas.ListItems()[i]; EditorGUILayout.BeginHorizontal(); var texture = MadAtlasUtil.GetItemOrigin(item); bool valid = MadGUI.Validate(() => texture != null, () => { item.name = EditorGUILayout.TextField(item.name); }); GUI.enabled = valid; GUI.color = Color.yellow; if (GUILayout.Button("Ping", GUILayout.Width(40))) { EditorGUIUtility.PingObject(texture); } GUI.enabled = true; GUI.color = Color.red; if (GUILayout.Button("X", GUILayout.Width(20))) { MadAtlasBuilder.RemoveFromAtlas(atlas, item); } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); if (!valid) { hasMissingTextures = true; } } if (hasMissingTextures) { MadGUI.Error("There are sprites with missing origin texture. This will for them to dissapear on edit."); } }); if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(atlas); } }
void AddTextures(Texture2D[] textures) { foreach (var tex in textures) { if (tex == atlas.atlasTexture) { EditorUtility.DisplayDialog("Wrong texture", "Cannot add atlas texture to the same atlas!", "OK"); return; } } MadAtlasBuilder.AddToAtlas(atlas, textures); }
public static void Convert() { MadUndo.LegacyRegisterSceneUndo("Convert to Atlas"); var allSprites = GameObject.FindObjectsOfType(typeof(MadSprite)) as MadSprite[]; var texturedSprites = from sprite in allSprites where sprite.inputType == MadSprite.InputType.SingleTexture && sprite.texture != null select sprite; var textures = from sprite in texturedSprites select sprite.texture; textures = textures.Distinct(); var atlas = MadAtlasBuilder.CreateAtlas(textures.ToArray()); if (atlas == null) { EditorUtility.DisplayDialog("Convert", "Conversion cancelled!", "OK"); return; } foreach (var sprite in texturedSprites) { sprite.inputType = MadSprite.InputType.TextureAtlas; sprite.textureAtlas = atlas; string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(sprite.texture)); sprite.textureAtlasSpriteGUID = guid; EditorUtility.SetDirty(sprite); } EditorUtility.DisplayDialog("Convert", "Conversion done! Please save your scene!", "OK"); }
static void CreateAtlas() { MadAtlasBuilder.CreateAtlas(); }