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

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Ok, well I tried upgrading to the newest version...that only creates an additional problem for me.

    1) There's a single-level prefab I have with a Panel and a UILabel that whenever I spawn it now, says "Unable to find an appropriate root to add the widget. Please make sure that there is at least one game object above this widget!". Actually, dragging this prefab out into the scene no longer displays the text in it....very weird.
    No idea what that means or how to fix it.
    2) How exactly do I take adtantage of the "working with Timescale zero" stuff? My code is in TriggerEnter which obviously doesn't work at that time.

    Do you have a forum for this? Or is this the best place to be asking questions?
    -Brian
     
  2. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Forum: http://www.tasharen.com/?post_type=forum

    Make UILabel a child of your panel, and you will fix #1.

    Timescale zero stuff is invisible to you. NGUI simply works as it did before even if the time is paused. That said, trigger enter won't be called. The game is paused after all.
     
  3. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    So then....if you don't use triggers or colliders....how exactly do you detect which elements were clicked on the pause menu?
     
  4. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Raycast. OnTriggerEnter has nothing to do with raycasts. :)
     
  5. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Btw in any case not sure why you are asking about this... when developing for NGUI you won't be doing any raycasts of your own. Want to add some code that runs when something gets clicked on? You shouldn't add any trigger enters. Just add "void OnClick()".
     
  6. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Never mind, I will try this.
     
  7. OmniverseProduct

    OmniverseProduct

    Joined:
    Feb 26, 2012
    Posts:
    1,568
    Just want to say that I am Definitely going to buy this when I can afford it, good work.
     
  8. Singyu Jo

    Singyu Jo

    Joined:
    Oct 18, 2010
    Posts:
    6
    Depth of SimpleTexture doesn't work properly.
    I've set depth of some SimpleTexture to 10 and other UIs(sliced sprites) to 0.
    But, Simple texture always behind by them.
    I think it's a bug.
    plz, fix it :)
     
  9. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,204
    @singyu jo: I thought depth only worked for things in the same atlas. Otherwise, you need to use the Z to adjust what is in front/back
     
  10. ojuzu

    ojuzu

    Joined:
    Jun 29, 2006
    Posts:
    67
    Hi ArenMook. I just purchased NGUI and it's been absolutely awesome so far with just one small issue. I use FingerGestures for all of my input and I'm trying to determine the best way to have things coexist between it and NGUI. I've read posts from others saying that they can be used together but I'm having issues with FingerGesture events firing. This may be more of a question for the creator of FingerGestures but since you mentioned in a post that they could be used together I'm just curious if you know off the top of your head what I should do to separate the two input systems.

    Thanks!

    Dennis
     
  11. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @Shingyu: As Jaimi mentioned, depth is for sorting widgets that use the same atlas. Different atlases (or materials for that matter) require you to adjust the Z coordinate to determine what's in front.

    @ojuzu: Unfortunately I don't have FingerGestures so I'm not going to be of much help here. I hope someone who has used both can give you a hand.
     
  12. ojuzu

    ojuzu

    Joined:
    Jun 29, 2006
    Posts:
    67
    Thanks for the quick response. No problem at all. I'll look into it and if I find a simple way to separate them I'll post here since I'm sure others could benefit. And if anyone else has suggestions I'd love to hear them as well!
     
  13. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Speaking of quick responses. Just so that it's out there, I am in San Francisco for a week (GDC 2012), so my responses will be way slower than usual. I have wifi in my hotel, so I'll answer whatever questions I can in the evening, but that's about it.
     
  14. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Hi Aren,

    I have an object in my game where when the player clicks it, I want a few buttons to pop up next to it. I've got this working using UIButtonTween and Tweenposition. However, is there any way for me to make it so that if the player clicks anything else in the screen (anything except the object that made the buttons pop up) the buttons disappear again off screen?
     
  15. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    You can use either OnSelect(false), or set UICamera.fallThrough to a game object you want to handle events that don't fall on any collider.
     
  16. yuewah

    yuewah

    Joined:
    Sep 21, 2009
    Posts:
    98
  17. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Hmm... technically the sprite is correct. Since the border goes from 10 to 20 pixels, the same size widget will look different. The widget would need to double in size to compensate... But I see why it's an issue for you. I'll try to think of an elegant solution. Thanks for the pic, it helps a lot!
     
  18. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Thanks for the quick reply ... can you explain OnSelect(false)? Is it a function of a particular NGUI object? Could you give me a quick bit of code to demonstrate its use?
     
  19. franbon2005

    franbon2005

    Joined:
    Mar 19, 2009
    Posts:
    86
    Like i have tested before the NGUI and the RPG KIT (sleglik) in the same time that is not possible !!

    Both of them use the Direction variable and when you change in one side or in other you have errors or troubles in the project!!

    Have you a solution ?? (i buy the both project )
     
  20. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @Rajmahal: Look at UIInput. It uses OnSelect. Basically every object gets OnSelect (true) when it's clicked on, and OnSelect(false) when something else is clicked on.

    @franbon2005: Tell Sleglik to change his global Direction class to something else -- whether making it a part of a namespace, or just change its name.
     
  21. ojuzu

    ojuzu

    Joined:
    Jun 29, 2006
    Posts:
    67
    I posted over in the FingerGestures thread about this issue and William was able to explain a nice and simple way to filter out FingerGesture events from NGUI's events. If anyone else needs to implement this functionality the info can be found here: http://forum.unity3d.com/threads/95...ur-fingertips!?p=850535&viewfull=1#post850535
     
  22. yuewah

    yuewah

    Joined:
    Sep 21, 2009
    Posts:
    98
    UITiledSprite also have the same problem.
     
  23. mohydineName

    mohydineName

    Joined:
    Aug 30, 2009
    Posts:
    301
    Hi,

    What is the best way to remove a listener on a specific delegate for UIEventListener?
     
  24. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Instead of += use -=.
     
  25. S0ULART

    S0ULART

    Joined:
    Jun 14, 2011
    Posts:
    131
    does NGUI support custom fonts? / bitmap fonts importing?
     
  26. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    It's the only way to do fonts, yes.
     
  27. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    @ArenMook... just a thought... any chance that you could potentially add some functionality along the lines of what Owlchemy Labs have done with Multiplatform Toolkit? So on a UISprite for example, you could assign one sprite if device is an iPad2, and another if running on an iPhone 4S? I'm in the process of trying to adapt an iPad game (using NGUI) to run on iPhone 4S, and attempting to get my head around bringing in sprites created with different aspect ratios in mind, changing their position on screen (e.g. "everything -100 pixels if device = blah").

    Was thinking about buying Multiplatform Toolkit, but watching the video, I'm not sure yet that it will work with NGUI as it's more about replacing GameObjects rather than loading different content into them. I might be totally off on that though - I really need to watch their videos again.

    Anyway... like I said, just sharing a thought :)
     
  28. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    You can replace an entire atlas by using the "replacement" parameter. Same with fonts. In fact, the most flexible way of doing multi-platform stuff is to have a dummy atlas that points to a real atlas (and dummy font pointing to a real font). Then when creating widgets, point to the dummy one. This makes replacing this atlas/font trivial -- just change the parameter on the dummy atlas/font to point to another one (ie: HD one), and all widgets will update automatically.
     
  29. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    Hi ArenMook,

    is there any way, using UIButtonMessage, to identify from the "target function" who is the button that sended the message?

    I need to find a way to understand, from receiver, what button was clicked.
    If is not possible I think that you can extend UIButtonMessage class adding a new string attribute called "returnedValue" that can be used to send information to the receiver... for example we can place there a unique identifier. :)

    What do you think about this?

    Thanks
    Kenshin
     
  30. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    UICamera.lastHit.collider
     
  31. Legacy

    Legacy

    Joined:
    Oct 11, 2011
    Posts:
    651
    Hey aren, wondering if you could do a tutorial on how you setup that character equipment example. I was going to adapt it into a system i built for abilities etc but really couldn't find a pattern in how it worked.
     
  32. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
  33. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    You should consider doing some tutorials for things like this - possibly outside of the main (essential), free tutorials that you do now. Kind of like "extra/advanced training" that you could sell in a similar way to the iTween videos that PixelPlacement sells.
     
  34. MindJuice

    MindJuice

    Joined:
    Jun 10, 2009
    Posts:
    18
    Hi,

    I've already purchased NGUI for my own use on games, but I may be able to use it at work for a non-game project in Unity if it can do one certain thing I need.

    Is the following possible with NGUI:

    * Download a PNG file from a server (I can use WWW class for this) and save to a local file
    * Load PNG and use it in a button, slider, background, etc. in NGUI (using only code/API with no visual interaction)

    I can also use the WWW class to load the PNG from file as in this example, but using a URL like this file://image.png

    http://unity3d.com/support/documentation/ScriptReference/WWW.html

    Ideally the PNG could be either a single standalone PNG or alternatively a texture atlas, assuming I also download the associated JSON data file.

    Thanks,


    Ken
     
  35. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Download Save -- this is something you can do using Unity, it's not really a UI task.

    Load a PNG and use it as a button -- well, yes -- keep in mind anything can be a button as long as it has a collider. You won't be able to load a PNG and add it to an atlas, but you can load a PNG and use it as-is on a UITexture.
     
  36. Fordeka

    Fordeka

    Joined:
    Aug 18, 2011
    Posts:
    78
    Hey Aren, should the hard clip on a panel affect how objects under it in a grid are respositioned? Sometimes if I reposition or move the grid undernearth the objects start where I would expect but sometimes they all get offset by quite a bit.
     
  37. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Switch to soft, adjust the padding, then switch back. See if that helps.
     
  38. wccrawford

    wccrawford

    Joined:
    Sep 30, 2011
    Posts:
    2,039
    I'm trying to update NGUI to the latest version from the Asset Store, and it won't update. The button just says 'please wait' and nothing ever happens.

    Does anyone have any idea why?
     
  39. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Asset Store can be temperamental at times. Try closing the window and coming back to it.
     
  40. wccrawford

    wccrawford

    Joined:
    Sep 30, 2011
    Posts:
    2,039
    Sorry to have bothered you.

    I actually even reinstalled Unity. Turns out it was a combination of 2 things. 1 was Eset messing with things. The other was that I wasn't logged into the app store, but it doesn't *tell* you that unless you go to the page with all the assets you own. Logging in fixed it.

    Thanks for responding!
     
  41. MindJuice

    MindJuice

    Joined:
    Jun 10, 2009
    Posts:
    18
    Regarding the download, I wasn't asking a question about that, just pointing out what I am doing (using WWW class to download a PNG to a local file), and that part is working fine.

    Good to hear that using the PNG as a texture is possible, but I haven't been able to make it work yet.

    Three followup questions:

    1. I'm trying to create a UITexture now in C# code, but the constructor always returns null. Is there something else I need to do?

    Code (csharp):
    1.     UITexture image = new UITexture();  // image is always null
    2. I see you have a lot of documentation on using the Unity interface to build UIs, but I can't find any examples of creating NGUI objects programmatically. Are there any?

    3. Is there any API documentation or explanation of how the pieces are supposed to work together?

    Thank you.

    Ken
     
  42. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    UITexture is a component, and you add it like any other component in Unity -- via AddComponent. I made it easier, though:

    Code (csharp):
    1. NGUITools.AddWidget<UITexture>(parentGameObject);
    This will add a child game object, add a UITexture to it, and reset its transform to default values.

    Edit: Code documentation is in code. All functions and classes are commented, and the UICreateWidgetWizard creates everything programmatically, so it's a good source of "oh, so this is how it's done".
     
    Last edited: Mar 9, 2012
  43. MindJuice

    MindJuice

    Joined:
    Jun 10, 2009
    Posts:
    18
    Ah...right...thanks. This is what I get for simply starting off by hacking at NGUI without properly learning Unity concepts first.

    Unity newb here, but lots of programming and game dev experience elsewhere, so apologies as I learn!

    I was able to make it work with this:
    Code (csharp):
    1. GameObject textureObj = new GameObject();
    2. UITexture texture = (UITexture)textureObj.AddComponent("UITexture");
    3. textureObj.transform.parent = gameObject.transform;
    4.  
    5. Material newMat = Resources.Load("transp", typeof(Material)) as Material;
    6. texture.material = newMat;
    7. texture.material.mainTexture = www.texture;
    8. texture.MakePixelPerfect();
    9.  
    I borrowed an existing Material with a Shader from RageSpline that handled the transparent image I was loading.
     
  44. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    With the professional version, does that mean the normal version doesn't have source code? Or does it just mean you only ever get the current source and no GIT?
     
  45. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    Normal version includes source code (and it's very easy to understand and modify). You just don't get GIT access, so you may have to wait a little longer to get updated versions and have to do a little more work to merge any changes you make when a new version is released.
     
  46. petrucio

    petrucio

    Joined:
    Aug 30, 2011
    Posts:
    126
    Nice and easy to use numeric input. Define min and max values and increment, optionally add an AudioClip to play on FormatExceptions, setup two buttons to send IncreaseStart/Stop and DecreaseStart/Stop messages on Press and Release, and it's good to go:



    You will need to change the signature of the UpdateLabel function on the UIInput.cs file to
    Code (csharp):
    1. virtual protected void UpdateLabel ()
    .

    UINumEdit.cs:
    Code (csharp):
    1.  
    2. //----------------------------------------------
    3. // UINumEdit NGUI Extension by Petrucio @ Pangas Entertainment
    4. // http://creativecommons.org/licenses/by-sa/3.0/
    5. // Copyright © 2012 Pangas Entertainment
    6. //----------------------------------------------
    7.  
    8. using UnityEngine;
    9. using System.Collections;
    10.  
    11. /// <summary>
    12. /// Editable numeric input field
    13. /// </summary>
    14.  
    15. [AddComponentMenu("NGUI/UI/Input (Numeric)")]
    16. public class UINumEdit : UIInput
    17. {
    18.     public float minValue   = 0;
    19.     public float maxValue   = 100;
    20.     public float startValue = 0;
    21.     public float increment  = 0.1f;
    22.     public string format = "0.0";
    23.     public AudioClip formatExceptionAudio = null;
    24.  
    25.     private float currentValue = 0;
    26.     private bool  stopUpdating = false;
    27.  
    28.     void Start () { SetValue(startValue); }
    29.  
    30.     /// <summary>
    31.     /// Have increase and decrease buttons send messages here for fluid values updates
    32.     /// </summary>
    33.  
    34.     void IncreaseStart() { StartCoroutine(AutoUpdate(+this.increment)); }
    35.     void DecreaseStart() { StartCoroutine(AutoUpdate(-this.increment)); }
    36.     void IncreaseStop()  { stopUpdating = true; }
    37.     void DecreaseStop()  { stopUpdating = true; }
    38.  
    39.     /// <summary>
    40.     /// Auto increments values while the button is held down, increasing speed with time
    41.     /// </summary>
    42.  
    43.     IEnumerator AutoUpdate(float p_increment)
    44.     {
    45.         stopUpdating = false;
    46.         SetValue(currentValue + p_increment);
    47.         yield return new WaitForSeconds(1);
    48.  
    49.         float wait_interval = 0.2f;
    50.         while (!stopUpdating)
    51.         {
    52.             SetValue(currentValue + p_increment);
    53.  
    54.             wait_interval = Mathf.Max(wait_interval - 0.005f, 0.02f);
    55.             yield return new WaitForSeconds(wait_interval);
    56.         }
    57.         yield break;
    58.     }
    59.    
    60.     /// <summary>
    61.     /// Keep the value between min and max values, and updates the label
    62.     /// </summary>
    63.  
    64.     private void SetValue(float number)
    65.     {
    66.         currentValue = Mathf.Max(Mathf.Min(number, this.maxValue), this.minValue);
    67.         this.text = currentValue.ToString(format);
    68.         base.UpdateLabel();
    69.     }
    70.  
    71.     /// <summary>
    72.     /// Checks for Format Exceptions
    73.     /// </summary>
    74.  
    75.     override protected void UpdateLabel()
    76.     {
    77.         if (this.text.Length == 0 || this.text.EndsWith("."))
    78.         {
    79.             base.UpdateLabel();
    80.             return;
    81.         }
    82.  
    83.         float value;
    84.         bool ok = float.TryParse(this.text, out value);
    85.         if (!ok)
    86.         {
    87.             this.text = this.currentValue.ToString(format);
    88.             if (formatExceptionAudio)
    89.             {
    90.                 iTween.Stab(gameObject, formatExceptionAudio, 0);
    91.             }
    92.             return;
    93.         }
    94.  
    95.         SetValue(value);
    96.     }
    97. }
    98.  
    Maybe I'll give it a proper home online if I release more of these later.
     
  47. Asse83

    Asse83

    Joined:
    Aug 1, 2009
    Posts:
    169
    Hey,

    I'm working with 1.82e and I have the problem that at some point the atlas maker started to implement only parts of some textures :(

    Any hints on how to get rid of this error?
     
  48. WolfGames

    WolfGames

    Joined:
    Jul 25, 2011
    Posts:
    65
  49. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Aha, very nice ;)
     
  50. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
Thread Status:
Not open for further replies.