Hello,
is there any way to access the built-in UI sprites such as DropdownArrow, Checkmark or UISprite? I just need the location of them on my hard drive but the only thing I could find was a file named unity_builtin_extra that I couldn’t open.
I want to edit these sprites with an image editor but I can’t find them.
You should be able to create a render texture with a transparent background and render the built in sprite to it and then save it to a png again. I did that for all the builtin textures, you still need to same the UISkin and use a custom version if you want that. That can be done by programaticly copying property values into a new UISkin instance wiith some editor script code.
How do I do that? I thought RenderTextures were only used to render from the camera? How would I render the sprite to it?
Everything I could come up with was this:
using UnityEngine;
using System.Collections;
using System.IO;
using UnityEngine.UI;
using UnityEditor;
public class CreateSpriteFile : MonoBehaviour {
private const string path = "UI/Skin/Checkmark.psd";
[MenuItem("Tools/Save sprites to hard drive")]
private static void NewMenuOption()
{
Image image = GameObject.Find("Main").AddComponent<Image>();
image.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(path);
Texture2D texture = image.sprite.texture;
byte[] bytes = texture.EncodeToPNG();
File.WriteAllBytes("C:/Users/Mathias/Desktop/Sprites/checkmark.png", bytes);
}
}
But it does not work; I get the following exception:
UnityException: Texture ‘Checkmark’ is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.
CreateSpriteFile.NewMenuOption () (at Assets/Editor/CreateSpriteFile.cs:17)