Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

NGUI (Next-Gen UI) -- demo final feedback request

Discussion in 'Assets and Asset Store' started by ArenMook, Dec 8, 2011.

Thread Status:
Not open for further replies.
  1. terenctb

    terenctb

    Joined:
    Jun 2, 2009
    Posts:
    12
    More suggestions on handling fonts with Texture Packer (streamlining the pipeline).

    This is related to the trim/crop feature in texture packer which really helps a lot in packing sprites together by trimming/removing transparent pixels. Currently I tested the font import, which uses the font config export file width/height instead of the texture rect width to calculate offsets on the bitmap font.

    The reason is that some font export packages(I use hiero), generate images of fixed sizes (i.e. 256x256). Obviously I could go in with GIMP and trim the font size(i.e. remove the transparent pixels myself) and then turn around and update the font config file but that gets pretty tedious. Far easier to just let TexturePacker handle it.
     
  2. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    That's unexpected. You say it worked in 1.23? Let me look at what may have changed.

    Edit: Looked into this. There does seem to be some issue with LoadLevel resulting in no UI in Flash (and only in flash) , however I reverted back to January 1st version and back then only the font was showing up after LoadLevel, no sprites. Which version were you using?
     
    Last edited: Jan 5, 2012
  3. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @quitebuttery: In example 2 I was placing items manually just so the example wouldn't get complicated. Ideally you would be placing them yourself in a simple 'for' loop, like what I did in example 3. I am guessing what you'd like to see is something like ScrollableContainer.AddItem(abc) and have the spacing be a property on the ScrollableContainer script you set in the inspector, right?

    @terenctb: The font import/atlas connection is on my list of things to do, you will be happy with what will come in 1.25 :)

    @nsxdavid and @terenctb: The support for 'trim' feature is on the list, I will bump it up a bit.
     
    Last edited: Jan 5, 2012
  4. Legacy

    Legacy

    Joined:
    Oct 11, 2011
    Posts:
    651
    i downloaded and imorted whatever package was at the new link you sent me last week via emal last night sol 1.24 it worked yesterday with 1.23 now my ui is gone in flash lol
     
  5. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    No I meant what version did you have before? :)

    I just tracked down why text is not showing up... it's beyond effed up. I added a check: if (mFont == null) return; to the OnFill function in the UILabel class just to be safe (mFont is used right after). For some reason on Flash this causes the text to not show up!

    Wtf?
     
  6. Legacy

    Legacy

    Joined:
    Oct 11, 2011
    Posts:
    651
    well ive been upgrading by importing every release so far. did you try this fresh with 1,24 on flash?
     
  7. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Yup. I am now trying to figure out why flash gets screwed up by a simple early return statement.
     
  8. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Lol, navigate to the end of UILabel class, the very last function (OnFill). Remove the null check up top and replace this line:

    Code (csharp):
    1. mFont.Print(mProcessedText, color, verts, uvs, cols, mEncoding);
    With this line:

    Code (csharp):
    1. mFont.Print(mFont == null ? "Wtf flash?" : mProcessedText, color, verts, uvs, cols, mEncoding);
    Guess what gets printed in all the labels after Application.LoadLevel?
     
  9. Legacy

    Legacy

    Joined:
    Oct 11, 2011
    Posts:
    651
    everything getting nulled out?
     
  10. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    But it doesn't, that's the thing. Flash just happens to evaluate it as if it does. If it was actually null, you wouldn't see "Wtf flash?" everywhere. It would simply crash, as mFont is used in that line. :)

    It's a major bug in the current version of Flash export.
     
  11. Legacy

    Legacy

    Joined:
    Oct 11, 2011
    Posts:
    651
    it was working with your last version though its not just the labels its all the images too

    edit: idk about load level thought i assumed it was working because my team member hda things working with the loading screen the other night
     
  12. Legacy

    Legacy

    Joined:
    Oct 11, 2011
    Posts:
    651
    also i just checked and ifi instantiate labels during run time(like i do for my damage system it instantiates a prefab with a label and assigns a number when i do damage to an enemy and then itweens up) that works fine i see that and the numbers are correct.
     
  13. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    1.23 had the same behavior, so you must have been on a version prior to that. Anyhow, I can "fix" it by making my code less safe (removing null checks), but it's a hack around a problem -- a problem with Unity's flash export.
     
  14. Legacy

    Legacy

    Joined:
    Oct 11, 2011
    Posts:
    651
    hmm any way you can just release it as a "Flash Compatible" version and leave the other one up there i really only need it for today because of the contest lol. (Maybe you can try out my game and see what a wonder ngui does for games like this :))
     
  15. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Yeah don't worry, I will get you up and running again. I just need to track down why widgets aren't showing up after LoadLevel. I'm guessing it's just another null check somewhere that Flash believes evaluates to null. I submitted a bug report about it.
     
  16. Legacy

    Legacy

    Joined:
    Oct 11, 2011
    Posts:
    651
    alrighty thanks :) lemme know when its all set ill work on polishing other things while i wait.
     
  17. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Done. Grab 1.24b, I added a work-around for this bug.
     
  18. Legacy

    Legacy

    Joined:
    Oct 11, 2011
    Posts:
    651
    kk same link as the one in my email?
     
  19. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
  20. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Hey there,

    I'm having some difficulty. I'm trying to set a sprite that covers the entire screen (for now I attach a uisprite so I can see something, but assume just a collider will do).
    I need to register a click on this sprite and pass it to a script on another object.
    I've set uisendstate and uisendstateonpress scripts and targeted my object - but no event gets triggered.
    The receiving object has multiple scripts attached (I presume there's no issue there); but void OnPress() never gets called.
    Any ideas what I have done wrong? :)

    Cheers
     
  21. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Did you add a collider?

    SendState series of scripts only forward states (integers), calling OnState() function on the target. If you are trying to forward actual events such as OnPress(), you will need to write a small custom script instead, something like:

    Code (csharp):
    1. public class ForwardEvent : MonoBehaviour
    2. {
    3.     public GameObject target;
    4.  
    5.     void OnPress (bool isPressed)
    6.     {
    7.         if (target != null) target.SendMessage("OnPress", isPressed, SendMessageOptions.DontRequireReceiver);
    8.     }
    9. }
    May I ask why you don't just receive this event by the 'target' sprite to begin with though?
     
  22. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Hey ArenMook,

    Yeah it has a collider attached and 'looks' correct i.e. it's position etc.
    Sorry I am confused :)
    Originally with Prime's UI I altered my gui to be event driven therefore touching the backdrop (i.e. not gui icon) caused an event trigger.
    I had a sprite collider covering the entire screen and the other sprites sat onto that. Therefore I could tell if 'backdrop' was touched or icon - hope you see what I mean.
    I have set the target to be the receiving object (I presume I have done this correctly); based on the examples - I am obviously mis-using something!!

    Cheers
     
  23. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    I suggest not doing it this way. Placing all your event logic in one place and manually managing forwarding those events to specific widgets creates a big jumbled mess in larger projects and generally is a nightmare to maintain. Placing your event logic on the buttons that should be receiving them is more straightforward and far easier to work with in the long run. That's how NGUI was designed, so the amount of code you'll have to write will go down considerably.

    Try this... remove the collider from your background and add a collider to your icon instead (NGUI menu -> Add Collider). Add a simple script to this icon:

    Code (csharp):
    1. public class Test : MonoBehaviour
    2. {
    3.     void OnClick ()
    4.     {
    5.         Debug.Log("Clicked!");
    6.     }
    7. }
    And see if this works.
     
  24. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Hey ArenMook,

    That didn't work. I'll reverse my method for icon selection; again I thought it was the right way to go as UIToolkit seemed to suggest.
    I'll stick my 'backdrop' test (ray to scene) in Update() and deal with it 'properly' as it were.
    Then presumably I can just stick my gui on top that and use Ngui as intended :))

    Cheers

    EDIT: Though I think you slightly mis-understand me. The buttons do have events to receive on each. The thing is I wanted the entire screen to be an event receiver also i.e. for when an icon isn't pressed but the scene is instead. Because then I know the scene was touched and not an icon on top the scene....; this does seem a more natural approach.
     
    Last edited: Jan 5, 2012
  25. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    If that didn't work then you are likely missing the UICamera script on your camera.

    Ray to scene test? If you are trying to determine whether the mouse clicked on the background or on the icon, just add a collider to the background as well, and move the background away from the camera a bit so the icons are clicked on first. You don't need to do any raycasts of your own.
     
  26. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Here is a script that will automatically arrange all children of the game object it's attached to into a grid of your dimensions:
    Code (csharp):
    1. [ExecuteInEditMode]
    2. [AddComponentMenu("NGUI/Examples/Simple Grid")]
    3. public class SimpleGrid : MonoBehaviour
    4. {
    5.     public enum Arrangement
    6.     {
    7.         Horizontal,
    8.         Vertical,
    9.     }
    10.  
    11.     public Arrangement arrangement = Arrangement.Horizontal;
    12.     public int maxRows = 0;
    13.     public float cellWidth = 200f;
    14.     public float cellHeight = 200f;
    15.     public bool repositionNow = false;
    16.  
    17.     void Start ()
    18.     {
    19.         Reposition();
    20.     }
    21.  
    22.     void Update ()
    23.     {
    24.         if (repositionNow)
    25.         {
    26.             repositionNow = false;
    27.             Reposition();
    28.         }
    29.     }
    30.  
    31.     public void Reposition ()
    32.     {
    33.         Transform myTrans = transform;
    34.  
    35.         int x = 0;
    36.         int y = 0;
    37.  
    38.         for (int i = 0; i < myTrans.childCount; ++i)
    39.         {
    40.             Transform t = myTrans.GetChild(i);
    41.  
    42.             t.localPosition = arrangement == Arrangement.Horizontal ?
    43.                 new Vector3(cellWidth * x, -cellHeight * y, 0f) :
    44.                 new Vector3(cellWidth * y, -cellHeight * x, 0f);
    45.  
    46.             if (x++ >= maxRows  maxRows > 0)
    47.             {
    48.                 x = 0;
    49.                 ++y;
    50.             }
    51.         }
    52.     }
    53. }
     
  27. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    :)
    Sorry I'm confusing you (and me!)
    I have UICamera attached to camera.
    Here's what I currently have:
    1 big sprite covers the whole screen (or at least 1 big collision box as I don't want too see this sprite)
    Now if I get a touch event on this sprite I assume the user has selected the scene (3d so I ray cast to find what I need not ngui :) )
    Ontop that I stick my icons.
    Then if a user touches the icon I get an event and I deal with that.
    My problem seems to be getting ngui to stick a big collider over the entire scene and have an event register from that; I've checked the examples and I seem to have the same setup so I must be missing something simple (of course!) :)

    Cheers
     
  28. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Right, that's the thing -- with NGUI everything with a collider is capable of receiving events, not just the UI. You can attach that test script to an NPC in your game and you will see the "Clicked" message when you click on him. Everything is treated cohesively as one system, so you don't need to write such hacks. :)

    You can safely remove that big collider.
     
  29. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    319
    markhula too many bad habits of our friend rom hehehe, you have to open your mind to this open thing (which is unity) :) NGUI makes your life easier....
     
  30. mydingefnysen

    mydingefnysen

    Joined:
    Dec 15, 2011
    Posts:
    51
    @markhula: Have you made sure the big collider is on the correct layer? And that its z-pos is within the cameras culling dist (I've noticed that sometimes if zpos is too close to camera culling limit it can still be visible but not recieve raycasts).

    @arenmook: Im trying to make a resizeble window with a label, text and button that keep the layout when resized, and if minimized only the label will be visible (but enclosed by the window). Im trying to figure out how to do this the best way but Im not so successful. For example, is it somehow possible to get the position of the inner rect of the resizable sliced sprite? My idea was to make a label with pivot=topleft follow that point (that is, the top left point of the inner rect). My sprite has some drop shadow so its not as easy as just getting the scale of the sliced sprite to know its size and bounds.

    hmm. talking about drop shadows on windows, maybe its easier to do that by stacking two sliced sprites on top of each other? One with the window and underneath one with the drop shadow? Might allow for more control of where exactly the window borders are.
     
    Last edited: Jan 5, 2012
  31. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Your best bet is to create a script that will watch a specific corner of a widget and will position itself to be at that corner + offset. You can specify the offset to be your window's border size.
     
  32. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    Im getting an error after the update :(

    Code (csharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UISprite.Init () (at Assets/NGUI/Scripts/UI/UISprite.cs:179)
    3. UISprite.UpdateUVs () (at Assets/NGUI/Scripts/UI/UISprite.cs:115)
    4. UISprite.OnStart () (at Assets/NGUI/Scripts/UI/UISprite.cs:195)
    5. UIWidget.Start () (at Assets/NGUI/Scripts/Internal/UIWidget.cs:276)
    6.  
    ]
     
  33. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Which version, 1.24 or 1.24b, and what's your target?
     
  34. mydingefnysen

    mydingefnysen

    Joined:
    Dec 15, 2011
    Posts:
    51
    @ArenMook: yeah, thats what I've been trying to do:) Ill try some more and see if I can come up with a more specific question later if I cant get it to work.

    Got an idea for a feature for UILabel. Right now we can set line width and it will cut the last word if it exceeds. It would be nice to be able to truncate it with a string, for example "Hello World" becomes "Hello Wo..." instead of just "Hello". Or a longer text might be truncated with "(more...)" at the end.
     
  35. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    1.24b target flash, its on the UICursor happens when the UISprite doesnt have atlas defined
     
  36. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @hjupter: I was afraid of that. It's the work-around for a bug in the current Flash export discussed earlier this morning in this thread. Remove the #if !UNITY_FLASH above that line to fix it, but this will break UI after LoadLevel. It's pretty much one or the other until Unity guys fix their bug.

    @mydingefnysen: That might be useful. I'll think about it, but with the current list of things to do I can't promise to get to it soon. :|
     
  37. andresp

    andresp

    Joined:
    Aug 12, 2011
    Posts:
    38
    I lol'd at this xD
     
  38. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Think I have it working :)
    Zdepth was an issue.
    But also (which stumped me for a while) - when I added uianchor it seemed to pickup the wrong camera - not sure how/why

    Still testing :)

    Cheers
     
  39. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    If it chose the wrong camera it means you had more than one camera drawing the layer of the object you attached UIAnchor to.
     
  40. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Could be :)
    Part of the problem of removing old UI code yet leaving enough in so it works. :)
    If it had been a fresh project then I think absolutely no issue.

    Thanks for your help.

    Cheers
     
  41. mydingefnysen

    mydingefnysen

    Joined:
    Dec 15, 2011
    Posts:
    51
    Follow-pivot-on-widget-script: Finally came up with something that works, but it feels overly complicated for the task. And lacks some features. Here it is in case anyone needs it.

    Code (csharp):
    1. using UnityEngine;
    2.  
    3. /// <summary>
    4. /// Makes a gameobject follow a corner or side of a widget. Define the widget, and if you like it to automatically adjust the position if the widget scales or translates.
    5. /// HOW TO IMPROVE: Support for offset, support for following a rotating widget, optimization (caching positionOffset for example)
    6. /// </summary>
    7.  
    8. public class FollowWidgetPivot : MonoBehaviour
    9. {
    10.     public UIWidget widgetToFollow;
    11.     public UIWidget.Pivot pivotToFollow = UIWidget.Pivot.TopLeft;
    12.     public Vector3 offset = Vector3.zero;
    13.     public bool followScale = false;
    14.  
    15.     private Vector3 mOldScale; //Used to only calculate position adjustments when scale changes
    16.     private Vector3 mOldPosition;
    17.  
    18.     void Update ()
    19.     {
    20.         if (!widgetToFollow || !followScale) return;
    21.         if (mOldScale != widgetToFollow.gameObject.transform.localScale || mOldPosition != widgetToFollow.gameObject.transform.position) UpdatePosition();
    22.     }
    23.  
    24.     public void UpdatePosition()
    25.     {
    26.         Vector3 newPos = widgetToFollow.gameObject.transform.position;
    27.         Vector2 positionOffset = GetPivotOffset(widgetToFollow.pivot, pivotToFollow);
    28.  
    29.         //Does it make any difference to use widgetToFollow.finalScale instead of widgetToFollow.gameObject.transform.localScale?
    30.         newPos.x += widgetToFollow.gameObject.transform.localScale.x*positionOffset.x;
    31.         newPos.y += widgetToFollow.gameObject.transform.localScale.y*positionOffset.y;
    32.         transform.position = newPos;
    33.  
    34.         mOldScale = widgetToFollow.gameObject.transform.localScale;
    35.         mOldPosition = widgetToFollow.gameObject.transform.position;
    36.     }
    37.  
    38.     private Vector2 GetPivotOffset (UIWidget.Pivot mPivot, UIWidget.Pivot targetPivot)
    39.     {
    40.         Vector2 v = Vector2.zero;
    41.  
    42.         if (targetPivot == UIWidget.Pivot.TopLeft || targetPivot == UIWidget.Pivot.Left || targetPivot == UIWidget.Pivot.BottomLeft)
    43.         {
    44.             if (mPivot == UIWidget.Pivot.Top || mPivot == UIWidget.Pivot.Center || mPivot == UIWidget.Pivot.Bottom) v.x -= 0.5f;
    45.             else if (mPivot == UIWidget.Pivot.TopRight || mPivot == UIWidget.Pivot.Right || mPivot == UIWidget.Pivot.BottomRight) v.x -= 1f;
    46.         }
    47.  
    48.         if (targetPivot == UIWidget.Pivot.TopRight || targetPivot == UIWidget.Pivot.Right || targetPivot == UIWidget.Pivot.BottomRight)
    49.         {
    50.             if (mPivot == UIWidget.Pivot.Top || mPivot == UIWidget.Pivot.Center || mPivot == UIWidget.Pivot.Bottom) v.x += 0.5f;
    51.             else if (mPivot == UIWidget.Pivot.TopLeft || mPivot == UIWidget.Pivot.Left || mPivot == UIWidget.Pivot.BottomLeft) v.x += 1f;
    52.         }
    53.  
    54.         if (targetPivot == UIWidget.Pivot.TopLeft || targetPivot == UIWidget.Pivot.Top || targetPivot == UIWidget.Pivot.TopRight)
    55.         {
    56.             if (mPivot == UIWidget.Pivot.Left || mPivot == UIWidget.Pivot.Center || mPivot == UIWidget.Pivot.Right) v.y += 0.5f;
    57.             else if (mPivot == UIWidget.Pivot.BottomLeft || mPivot == UIWidget.Pivot.Bottom || mPivot == UIWidget.Pivot.BottomRight) v.y += 1f;
    58.         }
    59.  
    60.         if (targetPivot == UIWidget.Pivot.BottomRight || targetPivot == UIWidget.Pivot.Bottom || targetPivot == UIWidget.Pivot.BottomLeft)
    61.         {
    62.             if (mPivot == UIWidget.Pivot.Left || mPivot == UIWidget.Pivot.Center || mPivot == UIWidget.Pivot.Right) v.y -= 0.5f;
    63.             else if (mPivot == UIWidget.Pivot.TopLeft || mPivot == UIWidget.Pivot.Top || mPivot == UIWidget.Pivot.TopRight) v.y -= 1f;
    64.         }
    65.  
    66.         return v;
    67.     }
    68. }
     
  42. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    @mydingefnysen:

    I was looking at creating a similar thing, looks like you jumped on it. That seems about right. But when I was mentally mapping this out in my head I realized that doing this as part of the Update() only works in the simple case. If you are trying to use this sort of "anchoring" to layout nested complex things, the order in which they update would be critical.

    In other words, a bunch of nested sprites with them all using your FollowWidgetPivot (or other positioning logic). It wouldn't be hard to make it so all cases "just work" but you need to make sure the parent of any object is updated first.

    This means a different system is needed. One where a root object gets an Update and then recurses its children and doing any special layout logic.

    So one way to do this is to move your logic out of Update() and into some other method, say Layout(). Then create another component called... um... I dunno, something like UILayoutChildrenController (that too long?). In it's Update() you do a GetComponent for FollowWidgetPivot on itself and if there call Layout(). Then recurse through the hierarchy of children doing the same thing.


    David
     
    Last edited: Jan 5, 2012
  43. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    I'd change UIWidget widgetToFollow to be just a transform. I'd also avoid doing things like gameObject.transform because it's a slow operation (Unity does a GetComponent<Transform>() under the hood unless it has changed since pre-3.0). Caching this value works best. This is why I a lot of NGUI's classes have the transform cached (mTrans). Shortens the code too. :)
     
  44. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @nsxdavid: You can set the order of script execution and place this script to happen before or after normal updates as needed.
     
  45. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    @ArenMook That wouldn't help in this case. It's not the order of the script (it's just one script!). It's the order by object based on nesting.
     
  46. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Ah, I see what you mean. True, that would be tricky.
     
  47. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    Not too tricky really. I know my suggestion works because... well... I've done that a dozen or so times in other UI systems I've built. Another example: UIToolkit handles it this way. Sorta... it uses listeners on transform changes, which causes a cascade in the proper order. But same thing.

    So I've been playing around with NGUI and one thing I'm confused about. When I create a new sprite and select an Atlas for it, it auto-selects some default sprite from the atlas. That's fine. But when I pick the sprite I'm really after from the drop down, it doesn't correct the size so it's actually the size of the previous sprite. I have to go and manually determine the size from the Atlas prefab and then go back to the sprite object and fix it up by hand.

    Worse still... if it's a child object, you can't just type those numbers in since that's like a "local scale". So they are blown out by the parent's scale. I must be missing something here.

    In fact, more I think about it... seems just wrong to use scale for this at all. I mean there is a fundamental difference between the 1:1 size of the object and how you might want to scale it, right?
     
    Last edited: Jan 5, 2012
  48. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    After selecting your sprite, click the Make Pixel-Perfect button. No need to look up anything. NGUI won't auto-resize your sprite in case you manually scaled it.

    You also shouldn't be parenting sprites to other sprites (don't you get a warning about it?). Always parent widgets to game objects with a uniform scale. Your typical hierarchy will be:

    Code (csharp):
    1. Root ( scale of 1/(targetResHeight*0.5) )
    2. --- Window1 (scale 1)
    3. ------- UISprite1 (scale in pixels such as 400, 200, 1)
    4. ------- UISprite2 (scale in pixels)
    5. --- Window2 (scale 1)
    6. ------- UISprite1 (scale in pixels)
    7. ------- UISprite2 (scale in pixels)
     
  49. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    I'm confused how you make a nested composition if you can't do that. Even a button with a label? If everything is statically defined from some point, you can't make a clean nested heiarchy. If I move the button I gotta move the label. And that's just the simple case!

    (ps. no warning either, though that would have been of little consolation if it had :)
     
  50. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Button <-- will have a collider and your event scripts
    -- UILabel <-- text
    -- UISlicedSprite <-- background

    http://www.tasharen.com/?page_id=237

    Same clean hierarchy, you just don't parent widgets to other widgets. You parent widgets to a game object, and move the game object. :)
     
    Last edited: Jan 5, 2012
Thread Status:
Not open for further replies.