Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: imkira on August 07, 2012, 10:18:22 PM

Title: Performance improvement for UISlicedSprite
Post by: imkira on August 07, 2012, 10:18:22 PM
Hi,

I use a lot of UISliced buttons, but in many cases I just want to extend them in one direction (horizontal or vertical), while keeping the other direction fixed.

Suppose you have set up an expandable horizontal button that uses non-zero pixels for left/right setting and 0 pixels for bottom/top.
That means we don't want top/bottom border, we just want left and right border and, of course, the middle part of the button.
I noticed that in such cases what could be done with 2 * 3 (2 for left part, 2 for middle part, 2 for right part) triangles is being done with 2 * 3 * 3 (18 parts).

I made an improvement for UISlicedSprite.cs on function OnFill.
I would appreciate if you could commit this in the next versions of NGUI.

  1. ...
  2.                 for (int x = 0; x < 3; ++x)
  3.                 {
  4.                         int x2 = x + 1;
  5.  
  6.                         // improvement 1
  7.                         if (uv[x].x == uv[x2].x) continue;
  8.  
  9.                         for (int y = 0; y < 3; ++y)
  10.                         {
  11.                                 if (!mFillCenter && x == 1 && y == 1) continue;
  12.  
  13.                                 int y2 = y + 1;
  14.  
  15.                                 // improvement 2
  16.                                 if (uv[y].y == uv[y2].y) continue;
  17. ...
  18.  

Thanks in advance.
Title: Re: Performance improvement for UISlicedSprite
Post by: ArenMook on August 08, 2012, 01:16:11 AM
Without any line numbers it's a little difficult to tell where this code is supposed to go.
Title: Re: Performance improvement for UISlicedSprite
Post by: imkira on August 08, 2012, 04:36:14 AM
Without any line numbers it's a little difficult to tell where this code is supposed to go.

Hi, thanks for your reply.
It's right at the end of OnFill function in that nested for loop beginning at line 192.
I basically just added the two "ifs" and "continue" instructions as stated by the "// improvement X" comments.

Thanks in advance.