Search Unity

Prime31 UIToolkit Multi Resolution GUI Solution Ready for Use...and it's free

Discussion in 'iOS and tvOS' started by prime31, May 3, 2011.

  1. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @ciarovoh, I'm not sure what you mean by "a texture with some control on it". UIToolkit will definitely manage choosing a low/high resolution atlas if that is what you are looking for.
     
  2. ciaravoh

    ciaravoh

    Joined:
    Dec 16, 2009
    Posts:
    252
    Brady,

    I just want to display a background using an ortho camera set to 386 width (half the resolution I'm targetting). I can't find any script to do this and EZGUi has the Packed Sprite to do it.

    you can set the width/height, the position relative to the camera, etc....

    To summarize, I want to have a background 1024*768 that will fit my camera and fill the screen of the iPad. Very simple in fact.
     
  3. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @ciarovoh, you *can* do that with UIToolkit but it would be tricky. UIToolkit uses a separate camera that renders on top of your normal camera whereas you want one that renders behind your normal camera.
     
  4. helixx2dbl

    helixx2dbl

    Joined:
    Jan 19, 2009
    Posts:
    9
    @Prime31, Hey, what is the proper way to destroy a UIObject. If I destroy one and it happens to be animated it will throw null value exceptions because the client has been destroyed but the animation is still running and trying to update its transform.
     
  5. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @helixx, you will need to stop animations before killing the object then you can use the removeElement method on the UI class
     
  6. helixx2dbl

    helixx2dbl

    Joined:
    Jan 19, 2009
    Posts:
    9
    Is there an easy way to stop all? Or do I need to store each UIAnimation when I start it?
     
  7. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @helixx, there is currently no way to stop all animations but it would be trivial to add it to the UIAnimation class.
     
  8. bryanleister

    bryanleister

    Joined:
    Apr 28, 2009
    Posts:
    130
    I apologize if this has been asked before, but I couldn't find an answer in my searches.

    I would like to use UISwipeDetector to determine the direction of a swipe. Not just Left, Right, Up or Down as in the example, but a Vector2 in the exact direction of the swipe. I can't seem to figure out how to access the swipe vector directly from UISwipeDetector.cs, it only returns a Left, Right, Up or Down result using the SwipeManager.cs script.

    I know I could alter the UISwipeDetector script to expose some public variables, but I'd rather leave the script unchanged and do this in my custom script, i.e. the SwipeManager.cs script. Can you point me in the right direction to get the touch data using UIToolkit?

    Bryan
     
  9. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    Bryan, if you are looking for just a swipes direction you definitely don't need anything as sophisticated as the UISwipeDetector. Its main purpose is to distill a series of touches down to just up, down, left or right. All you really need to do is look at a touch and it's delta position from the sounds of it.
     
  10. bryanleister

    bryanleister

    Joined:
    Apr 28, 2009
    Posts:
    130
    Hmmm, maybe my approach is too complicated. I was thinking of using the UIToolkit for other things too, so if one script is already accessing the data, I should get everything from it that I need. Probably just over thinking again:)
     
  11. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @bryanleister, UIToolkit it designed to be 100% extensible. If you want to make a touch detector class that does exactly what you want it is really easy. You can just use the UISwipeDetector as a template. You will be able to remove most of that class and just keep the touchBegan/Moved/Ended methods.
     
  12. blacksmithgames

    blacksmithgames

    Joined:
    Aug 30, 2009
    Posts:
    24
    We use several font sizes in our game. Do I need for every font size another UIFont texture ?
     
  13. Matkins

    Matkins

    Joined:
    Aug 24, 2009
    Posts:
    152
    Just use the biggest font size, then scale it when you create it;

    float scale = 0.5f;
    uiText.addTextInstance( "text here", 0, 0, scale, 1, Color.red );
     
  14. digitaloranges

    digitaloranges

    Joined:
    Apr 28, 2009
    Posts:
    1
    Hi all,

    Not sure if I'm doing something wrong here but ...

    I'm using UITextInstance and although I'm seeing sprite geometry being created in the editor window, it's not displaying in the camera view. The generated sprite object layers are all set to 'UILayer' (which I've set in the UI component) which seems correct.

    However - if I set the parent UIToolKit layer to 'UILayer' (upon startup it's set as 'default') in the editor while my game is running then the text appears! Even though it's sprite children are already set to 'UILayer'

    So - am I missing a step somewhere? If anyone can help me it would make my day :)
     
  15. goodhustle

    goodhustle

    Joined:
    Jun 4, 2009
    Posts:
    310
    Is anyone working on making panel contents scrollable with mesh clipping to make sure that panel contents "stay" within the panel? It looks like this is not currently supported, but possible. @Prime31, do you have any ideas on how to accomplish such a thing with the panel system you've got?
     
  16. UnityJP

    UnityJP

    Joined:
    Jul 7, 2011
    Posts:
    1
    Just wanted to say thanks to Prime31and all the others that have contributed for making this great toolkit and making it free as well. I've been messing around trying to make a game and this toolkit seems perfect for my menu systems but I did plan on selling the game on the various marketplaces (iPhone and Android mainly). I just wanted to make sure this didn't violate your license if I used the toolkit in a game being sold (I read the license in the readme but just wanted to clarify)?

    Hoping to make some custom controls when I need them in my game so I'll try to figure out git when/if I get there.

    Thanks again
     
  17. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @getluky, I haven't heard anyone start on making the panels scrollable. I would love to see a scrollable panel with all the touch control baked in. That would be a great addition. Without giving it too much deep thought I would start out with something like this:

    - each frame do some bounds checking and caching (to handle large lists)
    * the easy stuff first: set any fully out of bounds sprites to hidden
    * the hard stuff next: find the sprites that are on the border and adjust their frames and uv's to only show what is in the bounds of the container
    - once that is working, add momentum scrolling and bouncing on the top and bottom

    It's a short list but a monumental task. I look forward to the pull request :)

    @UnityJP, you are 100% free and clear to use UIToolkit in any game you want on any platform. The only thing you cannot do is sell the UIToolkit itself. UIToolkit is a throwback to the days before the Asset Store when there was a lot more community sharing here so the new folks get a jump start with an important part of every game: HUDs and menus.
     
  18. Fidde

    Fidde

    Joined:
    Dec 20, 2010
    Posts:
    109
    Is it possible to animate the scale of a UITextInstance without using UIText.updateText() on each frame (which recreates the entire instance)? Or perhaps some other trick to achieve a popping-up type of text?
     
  19. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Fidde, there currently isn't. The difficulty with scaling text is that you have to relayout each individual letter as they scale. What I would like to see is convenience animation methods on the UITextInstance class that loop through all the letters and animate them without recreating them.
     
  20. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    OK, I just sent a pull request that modified UIText to return an array of textSprites, for use with the animation methods. So, you can animate text like this:

    Code (csharp):
    1.  
    2.             UISprite[] textSprites = text1.getTextSprite();
    3.  
    4.             for(int i = 0 ; i < textSprites.Length ; i++){
    5.            
    6.                 StartCoroutine( animatePosition(textSprites[i] , new Vector3( textSprites[i].client.transform.position.x, -Screen.height * 0.7f, 1 ), .5f ) );
    7.                
    8.             }
    9.  
     
  21. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @reissgrant, I encapsulated what you are trying to do in a much more efficient manner. The UITextInstance class now has a positionBy method that will animate the text by the position you pass in. This keeps it to a single coroutine for the whole batch of UIObjects and makes animating the position a one liner.
     
  22. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    @Prime31, sounds great, I'll have a look.
     
  23. Fidde

    Fidde

    Joined:
    Dec 20, 2010
    Posts:
    109
    Thanks for the clarification, I'll push a commit if I come up with a solution for it. Started dabbling in exposing the sprite array, didn't look to cumbersome if you don't share sprites between UITextInstances.
     
  24. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Fidde, be sure to pull the latest. It has a method on UITextInstance that animates position. A scale animation would be very similar in setup and execution.
     
  25. zehreken

    zehreken

    Joined:
    Jun 29, 2009
    Posts:
    112
    Hi,
    I have a Menu class which includes all the gui related methods. Today I've added an Update() method to animate some UITextInstance object, everything went crazy, some of the sprites are added thousand of times one over another. I've even deleted the Update() method, the class is the same when I've left it on Friday, but nothing has changed. By the way this happens only on the iOS device, not on Unity and there is no error.
     
  26. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @zehr, without seeing some code I can say nothing more than UIToolkit will not create sprouts on it's own so you are more than likely creating them in a loop by accident somewhere.
     
  27. ashish

    ashish

    Joined:
    Dec 20, 2010
    Posts:
    26
    hi I wana know how to ur ez gui panel to and from variable set at runtime plz help me thanks in advance.........
     
  28. ashish

    ashish

    Joined:
    Dec 20, 2010
    Posts:
    26
    hi I wana know how to ur ez gui panel to and from variable set at runtime plz help me thanks in advance.........
     
  29. ashish

    ashish

    Joined:
    Dec 20, 2010
    Posts:
    26
    he my game is plate form base so I did not give
     
  30. helixx2dbl

    helixx2dbl

    Joined:
    Jan 19, 2009
    Posts:
    9
    @Prime, Hey, I tried making a stop all animations function in the UIAnimation class to stop the coroutines, but some are still running after I call stopAll and then destroy. Maybe I am doing it wrong? How would you write the stop all function? Thanks in advance!
     
  31. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @helixx, I would just grab all the running animations from the _spriteAnimations, loop through them calling stop() on each one, then clear out the dictionary. You could even go a step further and allow the stopAll method to take in


    Code (csharp):
    1. public static void stopAllAnimations()
    2. {
    3.      // loop through all keys
    4.            // loop through each animation for the key calling stop on each
    5.            // remove the key from the dictionary
    6. }
    7.  
    8.  
    9. public static stopAllAnimationsForObject( UIObject obj )
    10. {
    11.      // get all animations for object
    12.      // loop through them calling stop on each
    13.      // remove the key from the dictionary
    14. }
    15.  
     
  32. helixx2dbl

    helixx2dbl

    Joined:
    Jan 19, 2009
    Posts:
    9
    @Prime, Ok thanks. Thats what I did, it must be something else. Ill double check tho.
     
  33. helixx2dbl

    helixx2dbl

    Joined:
    Jan 19, 2009
    Posts:
    9
    If anyone was looking at this. Here is the code to add to the UIAnimation class.
    Code (csharp):
    1.  
    2. public static void stopAllAnimations()
    3.     {
    4.         foreach(KeyValuePair<UIObject, List<UIAnimation>> u in _spriteAnimations)
    5.         {
    6.             stopAllAnimationsForObject(u.Key);
    7.         }
    8.     }
    9.    
    10.    
    11.     public static void stopAllAnimationsForObject( UIObject obj )
    12.     {
    13.         List<UIAnimation> l = _spriteAnimations[obj];
    14.         for(int p = 0; p < l.Count; p++){
    15.             UIAnimation aUiAnimation = l[p];
    16.             aUiAnimation.stop();
    17.             _spriteAnimations[obj].Remove( aUiAnimation );
    18.         }
    19.     }
    20.  
     
  34. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @helixx, I went in Github to look for your pull request but couldn't find it :) I'll look again in a little bit...
     
  35. goodhustle

    goodhustle

    Joined:
    Jun 4, 2009
    Posts:
    310
    Is there any reason why the positionTo animation methods don't have corresponding convenience methods similar to the positionFrom* ones? It would be convenient to just use the same positioning system when setting up translation animations. If you'll accept a pull request for it, I can take a shot at it. Doesn't seem too hard.
     
  36. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @getluky, is it this you are looking for?
     
  37. unitynewb

    unitynewb

    Joined:
    Feb 22, 2009
    Posts:
    243
    I've been trying to make UIContinuousButton work, but for some reason it will only work on the first press then it does not continue. On this script below the Time is printed 1 time unless I let go of the button and press it again. I also tried using onTouchUpInside and that gave me the same results.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class controlstouch : MonoBehaviour {
    6.     public UIContinuousButton blButton;
    7.     void Start () {
    8.         blButton = UIContinuousButton.create( buttonToolkit, "blUp.png", "blDown.png", 0, 0);
    9.         blButton.onTouchDown += onTouchDownblButton;
    10. //      blButton.onTouchUpInside += onTouchDownblButton;
    11.     }
    12.     // Update is called once per frame
    13.     void Update () {
    14.    
    15.     }
    16.     public void onTouchDownblButton( UIButton sender ){
    17.         print("Touched "+Time.time);
    18.     }
    19. }
    20.  
     
  38. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
  39. unitynewb

    unitynewb

    Joined:
    Feb 22, 2009
    Posts:
    243
  40. goodhustle

    goodhustle

    Joined:
    Jun 4, 2009
    Posts:
    310
    @Prime31, that's helpful, and I think I see what my problem is.

    When doing positioning through the IPositionablePositioningExtensions, you're expecting a inputs from a UL-based origin with the y axis positive in the downwards direction, correct?

    However, the Vector3 that you pass into the animation functions is just a "raw" Vector3, so you need to switch coordinate system expectations. To get a sprite animating to a BL-aligned corner, you'd have to do Vector3(0, -Screen.height + sprite.frame.height, 0), right?

    In my opinion, it would be more consistent to have positioning animations work off of the same expected inputs (i.e. Vector2s, y-axis positive in downwards directions) and perhaps have convenience methods available for producing those inputs based on alignments.
     
  41. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @getlucky, one of the wonderful things about UIToolkit is the whole thing is totally extensible. You can make an Extension class that does things exactly the way you want to without touching the main framework at all.
     
  42. robotive

    robotive

    Joined:
    Apr 17, 2009
    Posts:
    59
    Hi, is there a possibility to have a disabled state for the UIButton?

    Thanks.
     
  43. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @robotive, feel free to add one and send over a pull request. You could also just swap the normal uv rect to a different, disabled image then swap it back.
     
  44. robotive

    robotive

    Joined:
    Apr 17, 2009
    Posts:
    59
    @prime31, thanks, will do :)
     
  45. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    Hello, thanks for this awesome toolkit. I am just getting started with it and am literally just putting together a quick test using the provided resources (kitchenSink in particular). I appear to have followed all of the necessary steps, but for some reason when I test by adding just a play button, the sprite is HUGE. I can't seem to pull it back or scale it or anything. Any idea what I'm doing wrong? Thanks.

    EDIT: So, during runtime if I select my child object inside the main UI object and manually set its layer to the layer I defined, it works fine.. otherwise it does not. It seems like the the UILayer property in the UI script isn't really working. What could I possibly be doing wrong?
     
    Last edited: Jul 15, 2011
  46. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @helios, make sure you set the main camera to not display the ui layer and then the UI object should have the ui layer selected.
     
  47. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    Ah ok, so I need to set the UI objects layer to the ui layer in the main inspector, in addition to setting the layer in the UILayer property?
     
  48. unitynewb

    unitynewb

    Joined:
    Feb 22, 2009
    Posts:
    243
    Is there anyway to determine where on the screen a UIVerticalLayout ends? I want to have a space in between buttons and thought of just creating another UIVerticalLayout and starting it at the end of the first one with a little space in between.

    I tried getting UIVerticalLayout.height and starting it there, but that started far away from the end of the UIVerticalLayout.
     
  49. LimeSplice

    LimeSplice

    Joined:
    Jul 15, 2011
    Posts:
    111
    Hi Everyone
    In the past, when it comes to UI and Menus, I've always created 2D sprite components and assigned scripts to them, rather than use the UI system.

    I'm interested to hear what others think of this. What's the pros and cons of using a UI Toolkit over the method that I use?

    @prime31. I'm assuming your toolkit handles multiple resolutions (iphone3-4, ipad)?


    Thanks!
     
  50. unitynewb

    unitynewb

    Joined:
    Feb 22, 2009
    Posts:
    243

    I ended up adding up the height for each buttons height and spacing to get this. I'm not sure why iI didnt think of that bbefore I made this post.