I just stumbled over a performance issue that (at least in the editor) results in hitches of ~300ms when shifting the items of my inventory bar.
From what I've discovered, the issue lies in UISlot.SetImage() where a sprite is create dynamically when the texture changes. The default sprite constructor will create a "tight" sprite mesh. This takes some time as apparently the whole texture is scanned to figure out the actual non-transparent pixels for the tight mesh. I've changed the line
sprite = Sprite.Create (_texture, new Rect (0f, 0f, _texture.width, _texture.height), new Vector2 (0.5f, 0.5f));
into
sprite = Sprite.Create (_texture, new Rect (0f, 0f, _texture.width, _texture.height), new Vector2 (0.5f, 0.5f), 100F, 0, SpriteMeshType.FullRect);
and it solved the issue (still, sprites should not be created all over again, I'm also not sure if they are garbage collected at some time, maybe at the next scene change).
Comments