Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - bogdandude

Pages: [1]
1
Hey there!

We tweaked the UIRoot code a bit to do this:
  • Have a flexible scaling, starting from 640 height (iPhone) to 768 height (iPad)
  • For anything resembling a phone in size, up to a 5.5" device, we're still using the larger UI we set up at 640 height
  • For any device larger than 7", we're using the smaller UI (smaller buttons relative to the game view size), which we set up at the 768 height
  • For anything in between, we interpolate

This seems to work great across all iOS and Android devices, and we no longer see tiny UI elements on 1920x1080 Android screens.

Here's the modified source code:

  1. // CUSTOM HEIGHT CALCULATOR BASED ON DPI
  2.         {
  3.  
  4.             if (dpi == 0)
  5.             {
  6. #if UNITY_EDITOR
  7.                 dpi = 160;
  8. #else
  9.                 dpi = (platform == RuntimePlatform.Android || platform == RuntimePlatform.IPhonePlayer) ? 160f : 96f;
  10. #endif
  11.             }
  12.  
  13.             //Diagonal value for which below we use the minimum Height we desire
  14.             float minDiagonal = 5.5f;
  15.             //Diagonal value for which above we use the maximum Height we desire
  16.             float maxDiagonal = 7f;
  17.  
  18.             //Limit values for the height
  19.  
  20.             int devWidth = Screen.width * Screen.width;
  21.             int devHeight = Screen.height * Screen.height;
  22.             float ypotinousa = devHeight + devWidth;
  23.             ypotinousa = Mathf.Sqrt(ypotinousa);
  24.             //Diagonal size in inches
  25.             float diagonalInches = ypotinousa / dpi;
  26.  
  27.             if (diagonalInches <= minDiagonal)
  28.                 return minimumHeight;
  29.             else if (diagonalInches >= maxDiagonal)
  30.                 return maximumHeight;
  31.             else
  32.             {
  33.                 //IF diagonal is in between the limits we adjust the height to it
  34.                 float diagonalDifference = maxDiagonal - minDiagonal;
  35.                 float diagonalPercantege = ((float)diagonalInches - minDiagonal) / diagonalDifference;
  36.  
  37.                 float widthDifference = maximumHeight - minimumHeight;
  38.                 int targetHeight = Mathf.RoundToInt(minimumHeight + (widthDifference * diagonalPercantege));
  39.                
  40.                 return targetHeight;
  41.             }
  42.         }

This goes into the
  1. static public int AdjustByDPI(float height, int minimumHeight, int maximumHeight)
  function, in NGUIMath.cs

I hope you guys will find it useful too, and maybe we'll someday see this included as standard in future NGUI versions :)

Bogdan

Angry Mob Games

2
Here are some steps:


1 Create a button using your UI Widget wizard (choose a colored texture, so you'd see when it gets greyed out).
2 Maybe also add a UIButtonScale, to see when you're hovering it
3 Remove the Target from the UIButton, in inspector (set it to none).

When you hit play, the button gets disabled (the UIButton component is disabled).

The UIButtonScale still works, and we have a separate component, which links your click events to C# OnButtonClick events, so the buttons work even if that UIButton component is disabled.. it's just greyed out.

So do you think we're doing it wrong, or would you like to change it in the next versions?

Thanks!

3
Hey Aren!

The buttons have colliders, and they get grayed out with or without associated events.

As I told you, they stop getting greyed out when adding a 'Target', so they'd have something to color..
But in some cases, I don't want them to color any of their children...

Could you please look into it?

Thanks!

4
So all buttons get greyed out if they don't have a 'Target' (tweenTarget) set in the editor.
If that's not set, it picks the button gameobject itself, which never has a renderer attached (the images/text are children of that game object).

I guess you also made a single inspector editor for UIButton + UIButtonColor, so it's hard to just remove the UIButtonColor component, if I don't want anything colored when hovering/pressing/disabling the button.

So do you think I should wait for a fix, or should I manually set a 'Target' for each button with such problems?

5
I tracked the bug to this (in UIButtonColor):

Debug.LogWarning(NGUITools.GetHierarchy(gameObject) + " has nothing for UIButtonColor to color", this);
               enabled = false;

so it appears your code doesn't pick up any tweenTarget.renderer for some of the UIButtons, and it disables them (that's not what I want :)

Could you please look into it? And let me know if you plan to change this, or we should be changing something on our side.

Thanks a lot!


6
NGUI 3 Support / BUG with NGUI setting UIButtons to their disabled color
« on: October 31, 2013, 04:20:34 PM »
I believe there's a bug with the latest 3.x NGUI versions:

Many buttons in the game turn grey (their disabled color). Those are just random buttons.

Can you check your custom script execution order? And see if some button initialization to get them enabled/disabled takes place at the wrong time?

Some buttons stay disabled forever (we're not calling any code for that -> the UIButton component gets disabled), while some get enabled again, but their color doesn't change back until you hover them.

Pages: [1]