editor script problem, looping
Hello,
I'm looping though an array of sprites to create a button for it. Every sprite of the spritesheet get's his own button, i know this is slow so i need to find a work around for this.
Currently i have:
EditorGUILayout.BeginHorizontal();
for (int i = 0; i < tile.sprites.Length; i++)
{
if (i % 5 == 0)
{
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
}
if (GUILayout.Button(TextureFromSprite(tile.sprites[i]), GUILayout.Width(50), GUILayout.Height(50)))
{
Debug.Log(tile.sprites[i].name);
}
}
EditorGUILayout.EndHorizontal();
The Texturefromsprite is a method to get the sprite for the button ( it returns the sprite itself)
Thanks in advance!
Answer by G4merSylver · Jan 05, 2016 at 12:06 PM
Not sure if I got it right, but by "slow" you probably mean that it has an high strain because its constantly updating? I'm not wellversed in the editor scripting, but instead of using the sprite as an button how about creating an normal button and another overlay that is calculated just once?
If I remember correctly the function encapsulating this should be something thats permanently updating, in this case its constantly spamming the image in an loop.
On another note, do you really need the sprite buttons? I am not entirely sure if the buttons were meant to be used with sprites...
On another note II, it would probably lower the strain if you dont have useless for calls, rewriting the for loop to avoid the i % 5 == 0 might help to.