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. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    A PM I just received gave me a perfect idea for the next example: iTunes style playlist.
     
  2. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    It's a part of 1.28, now available for download via the PayPal link.

    It's fairly rudimentary. For example in order to make a widget expand and shrink in a loop, you can attach a TweenScale to it and check the "loop" parameter. There's also TweenPosition, TweenRotation, and TweenColor. TweenColor is capable of tweening widget colors, renderer material color, or light colors -- whatever it finds on the game object it's attached to.

    Usage via code is equally simple:
    Code (csharp):
    1. TweenColor.Begin(gameObject, duration, color);
    You can change the method of interpolation like so:
    Code (csharp):
    1. TweenColor.Begin(gameObject, duration, color).method = Tweener.Method.EaseInOut;
    UIState series of scripts have been updated to use the tweening scripts.

    I'll add an example for it in a bit.
     
  3. parkerdc

    parkerdc

    Joined:
    Aug 2, 2011
    Posts:
    10
    I bought all your packages from the app store except BT (PayPal). I will have to wait for the app store to get the update.

    I took the uistateposition, created a new class and added this code to the bottom of the update.

    Code (csharp):
    1.  
    2. if (Mathf.RoundToInt(mTrans.localPosition.x) == positions[index].x  Mathf.RoundToInt(mTrans.localPosition.y) == positions[index].y  Mathf.RoundToInt(mTrans.localPosition.x) == positions[index].z)
    3.  
    4. if (currentState < positions.Length) currentState += 1;
    5.  
    I created various positions that the logo falls into place and red player walks. Once they reach the position, continue onto the next one. They stop at the end.

    The other class I created was to cycle through positions, going back to the begining once reaching the end.


     
    Last edited: Jan 8, 2012
  4. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    I still say using Unity's built-in animation is your best bet for anything past simple tweening :)

    1.28 should be on the asset store tomorrow.
     
  5. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Hi Aren, the Trim support for TexturePacker seems to work great! Only this problem: every time when I reimport the TP Import TextAsset, all my sprite's sizes got reset back to pixel perfect. Is that a regression of previous bug? It's time consuming to go back and resize every sprite just because the atlas had some new stuff added to it.
     
  6. parkerdc

    parkerdc

    Joined:
    Aug 2, 2011
    Posts:
    10
    Thanks for the update. I was under the impression that there is a big overhead when using Unity's built in animation.

    Do you know of a good tutorial on how to use the built in animation?
     
    Last edited: Jan 8, 2012
  7. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @mindlube: That must be a regression bug. I'll track it down.

    @parkerdc: Nope, can't say I do... I learned it just by playing around with it. It's fairly simple though -- you get a graph, and if you are in Record mode, you can just move the timeline, move the objects into place, then hit Play and see it come alive.
     
  8. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Aren, I'm using 1.26 from the App Store. I just did a test, and the same happens for non-trimmed atlases as well. So I could just be confused what the normal behavior was though: I was sizing directly my UISprites, instead of parenting them to gameobject and scaling/transforming the parent instead.That would be more advisable, right?
     
  9. mydingefnysen

    mydingefnysen

    Joined:
    Dec 15, 2011
    Posts:
    51
    @arenmook: Thanks for your suggestions regarding how to best turn of widgets!

    A question, when adding a collider to a widget that was just created (in code), is there something special to keep in mind? Look at this short code for example:
    Code (csharp):
    1.  
    2. UILabel labelWidget = (UILabel)UIManager.AddUIWidget<UILabel>(labelRootGO, "notUsedForLabels");
    3. labelWidget.font = UIManager.GetUIFont(boldFont) as UIFont;
    4. labelWidget.text = "LABEL TEXT";
    5. labelWidget.MakePixelPerfect();
    6.  
    7. UIManager.AddCollider(labelWidget.gameObject);
    8.  
    The first to lines set the widget up through my simple UIManager (It creates a gameobject and adds it to the UI hierarchy (The root that has the UIPanel) and set the correct layer and so on), the second line just gets the right font.

    The problem is that the collider added by AddCollider gets a size of zero (the code is a copy of the stuff in NGUIMenu minus the editor code stuff). If I add it through the menu later in runtime everything is correct. Is it that the UIPanel has not yet updated the sprite and its size?

    Edit: It seems to work for UISprites.

    Edit2: labelWidget.visibleSize returns (0,0) but if I instead run labelWidget.font.CalculatePrintedSize I get the correct values.. I dont understand this, but it works the way I want it now, I think :)
     
    Last edited: Jan 8, 2012
  10. marjan

    marjan

    Joined:
    Jun 6, 2009
    Posts:
    563
    Hello,
    i just bought NGUI and am quite pleased with it so far. While i was trying to set up my GUI with it, i thought, oh well, why not try to make everything with it, and in my case that is.... tadaaaaaa, mobile joystick.
    You know, there is a joystick prefab in the mobile package (i guess), and since this is a GUI, it should be handled by any guysolution - or it ads up drawcalls.
    Furthermore, one could pimp it a bit.

    I guess some other users would appreciate this as well, as the one draw call gui is typically a mobile thingy.

    as Ngui uses C# only this evening i ported the unitys joystick.js to c#. Seems to work, i got no errors.
    But now i am stuck, as we need to replace everything concerning GUITexture (which this script relies on) to UISprite, or whatever you use. Its not much, one merely needs to retrieve the actual screenrepresentations RECT of the joystick texture.
    As for Pimping it up:
    The existing joystick ONLY works on mobile devices. Because of the input things. It would be much nicer to have additional MouseInput available at least in the editor, to test a game a bit there (For other machines, i actually cannot see any use in this) A relative restposition graphic would also by nice (i mean basically a circle underneath, that is static, but the user can see how much he moved the joystick (well actually the developer only needs to put an appropriate graphic underneath the joystick sprite)).
    Second thing to pimp would be the position of the joystick. Unitys solution is fixed. I like the idea of centering the joystick on Touchdown. So people with large hands have the center of it more to the middle of the screen.

    I will try to port it myself more, when i find the time (hard with two children). But i am not a too good coder especially not in C. If you think its a good idea to incorporate this, here is my joystick port so far:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. /// <summary>
    5. /// Attach this script to a child of a draggable window to make it tilt as it's dragged.
    6. /// Look at how it's used in Example 6.
    7. /// </summary>
    8.  
    9. public class JStickBoundary
    10. {
    11.     public Vector2 min = Vector2.zero;
    12.     public Vector2 max = Vector2.zero;
    13. }
    14.  
    15.  
    16. public class NGUIjoystick : MonoBehaviour
    17. {
    18.                     // A static collection of all joysticks
    19.  
    20.  
    21.     static private NGUIjoystick[] joysticks;                    // A static collection of all joysticks
    22.     static private bool enumeratedJoysticks=false;
    23.     static private float tapTimeDelta = 0.3f;                   // Time allowed between taps
    24.  
    25.     public bool touchPad;                                               // Is this a TouchPad?
    26.     public Rect touchZone;
    27.     public float deadZone = 0;                                          // Control when position is output
    28.     public bool normalize = false;                                  // Normalize output after the dead-zone?
    29.     public Vector2 position;                                            // [-1, 1] in x,y
    30.     public int tapCount;                                                // Current tap count
    31.  
    32.     private int lastFingerId = -1;                              // Finger last used for this joystick
    33.     private float tapTimeWindow;                                // How much time there is left for a tap to occur
    34.     private Vector2 fingerDownPos;
    35.     private float fingerDownTime;
    36.     private float firstDeltaTime = 0.5f;
    37.  
    38.     private GUITexture guiSprite;                                       // Joystick graphic
    39.     private Rect defaultRect;                                   // Default position / extents of the joystick graphic
    40.     private JStickBoundary guiBoundary = new JStickBoundary();              // Boundary for joystick graphic
    41.     private Vector2 guiTouchOffset;                             // Offset to apply to touch input
    42.     private Vector2 guiCenter;                                  // Center of joystick
    43.    
    44. /* 
    45. #if !UNITY_IPHONE  !UNITY_ANDROID
    46.  
    47.     void Awake () {
    48.         gameObject.active = false; 
    49.     }
    50.  
    51.    
    52. #else
    53.      */
    54.     void Start () {
    55.  
    56.         // Cache this component at startup instead of looking up every frame   
    57.         guiSprite = (GUITexture) GetComponent( typeof(GUITexture) );
    58.    
    59.         // Store the default rect for the gui, so we can snap back to it
    60.         // how do we find the drawing rect for this NGUI GameObject
    61.         defaultRect = guiSprite.pixelInset;
    62.    
    63.        
    64.         defaultRect.x += transform.position.x * Screen.width;// + guiSprite.pixelInset.x; // -  Screen.width * 0.5;
    65.         defaultRect.y += transform.position.y * Screen.height;// - Screen.height * 0.5;
    66.    
    67.         Vector3 initPos = new Vector3(0.0f, 0.0f, transform.position.z);
    68.         transform.position = initPos;
    69.        
    70.         if (touchPad) {
    71.             // If a texture has been assigned, then use the rect ferom the gui as our touchZone
    72.             if (guiSprite.texture)
    73.                 touchZone = defaultRect;
    74.         } else {               
    75.             // This is an offset for touch input to match with the top left
    76.             // corner of the GUI
    77.             guiTouchOffset.x = defaultRect.width * 0.5f;
    78.             guiTouchOffset.y = defaultRect.height * 0.5f;
    79.        
    80.             // Cache the center of the GUI, since it doesn't change
    81.             guiCenter.x = defaultRect.x + guiTouchOffset.x;
    82.             guiCenter.y = defaultRect.y + guiTouchOffset.y;
    83.        
    84.             // Let's build the GUI boundary, so we can clamp joystick movement
    85.             guiBoundary.min.x = defaultRect.x - guiTouchOffset.x;
    86.             guiBoundary.max.x = defaultRect.x + guiTouchOffset.x;
    87.             guiBoundary.min.y = defaultRect.y - guiTouchOffset.y;
    88.             guiBoundary.max.y = defaultRect.y + guiTouchOffset.y;
    89.         }
    90.  
    91.     }
    92.    
    93.     void Disable () {
    94.         gameObject.active = false;
    95.         enumeratedJoysticks = false;
    96.     }
    97.  
    98.  
    99.     void ResetJoystick () {
    100.         // Release the finger control and set the joystick back to the default position
    101.         guiSprite.pixelInset = defaultRect;
    102.         lastFingerId = -1;
    103.         position = Vector2.zero;
    104.         fingerDownPos = Vector2.zero;
    105.         /*
    106.         if (touchPad)
    107.             guiSprite.color.a = 0.025f;
    108.         */
    109.     }
    110.  
    111.     bool IsFingerDown () {
    112.         return (lastFingerId != -1);
    113.     }
    114.    
    115.     void LatchedFinger (int fingerId) {
    116.         // If another joystick has latched this finger, then we must release it
    117.         if (lastFingerId == fingerId)
    118.             ResetJoystick ();
    119.     }
    120.    
    121.     void Update () {   
    122.         if (!enumeratedJoysticks) {
    123.             // Collect all joysticks in the game, so we can relay finger latching messages
    124.             joysticks = FindObjectsOfType(typeof(NGUIjoystick)) as NGUIjoystick[];
    125.            
    126.             enumeratedJoysticks = true;
    127.         }  
    128.        
    129.         int count = Input.touchCount;
    130.    
    131.         // Adjust the tap time window while it still available
    132.         if (tapTimeWindow > 0)
    133.             tapTimeWindow -= Time.deltaTime;
    134.         else
    135.             tapCount = 0;
    136.    
    137.         if (count == 0) {
    138.             ResetJoystick ();
    139.         } else {
    140.             for (int i = 0; i < count; i++) {
    141.                 Touch touch = Input.GetTouch (i);          
    142.                 Vector2 guiTouchPos = touch.position - guiTouchOffset;
    143.    
    144.                 var shouldLatchFinger = false;
    145.                 if (touchPad) {            
    146.                     if (touchZone.Contains (touch.position))
    147.                         shouldLatchFinger = true;
    148.                     } else if (guiSprite.HitTest (touch.position)) {
    149.                         shouldLatchFinger = true;
    150.                     }
    151.    
    152.                     // Latch the finger if this is a new touch
    153.                     if (shouldLatchFinger  (lastFingerId == -1 || lastFingerId != touch.fingerId)) {
    154.                
    155.                     if (touchPad) {
    156.                         Color joystickcolor =  renderer.material.color;
    157.                         joystickcolor.a = 0.15f;
    158.                         guiSprite.color = joystickcolor;
    159.  
    160.                         lastFingerId = touch.fingerId;
    161.                         fingerDownPos = touch.position;
    162.                         fingerDownTime = Time.time;
    163.                     }
    164.                
    165.                     lastFingerId = touch.fingerId;
    166.                
    167.                     // Accumulate taps if it is within the time window
    168.                     if (tapTimeWindow > 0) {
    169.                         tapCount++;
    170.                     } else {
    171.                         tapCount = 1;
    172.                         tapTimeWindow = tapTimeDelta;
    173.                     }
    174.                                            
    175.                     // Tell other joysticks we've latched this finger
    176.                     foreach ( NGUIjoystick j in joysticks ) {
    177.                         if ( j != this )
    178.                             j.LatchedFinger( touch.fingerId );
    179.                     }                      
    180.                 }              
    181.    
    182.                 if (lastFingerId == touch.fingerId) {
    183.                     // Override the tap count with what the iPhone SDK reports if it is greater
    184.                     // This is a workaround, since the iPhone SDK does not currently track taps
    185.                     // for multiple touches
    186.                     if (touch.tapCount > tapCount)
    187.                         tapCount = touch.tapCount;
    188.                
    189.                     if (touchPad) {
    190.                         // For a touchpad, let's just set the position directly based on distance from initial touchdown
    191.                         position.x = Mathf.Clamp ((touch.position.x - fingerDownPos.x) / (touchZone.width / 2), -1, 1);
    192.                         position.y = Mathf.Clamp ((touch.position.y - fingerDownPos.y) / (touchZone.height / 2), -1, 1);
    193.                     } else {                   
    194.                         // Change the location of the joystick graphic to match where the touch is
    195.                         position.x = (touch.position.x - guiCenter.x) / guiTouchOffset.x;
    196.                         position.y = (touch.position.y - guiCenter.y) / guiTouchOffset.y;
    197.                     }
    198.                
    199.                     if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
    200.                         ResetJoystick ();
    201.                 }          
    202.             }
    203.     }
    204.    
    205.     // Calculate the length. This involves a squareroot operation,
    206.     // so it's slightly expensive. We re-use this length for multiple
    207.     // things below to avoid doing the square-root more than one.
    208.     float length  = position.magnitude;
    209.    
    210.    
    211.     if (length < deadZone) {
    212.         // If the length of the vector is smaller than the deadZone radius,
    213.         // set the position to the origin.
    214.         position = Vector2.zero;
    215.     }
    216.     else {
    217.         if (length > 1) {
    218.             // Normalize the vector if its length was greater than 1.
    219.             // Use the already calculated length instead of using Normalize().
    220.             position = position / length;
    221.         }
    222.         else if (normalize) {
    223.             // Normalize the vector and multiply it with the length adjusted
    224.             // to compensate for the deadZone radius.
    225.             // This prevents the position from snapping from zero to the deadZone radius.
    226.             position = position / length * Mathf.InverseLerp (length, deadZone, 1);
    227.         }
    228.     }
    229.    
    230.     if (!touchPad) {
    231.         // Change the location of the joystick graphic to match the position
    232.         //guiSprite.pixelInset.x = (position.x - 1) * guiTouchOffset.x + guiCenter.x;
    233.         //guiSprite.pixelInset.y = (position.y - 1) * guiTouchOffset.y + guiCenter.y;
    234.     }
    235. }
    236.  
    237. }
    238.  
    239. //#endif
    240.  
    241.  
     
  11. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @mindlube: Generally the game object container for your widgets will have a scale of 1, and your sprites will be in pixel coordinates (say 400, 200, 1). In any case sprites shouldn't get re-sized on atlas import. If that's happening, I will fix it tonight.

    @mydingefnysen: Yes, take a look at how I add colliders via the menu command in NGUIMenu, line 58. I can move this functionality outside of the Editor if you need to add stuff dynamically in-game, but I would advise you to create "template" widgets that you will create copies of via Instantiate and fill in their data dynamically instead. That's how I create the backpack in Example 3 (the orc).

    Edit: Oh, I see you already used the code from there. Nevermind. :)
     
  12. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @marjan: Porting OnGUI code to use NGUI might be a bit of a challenge, considering OnGUI stuff is all in-code while NGUI is mostly visual. The way textures are drawn in particular is quite different as NGUI likes to work with atlases, or at least materials (via UITexture), rather than raw textures directly. That said, if you figure it all out, I'd love to see. :)
     
  13. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    For the record, I'm porting from UIToolkit to NGUI. Process: Rip everything out and rebuild it. This is not the fault of NGUI, it's just that it works so much differently (and better, IMHO). I say this having spent a considerable amount of time contributing to the UIToolkit codebase!

    David
     
  14. mydingefnysen

    mydingefnysen

    Joined:
    Dec 15, 2011
    Posts:
    51
    @arenmook: well yes, Im having problem adding colliders in runtime right after a widget has been created. reading visibleSize gives zero on UILabels even though font and text has been set. Running font.CalculatePrintedSize gives correct (I think) values but not correct ones on multiLine labels it seems.

    Edit: if I add a collider by code in runtime by pressing a button its wrong the first time, but if I manually delete the collider in the inspector and then add the collider back again, its correct. weird stuff :) dont know if its my code or not (could be, its way past brain-time for me now, good night! :)
     
    Last edited: Jan 9, 2012
  15. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    @ArenMook hey i just tried 1.28 with flash and loadLevel and it works good job :D , but im getting this error

    Anyways doesnt seem to break anything :)

    Code (csharp):
    1. A script behaviour has a different serialization layout when loading. (Read 32 bytes but expected 36 bytes)
    2. Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?
    3. LogCallStackError
    4.     at com.unity::UnityNative$/Ext_Flash_LogCallstack()
    5.     at com.unity::UnityNative$/_Z17DebugStringToFilePKciS0_iiii()
    6.     at com.unity::UnityNative$/_ZN14SerializedFile10ReadObjectEli18ObjectCreationModebPP8TypeTreePbPP6Object()
    7.     at com.unity::UnityNative$/_ZN17PersistentManager26LoadFileCompletelyThreadedERKSsPlS2_ibP12LoadProgress()
    8.     at com.unity::UnityNative$/_ZN21PreloadLevelOperation7PerformEv()
    9.     at com.unity::UnityNative$/_ZN14PreloadManager26UpdatePreloadingSingleStepEv()
    10.     at com.unity::UnityNative$/_Z10PlayerLoopbb()
    11.     at com.unity::UnityNative$/NativeExt_PlayerLoop()
    12.     at com.unity::UnityContentInternal/playerLoop()
    13.     at com.unity::UnityContent/onEnterFrame()
     
  16. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @hjupter: Thanks, I know exactly what's causing it. I'll fix it.

    @mydingefnysen: It's likely just the order of initialization there. I'll have a look at it in a bit.
     
  17. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    1.28b is up with a bunch of small fixes and play style option for the tweener -- Once, Loop, and PingPong. Self-explanatory, I think. :)
     
  18. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    Great work!

    I'm finding things are getting implemented even before I know I need them. :D
     
  19. gregmax17

    gregmax17

    Joined:
    Jan 23, 2011
    Posts:
    186
    How do I change text/label via code? I am using UnityScript

    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4. var labelTrans : Transform;
    5.  
    6. function Start()
    7. {
    8.     var uiLabel : UILabel = labelTrans.GetComponent("UILabel") as UILabel;
    9.     uiLabel.text = "TEST";
    10. }
    11.  
    This will give me an error saying that UILabel doesn't exist.
     
  20. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    You cant access UILabel from javascript since its a c# class in order to do that you have to put ngui scripts inside plugins folder but i personally wont do that as when you update ngui you will have to move scripts each time...

    This might help you
    http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html
     
  21. gregmax17

    gregmax17

    Joined:
    Jan 23, 2011
    Posts:
    186
    @hjupter
    Ok, this does help a bit, but I am still not clear on how to access the UILabel.text property even if I were to use C#. Can you please provide a small code sample?
     
  22. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    what you did is fine but for c# would be:

    Code (csharp):
    1. UILabel  uiLabel = labelTrans.GetComponent<UILabel>() as UILabel;
    2. uiLabel.text = "TEST";
     
  23. gregmax17

    gregmax17

    Joined:
    Jan 23, 2011
    Posts:
    186
    I am still getting the error: "the type or namespace name UILabel could not be found". I moved the script "Main" in the folder "Standard Assets", and attached the script to a empty game object in the scene. This is what I have:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class Main : MonoBehaviour
    6. {
    7.     public Transform labelTrans;
    8.  
    9.     // Use this for initialization
    10.     void Start()
    11.     {
    12.         UILabel uiLabel = labelTrans.GetComponent<UILabel>() as UILabel;
    13.     }
    14. }
    15.  
    Is there something I am doing wrong?
     
  24. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    You did wrong moving your script to "Standard assets"

    "Scripts in one of these folders can't directly access scripts outside these folders."

    Move your script to any other folder, if you a folder called "Scripts" that one should be fine
     
  25. gregmax17

    gregmax17

    Joined:
    Jan 23, 2011
    Posts:
    186
    @hjupter
    That did it, thank you!
     
  26. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    @ArenMook: more work for you :p ... there is a bug on Tweener class when export to Flash

    Code (csharp):
    1. \Tweener.as(80): col: 41 Error: Implicit coercion of a value with static type Object to a possibly unrelated type UnityEngine:_Object.
    2.  
    EDIT: I commented this line //if (comp == null) comp = go.AddComponent<T>(); and compiled everything fine
     
    Last edited: Jan 9, 2012
  27. Quickfingers

    Quickfingers

    Joined:
    Aug 29, 2009
    Posts:
    268
    Hey ArenMook : 1.28b Tweener class isn't compatible with Flash exporter. Just a heads up :)
     
  28. mydingefnysen

    mydingefnysen

    Joined:
    Dec 15, 2011
    Posts:
    51
    Been doing some more tests by copying what you did in UITooltip. What I dont get is that in UITooltip we get the correct size of mSize, but when I do CalculatePrintedSize in the same way, the returned y value is always 1, and x varies depending on line length, as if it was not a multiline. Visually it is wordwrapped though.

    Edit: I found the problem. In UITooltip the text is not wordwrapped by the internal UILabel wordwrapping but instead manually by inserting \n. So of course what I needed to do was to not pass the UILabel.text (which is never wordwrapped) into CalculatePrintedSize, but instead do this:

    Code (csharp):
    1. CalculatePrintedSize(textFieldWidget.font.WrapText(textFieldWidget.text, textFieldWidth / textFieldWidget.cachedTransform.localScale.y, true, false).Replace("\\n", "\n"), false);
    Not very intuitive =) No need to fix the code (even though it would be nice to be able to use .visibleSize directly) but a note about it in UILabel or something would save some time for us code-implementers :)
     
    Last edited: Jan 9, 2012
  29. LKIM

    LKIM

    Joined:
    Feb 17, 2011
    Posts:
    40
    Just jumping in on the end of this thread, not sure if this question was already answered.

    Is it possible for EZGUI and NGUI to coexist? We have an application that we have already developed with EZ GUI, but there are a fair number of things about it that didn't work quite smoothly, and we're looking into using NGUI as either a complete replacement, or ideally in conjunction with EZ GUI.

    I tried to import both of these into a test solution, but there are many classes with the same names.

    Thanks,
    Liron

    EDIT: Just FYI
    I've been playing with the examples, and I'm getting the following error. Probably just need to add a null check.

    NullReferenceException
    UnityEngine.Transform.get_localPosition ()
    UIStatePositions.OnState (Int32 state) (at Assets/NGUI/Scripts/Interaction/UIStatePositions.cs:32)
    UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
    UISend:Send(String, Int32) (at Assets/NGUI/Scripts/Internal/UISend.cs:32)
    UISend:Send(Int32) (at Assets/NGUI/Scripts/Internal/UISend.cs:14)
    UISendStateOnClick:OnClick() (at Assets/NGUI/Scripts/Interaction/UISendStateOnClick.cs:15)
    UnityEngine.GameObject:SendMessage(String, SendMessageOptions)
    UICamera:processTouch(MouseOrTouch, Boolean, Boolean) (at Assets/NGUI/Scripts/UI/UICamera.cs:394)
    UICamera:Update() (at Assets/NGUI/Scripts/UI/UICamera.cs:284)
     
    Last edited: Jan 9, 2012
  30. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @mydingefnysen: visibleSize is a relative value. You need to multiply it by the local transform to get pixel values. Y value of '1' simply means '1 line height'. I added a note about this to the comments above this function 2 versions ago.

    @LKIM: NGUI was designed to replace EZGUI, so not easily. Which example are you getting that exception in? The only way that's possible is if the object's transform has been destroyed, and that doesn't seem likely.

    @quickfingers and @hjupter: I'll fix the flash compilation, thanks!
     
  31. mydingefnysen

    mydingefnysen

    Joined:
    Dec 15, 2011
    Posts:
    51
    @arenmook: yes, but since the localTransform.y in a multiline UILabel is the size of one line it doesnt help, or am I doing it the wrong way?
     
  32. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    localTransform.y should be your font size in a pixel-perfect label. Ie: font size 28 will have localTransform.y of 28.

    Flash is driving me up the wall with the inability to convert Object to UnityEngine.Object.
     
  33. mydingefnysen

    mydingefnysen

    Joined:
    Dec 15, 2011
    Posts:
    51
    yes, but what I dont get is how AddCollider works on wrapped UILabels, since visibleSize.y*localTransform.y is the height of just one line. I got it to work with the code I posted earlier so its no problem really, Im just curious :)
     
  34. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    I've modified UILabel.visibleSize to process the text right then and there, rather than in OnFill. This will give you the expected values, with new lines and all. I've also added a property, UILabel.processedText. This will be in 1.28c that I'll put up as soon as I figure out why scale tweening doesn't seem to work quite right in Flash.
     
  35. LKIM

    LKIM

    Joined:
    Feb 17, 2011
    Posts:
    40
    OK so be it, so we'll have to decide which one we want to go with moving forward.

    Some things I'm not seeing in NGUI that EZ GUI provides - are these easy to implement?
    • Scroll List with selectable items
      It seems that you can handle a scroll list pretty well, but I don't see any infrastructure for actually selecting one (or several) of these items. Is it easy enough to extend the UIGrid to be able to manage this? Is this something that you have planned for a future release?​
    • Scroll list with items of different sizes
      The UIGrid that you have currently seems to define a fixed size for all of the items. We probably want a fixed amount of space between items, but each item could be a different size. What about if the items scale on hover/selection? Would it be difficult to make the scroll list autoposition all the items if one of the item's scale changes?​
    • Show/Hide panels
      EZ GUI has a lot built into it for handling the showing and hiding of panels. A lot of this happens automatically when things are hooked up correctly. (This is actually pretty annoying to do correctly, but that's besides the point.) Currently, we have a configuration of panels for all the app settings which simulate a hierarchical dropdown list. Is there an easy way to implement something like that in NGUI?​
      • Menu 1
        • Setting B
        • Menu 2
          • Setting C
          • Setting D
      • Menu 3
        • Setting E
        • Setting F
      • Setting A

    Probably gonna ask more as I come across it.

    Thanks,
    Liron

    PS I can't replicate that null error, so I can't remember what example it was from.
     
  36. mydingefnysen

    mydingefnysen

    Joined:
    Dec 15, 2011
    Posts:
    51
    @arenmook: You're super awesome! :D
     
  37. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @LKIM:

    A "panel" with NGUI would be a simple game object with or without a UIPanel script on it. (with means it's a separate draw call, without means it's drawn at the same time as everything else). Just enable or disable the game object recursively to turn the "panel" on/off.

    UICamera.selectedObject tells you the last selected object. If you want your own custom selection, try attaching a script that does something in OnSelect, like so:

    Code (csharp):
    1. public class UISelectable : MonoBehaviour
    2. {
    3.     static public GameObject selection;
    4.  
    5.     public void OnSelect (bool selected)
    6.     {
    7.         selection = selected ? gameObject : null;
    8.     }
    9. }
    UIGrid is a very simple 59-line-of-code example of how to dynamically position items. You can write your own to handle dynamic sizing. Use the widget's visibleSize property, multiply it by widget's local transform scale and you will have your size in pixels.
     
  38. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Unity's Flash export is just... epic. Apparently structs are passed by reference rather than by copy in Flash.
    Code (csharp):
    1. mBaseScale = transform.localScale;
    2. Debug.Log(mBaseScale);
    3. mTargetScale = NGUITools.Multiply(mBaseScale, amount); // amount is 1.1
    4. Debug.Log(mBaseScale);
    Results in:
    Code (csharp):
    1. (1.0, 1.0, 1.0)
    2. (1.1, 1.1, 1.1)
    I had to create a temporary variable for flash in order to "fix" this.
     
    Last edited: Jan 9, 2012
  39. markhula

    markhula

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

    I'm having some issues with my use of OnState func.
    The problem is I have a bunch of icons and once you select one it scrolls other's onto the screen - this works fine.
    The issue is if you hold your finger on the selected icon then it's onstate will be called with 0 (as you leave it's collision box) and as it's moving your finger (in the same position) could now hit another icon and cause it's onstate to be 1.
    Hope you see what I mean. I could do some tacky thing by turning collisions off etc.But effectively your finger could be on another icon even though it hasn't moved. Any ideas of a neat solution so that an icon's state can be tested for 'held' and only on release that status is cleared.

    Cheers
     
  40. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    Hey Aren, i mentioned this before ngui drop fps when having a game scene behind in flash only, look at this http://www.ninjapvp.com/game/flash/ there is a stamina bar/yellow bar when you press SHIFT the character star running and the bar begins to empty so its a uisliced updating its scale and for me drops like 20 fps, this is my pc specs intel core i7 3.2ghz (8 cores), 10gb ram, 2gb video card
     
  41. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @markhula: OnState stuff is currently scheduled for a revamp in 1.3. You are likely mixing more than one state sending script there, such as UISendState and UISendStateOnClick. My suggestion -- dont use them. Just write a simple script that implements something in OnPress or other event listener function. If you open up UISendState itself, it's 24 lines of code, with only 2 one-line functions. It's pretty easy to modify it to your own needs.

    @hjupter: Yeah it seems dynamic mesh creation in flash is very, very slow. You can improve the framerate by not changing the value every frame, but instead at intervals (for example twice per second).
     
  42. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    1.28c is up with fixes for flash and some other things I noted above.
     
  43. Kalagaraz

    Kalagaraz

    Joined:
    Aug 26, 2009
    Posts:
    46
    Aren:

    <Link removed>

    I can't just can't seem to get the tiles to align seamlessly. If you could take a look I would appreciate it.
     
    Last edited by a moderator: Jan 9, 2012
  44. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Your scene in there is blank. Next time please PM or email me instead of posting NGUI code on a public forum.
     
    Last edited: Jan 9, 2012
  45. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    aren forgot to tell you on my game i have a key to disable the main ngui so you can see the difference of fps, the key is END
     
  46. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Doesn't help, it's always at ~62 no matter what. I have a GTX 570 though, you would have to overload it fairly extensively for it to chug.
     
  47. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    BTW folks.,..

    If you are using NGUI, and loving it and the support you get... head on over to the asset store and write a glowing review. Be sure to give enough detail so other devs can understand why its so good. Don't forget the 5 stars too. The developer would be both deserving and appreciative, I'm sure.

    I am allowed to review-beg because I am merely a customer too. :)

    David
     
  48. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    Agree, Im gonna do it now!
     
  49. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Thank you, I appreciate that -- but in all honesty one thing that's better than reviews is feedback on what to improve. :) Over the weekend someone rated NGUI down without leaving any suggestions on how to make it better, and that's a bit disappointing. Thank you everyone in this thread, your feedback has been invaluable so far.
     
  50. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    seems like i cant review because i bought it on paypal.... anyways the best $65 ive spent on asset store so far
     
Thread Status:
Not open for further replies.