Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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

    werneroi

    Joined:
    May 13, 2012
    Posts:
    26
    Hello everyone and Prime.

    is there a way to hide a container (this case it is a UIHorizontalLayout) with all its children?

    if i just use
    Code (csharp):
    1.  
    2. UIHorizontalLayout.hidden = true;
    3.  
    it only hides the buttons but not the text which is added also as a child to the buttons.
    i tried using the destroy() option which was added lately but with no luck as well.

    any ideas will be great!
     
  2. paulStapelberg

    paulStapelberg

    Joined:
    Jun 13, 2010
    Posts:
    30
    @werneroi, you could hide your text when you hide your container. I'm not the greatest programmer so there is probably a better way to do it, but that's how I would go about it. Anyone else have a good way to do it?

    PS - Another way of making things 'disappear' is simply moving them off the screen and then moving them back on screen if you need them again.
     
  3. pweeks

    pweeks

    Joined:
    Mar 29, 2011
    Posts:
    104
    i think i have a fix for this...Unity appears to randomly order the list of uitoolkits if you have more than one. so if you're button toolkit renders first, it doesnt matter what the layer value is, it will blend to whatever is in the buffer...i've added sort code to ui.cs and it seems to fix it
     
  4. pweeks

    pweeks

    Joined:
    Mar 29, 2011
    Posts:
    104
    we added code for list of text children and the subsequent code to hide them...thought we sent a pull request to have it added, but if you're not hiding text, then it didnt get added...I'll have to find the files we touched and i can send it, but currently working on the sorting bug, so might not be today

    a quick look...we added addText to UISprite.cs and in the hide function added the call to hide the text
    Code (csharp):
    1.  
    2.     protected List<UITextInstance> _children = new List<UITextInstance>();
    3.     public virtual bool hidden
    4.     {
    5.         get { return ___hidden; }
    6.         set
    7.         {
    8.             // No need to do anything if we're already in this state:
    9.             if( value == ___hidden )
    10.                 return;
    11.  
    12.             if( value )
    13.                 manager.hideSprite( this );
    14.             else
    15.                 manager.showSprite( this );
    16.  
    17.             // apply state to the children
    18.             foreach( var child in _children )
    19.                 child.hidden = value;
    20.         }
    21.     }
    22.  
    23.     public virtual void addText( params UITextInstance[] children )
    24.     {
    25.         foreach( var child in children )
    26.         {
    27.             //child.parentUIObject = this;
    28.             _children.Add( child );
    29.         }
    30.  
    31.         //layoutChildren();
    32.     }
    33.  
    edit2: we also added similar functions and variables to uiabstractcontainer.cs
     
    Last edited: Jun 1, 2012
  5. werneroi

    werneroi

    Joined:
    May 13, 2012
    Posts:
    26
    @pweeks

    thanks man, i will wait patiently , if you find the files that will be great. I will also try to learn from what you just posted!
     
  6. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    Does anyone know if there is a way to offset the center position of the UISprite to a specific coordinate/position on the sprite?
     
  7. paulStapelberg

    paulStapelberg

    Joined:
    Jun 13, 2010
    Posts:
    30
    Is it possible to change/set the height of a container panel? I want to make the panel size according to the text parented to it. At the moment I am using text1.parentUIObject = panel to parent the text to the panel. I know the panel sets it's size automatically when using panel.addChild(button1), is there something similar for a text object?
     
  8. coolpowers

    coolpowers

    Joined:
    Mar 23, 2010
    Posts:
    125
    When using the animation functions on UIButton, the hitbox gets messed up. Known bug, or am I missing a step?
     
  9. jdwieber

    jdwieber

    Joined:
    Mar 20, 2012
    Posts:
    28
    I want to create a simple hud that displays the usual game elements like score, time, power bar, etc., but I want to have an opaque background image. What is the best way to add the background? My initial thought (haven't actually tried it yet) is to use a panel object with the text elements and power bar as children. Is this the preferred way, or is there a better way? Thanks.

    Regards,

    Joseph
     
  10. jdwieber

    jdwieber

    Joined:
    Mar 20, 2012
    Posts:
    28
    I have another noob question that I can't find the answer to. I'm trying to get some simple UIText elements on the screen and I'm getting errors because I don't know the correct way to create the font files required. Using TWL theme editor I made two bitmap fonts from a ttf font. One has a font size of 32, and one is 64. The larger font has the same name as the smaller font with 2x appended. I renamed the .fnt files to .txt. I brought each one into texture packer and exported them with json format. Each one is in it's own file as I don't have other textures to add at this time. Everything lives in Assets/Resources. In the Inspector for the object with the UIToolkit script attached I set the TexturePackerConfigName to the name of the json file (without the .txt extension). I assign the material and grabbed the ExtendedTextTest script and put it in my scene with the appropriate name changes ( "maze32", "maze32.png"). The exception thrown is this:
    Code (csharp):
    1. Exception: can't find texture details for texture packer sprite:maze32.png
    2. UISpriteManager.frameForFilename (System.String filename) (at Assets/Plugins/UIToolkit/BaseElements/UISpriteManager.cs:182)
    3. UIText..ctor (.UIToolkit manager, System.String fontFilename, System.String textureFilename) (at Assets/Plugins/UIToolkit/UIElements/UIText.cs:89)
    4. UIText..ctor (System.String fontFilename, System.String textureFilename)
    5. HUD.Start () (at Assets/Scripts/HUD.cs:29)
    which I think indicates that it can't find the .fnt files (have .txt extensions). What am I doing wrong? Is there a tutorial, thread, or some other info. around that covers the workflow of creating the font resources and bringing them into unity in the format that UIToolkit expects? Everything that I have in my scene parallels the demo. Also, if I bring my font resources into the demo it dies as well, so I must be missing a fundamental step somewhere. Thanks for the help.

    EDIT:

    Never mind. I put everything (SD and HD fonts bitmats) in a single texture atlas and all is well now.

    EDIT:

    I spoke too soon. I used it to display fps and it's all garbled looking. I didn't think two different sized font textures would work. It worked up until I resized the screen and it went to 2x.

    EDIT:

    I'm back to the original exception. I just don't see what I'm doing wrong. Good grief, it's just not my day... I tried to attach a zip file of my Resources directory with the files I created and the simple hud script that I'm trying to use, but I got an IO error. It was .zip extension and well under the max allowable size. I quit.

    EDIT:

    I lied, I'm still at it. I followed all the suggestions given to hippocoder in 2011, but still no dice.

    EDIT:

    Finally got it going. Went back to stuffing all my textures into one atlas. The first time I did it I put two different sizes of the same text in the atlas. This is what caused the garbled output in my earlier attempt. For anyone else that might have trouble here is exactly what I did to get it going.

    1. Create a bitmap font using a tool like TWL Theme Editor, or bmGlyph
    2. Make sure to create HD and SD versions
    3. Open texture packer and bring in all your UI elements, and the bitmap font png file (the HD version)
    3a. Publish SD and HD to json/png
    4. Rename all the .fnt, and .json files to have .txt extension
    5. Bring the six files into Assets/Resources of you unity project
    5a There should be two .txt files created by the bitmap font tool: fontName.txt and fontName2x.txt, there should four from Text Packer: spriteSheet.png, spriteSheet.txt, spriteSheet2x.png, and spriteSheet2x.txt

    Whew, glad that's over with...
     
    Last edited: Jun 7, 2012
  11. jdwieber

    jdwieber

    Joined:
    Mar 20, 2012
    Posts:
    28
    I'm using UITextInstance to implement a simple text based compass to print the direction in the world the user is facing. I'm updating the string data in the Update function and I'm seeing an issue when a longer string is overwritten by a shorter string. For instance when the user pans from "North West" to "West" the display displays "West West" with som garbled pixels where the new string ends and the old one remains. I searched the web and don't see anyone mention this. Has anyone seen this before? I happens every time a long string is replaced by a shorter string. Here is a code snippet:

    Code (csharp):
    1.  
    2.     void Start ()
    3.     {
    4.         m_controller = GameObject.Find ( "Player" );
    5.         m_mazeBuilder = GetComponent< MazeBuilder >();
    6.         m_timeLeft = updateInterval;
    7.  
    8.         var text = new UIText( "centuryGothicStroke", "centuryGothicStroke.png" );
    9.         m_compass = text.addTextInstance( "Bearing", 0, 0, 1, 5, Color.red, UITextAlignMode.Left, UITextVerticalAlignMode.Top );
    10.         m_fpsText = text.addTextInstance( m_fps, Screen.width, 0, 0.75f, 5, Color.red, UITextAlignMode.Right, UITextVerticalAlignMode.Top );
    11.     }
    12.  
    13.     void Update()
    14.     {
    15.         m_timeLeft -= Time.deltaTime;
    16.         m_accum += Time.timeScale / Time.deltaTime;
    17.         ++m_frames;
    18.  
    19.         if( m_timeLeft <= 0f )
    20.         {
    21.             float fps = m_accum / m_frames;
    22.             m_fps = string.Format( "{0:F2} FPS", fps );
    23.             m_timeLeft = updateInterval;
    24.             m_accum = 0f;
    25.             m_frames = 0;
    26.             m_fpsText.text = m_fps;
    27.         }
    28.  
    29.         if ( m_controller )
    30.         {
    31.             float deg = m_controller.transform.rotation.eulerAngles.y;
    32.             Heading heading = mapDegrees ( deg );
    33.             m_compass.text = heading.ToString();
    34.         }
    35.    }
    36.  
    Am I doing something wrong? I got the code right from the text demo. I stuck in a call to m_compass.clear() before setting the new text, but this drops my frame rate from 65 to 38. Is there a better way to fix this?
     
    Last edited: Jun 7, 2012
  12. werneroi

    werneroi

    Joined:
    May 13, 2012
    Posts:
    26
    @jdwieber

    hi man, i had a similar thing with a timer update, i think what happens is that you set the text the first time at the start and then you add text in upadte so it doesn't erase the old one, the way i solved was to declare the text as empty without the var, so it will be like this:

    Code (csharp):
    1.  
    2. m_fpsText = text.addTextInstance( " " , Screen.width, 0, 0.75f, 5, Color.red, UITextAlignMode.Right, UITextVerticalAlignMode.Top );
    3.  
    then in update just set the value of m_fps as the text , just like you did.

    i didnt test it with your script so i hope it will work.
     
  13. jdwieber

    jdwieber

    Joined:
    Mar 20, 2012
    Posts:
    28
    @werneroi

    Thanks for the reply. I tried it, but got the same results as before. I added the below check and it works ok. I lose ~4 fps, which I'm not happy about, but at least I can move forward until a better solution comes along. It's not an accurate check though and can still leave some old pixels in place, but for the selected strings the compass displays, it seems to do the job. Comparing the results from UIText.sizeForText would be the accurate comparison.

    Code (csharp):
    1.  
    2. m_currBearing = heading.ToString();
    3. if( m_currBearing.Length < m_compass.text.Length )
    4. {
    5.       m_compass.clear();
    6. }
    7. m_compass.text = m_currBearing;
    8.  
    I think it's because the main camera ignores the UILayer, and the UILayer camera only clears depth info. Hopefully I find a better solution. If and when I do, I'll update the post.
    Cheers.
     
    Last edited: Jun 7, 2012
  14. jdwieber

    jdwieber

    Joined:
    Mar 20, 2012
    Posts:
    28
    Does anyone know of some place that I can get some themed images, or pre-made sprite sheets, to create a UI from? I'm a developer with almost no artistic ability and I need some nice looking images to create a sprite sheet from. The typical things like radio buttons, sliders, etc.. I can color them, put text on them, scale them, but I can't design them and have a cohesive and aesthetically pleasing result. Thanks.

    Regards,

    Joseph
     
  15. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    Try checking the asset store on Unity.
     
  16. jdwieber

    jdwieber

    Joined:
    Mar 20, 2012
    Posts:
    28
    @AbsurdHart

    I checked there first, but only found assets for the unity GUI skin system. I grabbed the two free assets and had a look. They are pretty low res compared to the samples that come with UIToolkit, and I'm not sure how they will work. From what I understand, UIToolkit applies the textures as decals, but the unity GUI Skin system does sampling. I don't think the gui skin assets will work well with UIToolkit. Of course, I could be dead wrong. Do you use gui skins from the asset store?
     
  17. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    After Google searching Royalty-Free UI Assets, this popped up.
    Try this:
    http://www.designer-daily.com/18-free-ui-elements-packs-for-your-web-designs-and-apps-11823

    If you don't have Photoshop you can download GIMP for free.
     
  18. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    We built our project to the iPhone 4S after testing it on the iPad2 and iPad 3, and the UI coordinates seem to stay at the 4:3, of the iPad, when they should be at 3:2 for the iPhone 4S. Does anyone know what we may be doing wrong? Thank you.
     
  19. coolpowers

    coolpowers

    Joined:
    Mar 23, 2010
    Posts:
    125
    There's definitely something screwy with the touchFrame getting messed up during some sequence of hiding, disabling, and applying animations to buttons. I don't really have time to dig through the code and see where it's happening so I just applied a hack (position the button, save the touchFrame, then reapply the saved touchFrame after moving or disabling or whatever) but if someone can find out what the problem is it would be great.
     
  20. jdwieber

    jdwieber

    Joined:
    Mar 20, 2012
    Posts:
    28
    Thanks! I also found some cool stuff here: http://favbulous.com/free-psd

    I do like the gimp, but it's a bit of a hassle on my mac (just switched after 12yrs of loyal linux use), so I'm using a program called pixelmator (for anyone looking for an inexpensive alternative on mac). It very nice and has more features than I hope to ever use. Thanks again for the link.
     
  21. jdwieber

    jdwieber

    Joined:
    Mar 20, 2012
    Posts:
    28
    I made a texture sheet using TexturePacker (TP) that has two fonts and my UI elements in it. When I enable auto texture selection for hd my ui gets all garbled. When I disable that feature it looks fine. This is a test ui and only has a single atlas, UI script, and UIToolkit script. It code copy/pasted from the kitchen sink demo. The atlas is 2048x2048 with a lot of empty space. I tried publishing it using all different configurations and settings. I cranked up the padding, dropped it down, etc.. There are no error messages reported by TP, or unity. I tried running under android and web with the same mess. Is there a maximum size for the atlas that I'm exceeding? Any ideas what could be wrong?
    SD:
    $UIToolkitSD.png

    HD:
    $UIToolkitHD.png


    Thanks
     
  22. TrialByFun

    TrialByFun

    Joined:
    Jun 23, 2009
    Posts:
    97
    First thing to check is that the hd texture isn't being compressed to half size (1024) in its compression settings.
     
  23. pweeks

    pweeks

    Joined:
    Mar 29, 2011
    Posts:
    104
    indeed...check the Unity settings...if you've got a 2048x2048, Unity probably said "meh...lets make it 1024x1024", which will mess up everything
     
  24. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    hi prime
    i m still a noobs and struggle to understand the swap demo.
    i try to do to recognize the swap direction by doing this

    void Start()
    {
    var swipeDetector = UISwipeDetector.create( new Rect( 0, 0, Screen.width, Screen.height ), 1 );
    swipeDetector.onSwipe += detectedSwipe;
    }


    void detectedSwipe( UISwipeDetector sender, SwipeDirection direction )
    {
    if(SwipeDirection.Left)
    Debug.Log( "swipe left " );
    else if(SwipeDirection.right)
    Debug.Log( "swipe left " );
    }

    but it crash.
    thanks for your awesome support from a noob who love unity :)
     
  25. werneroi

    werneroi

    Joined:
    May 13, 2012
    Posts:
    26
    @toto2003

    your if() are wrong.
    use this
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class SWIPER : MonoBehaviour {
    6.  
    7. void Start()
    8.     {
    9.     var swipeDetector = UISwipeDetector.create( new Rect( 0, 0, Screen.width, Screen.height ), 1 );
    10.     swipeDetector.onSwipe += detectedSwipe;
    11.     }
    12.    
    13.    
    14. void detectedSwipe( UISwipeDetector sender, SwipeDirection direction )
    15.     {
    16.     if (direction == SwipeDirection.Left)      
    17.     Debug.Log( "swipe Left " );
    18.     if (direction == SwipeDirection.Right)
    19.     Debug.Log( "swipe Right " );
    20.     }
    21. }
    22.  
     
  26. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    u made my day :)
     
  27. jdwieber

    jdwieber

    Joined:
    Mar 20, 2012
    Posts:
    28
    @SBurgess
    @pweeks

    Indeed, that got it. Max size was set to 1024 and it was being compressed. Thanks.
     
    Last edited: Jun 13, 2012
  28. jdwieber

    jdwieber

    Joined:
    Mar 20, 2012
    Posts:
    28
    Is there any reason that UIToolkit buttons wouldn't work on an Android device? I'm in the process of learning UIToolkit and have set up a simple main menu to my game. It works as expected in the standalone, and web players, but when I switch to Android and deploy it to a device, it just hangs. None of the buttons fire their registered handlers, and none of the sounds play. In the code below, I have a text overlay on the buttons and I tried removing them, but still it doesn't work for me on Android. Am I doing something wrong in the code, or am I missing something? Here is my code:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class mainMenu : MonoBehaviour
    6. {
    7.     public AudioClip clickSound;
    8.  
    9.     void Start ()
    10.     {
    11.         Screen.orientation = ScreenOrientation.Portrait;
    12.  
    13.         UIToolkit manager = UI.firstToolkit;
    14.         var background = UI.firstToolkit.addSprite ( "panel.png", 0, 0, 10 );
    15.         background.setSize ( Screen.width, Screen.height );
    16.  
    17.         var buttonTI = manager.textureInfoForFilename ( "buttonNormal.png" );
    18.         var centerY = ( Screen.height - buttonTI.frame.height ) * 0.5f;
    19.         var centerX = ( Screen.width - buttonTI.frame.width ) * 0.5f;
    20.  
    21.         //Set up the play button with a text overlay
    22.         var playButton = UIButton.create ( manager, "buttonNormal.png", "buttonSelected.png", ( int )centerX, ( int )centerY, 2 );
    23.         playButton.centerize ();
    24.         playButton.setSize ( buttonTI.frame.width * 2.5f, buttonTI.frame.height * 2.5f );
    25.         playButton.highlightedTouchOffsets = new UIEdgeOffsets ( 30 );
    26.         playButton.onTouchUpInside += onTouchUpInsidePlayButton;
    27.         playButton.touchDownSound = clickSound;
    28.  
    29.         //figure out what scale we need to fit the text completely inside the button image
    30.         //TODO: Find a better way to discover what scale is needed
    31.         var text = new UIText ( "DeutchGothicStrokeGradient", "DeutchGothicStrokeGradient.png" );
    32.         Vector2 size = Vector2.zero;
    33.         float scale = 1.05f;
    34.         float delta = 0.05f;
    35.         do
    36.         {
    37.             scale -= delta;
    38.             size = text.sizeForText ( "PLAY", scale );
    39.         }
    40.         while( size.x >= playButton.width );
    41.         float xPos = ( Screen.width - size.x ) * 0.5f;
    42.         float yPos = ( Screen.height - size.y ) * 0.5f;
    43.         Color color = new Color ( 0.6f, 0.5f, 0.4f, 0.5f );
    44.         UITextInstance playText = text.addTextInstance ( "PLAY", xPos, yPos, scale, 1, color, UITextAlignMode.Left, UITextVerticalAlignMode.Top );
    45.         playText.parentUIObject = playButton;
    46.  
    47.         //Create an option button simalr to above
    48.         yPos = centerY - playButton.height;
    49.         var optionButton = UIButton.create ( manager, "buttonNormal.png", "buttonSelected.png", ( int )centerX, ( int )yPos, 2 );
    50.         optionButton.centerize ();
    51.         optionButton.setSize ( buttonTI.frame.width * 2.5f, buttonTI.frame.height * 2.5f );
    52.         optionButton.onTouchUpInside += ( sender ) => Debug.Log ( "clicked the button: " + sender );
    53.         optionButton.touchDownSound = clickSound;
    54.         scale = 1.05f;
    55.         do
    56.         {
    57.             scale -= delta;
    58.             size = text.sizeForText ( "OPTIONS", scale );
    59.         }
    60.         while( size.x >= optionButton.width );
    61.         xPos = ( Screen.width - size.x ) * 0.5f;
    62.         UITextInstance optionText = text.addTextInstance ( "OPTIONS", xPos, yPos, scale, 1, color, UITextAlignMode.Left, UITextVerticalAlignMode.Top );
    63.         optionText.parentUIObject = optionButton;
    64.  
    65.         //Quit button
    66.         yPos = centerY + optionButton.height;
    67.         var quitButton = UIButton.create ( manager, "buttonNormal.png", "buttonSelected.png", ( int )centerX, ( int )yPos, 2 );
    68.         quitButton.centerize ();
    69.         quitButton.setSize ( buttonTI.frame.width * 2.5f, buttonTI.frame.height * 2.5f );
    70.         quitButton.onTouchUpInside += ( sender ) => Application.Quit ();
    71.         scale = 1.05f;
    72.         do
    73.         {
    74.             scale -= delta;
    75.             size = text.sizeForText ( "QUIT", scale );
    76.         }
    77.         while( size.x >= quitButton.width );
    78.         xPos = ( Screen.width - size.x ) * 0.5f;
    79.         UITextInstance quitText = text.addTextInstance ( "QUIT", xPos, yPos, scale, 1, color, UITextAlignMode.Left, UITextVerticalAlignMode.Top );
    80.         quitText.parentUIObject = quitButton;
    81.  
    82. #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER
    83.         playButton.hoveredUVframe = UI.firstToolkit.uvRectForFilename( "buttonHover.png" );
    84.         optionButton.hoveredUVframe = UI.firstToolkit.uvRectForFilename( "buttonHover.png" );
    85.         quitButton.hoveredUVframe = UI.firstToolkit.uvRectForFilename( "buttonHover.png" );
    86. #endif
    87.     }
    88.  
    89.  #region Callbacks
    90.     //Scores
    91.     public void onTouchUpInsideScoresButton ( UIButton sender )
    92.     {
    93.         StartCoroutine ( "loadScoresMenuScene", sender.touchDownSound.length );
    94.     }
    95.  
    96.     private IEnumerator loadScoresMenuScene ( float seconds )
    97.     {
    98.         yield return new WaitForSeconds( seconds );
    99.         Application.LoadLevel ( "scoresMenuScene" );
    100.     }
    101.  
    102.     //Options
    103.     public void onTouchUpInsideOptionsButton ( UIButton sender )
    104.     {
    105.         StartCoroutine ( "loadScoresMenuScene", sender.touchDownSound.length );
    106.     }
    107.  
    108.     private IEnumerator loadOptionMenuScene ( float seconds )
    109.     {
    110.         yield return new WaitForSeconds( seconds );
    111.         Application.LoadLevel ( "optionMenuScene" );
    112.     }
    113.  
    114.     //Main Scene
    115.     public void onTouchUpInsidePlayButton ( UIButton sender )
    116.     {
    117.         StartCoroutine ( "loadMainScene", sender.touchDownSound.length );
    118.     }
    119.  
    120.     private IEnumerator loadMainScene ( float seconds )
    121.     {
    122.         yield return new WaitForSeconds( seconds );
    123.         Application.LoadLevel ( "mainScene" );
    124.     }
    125.  #endregion;
    126.  
    127. }
    128.  
    Thanks.
     
  29. jdwieber

    jdwieber

    Joined:
    Mar 20, 2012
    Posts:
    28
    That would be sooooooo sweet! There should be a forum at Prime31.
     
    Last edited: Jun 13, 2012
  30. jdwieber

    jdwieber

    Joined:
    Mar 20, 2012
    Posts:
    28
    I have this issue too. I avoid it by storing the length of the string being displayed and before setting the text to a new string I check to see if the new string is shorter. If so, I call clear before setting the new text. I assume it works since I haven't seen the floaters since. My project is new and is rapidly changing, so it's hard for me to tell if it was that change that fixed it, or some other change. It's a simple test though that you can try. The frame rate dropped about 3fps though :(. I'm eventually going to revisit it and force a fixed length string to see if I can avoid calling clear and not have the floaters come back.
     
  31. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    I just pushed a new feature that might be of use to folks using UIToolkit. Any touchable (such as a button) can now set a property allowTouchBeganWhenMovedOver which when true allows the button to be activated when a finger slides over it. The touch does not have to start on the button for it to be activated. This is useful for stuff like a d-pad made of 4 buttons. The user can then just slide their finger over the buttons to activate them without needing to pick it up. See the options button in the MultipleAtlasManager.cs file for an example.
     
  32. pweeks

    pweeks

    Joined:
    Mar 29, 2011
    Posts:
    104
    we've had no issues on any device as of yet, not sure why you'd have to reset anchor info based on resolution or aspect ratio...sorry i can't be of more help
     
  33. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    Another push went live with enhancements to the horizontal scrollable and with experimental support for @4x atlases (for iPad 3). Paging enabled scrollables can now be a different width than their item width allowing you to see the next/previous items partially. A bug was fixed with the scroll position being off a couple pixels on occasion when paging snapped to the first or last page.
     
  34. Panajev

    Panajev

    Joined:
    Mar 26, 2012
    Posts:
    42
    Hello Prime31,

    One useful addition to UIToolkit would be in the way of more documentation, sometimes it would be of great help.

    It is not too clear to me how to quickly change anchor info (the position of the anchor) or how to start an animation with an infinite loop count (making it loop until the animation is stopped by hand)... also, is it possible to query UIToolkit to know if an animation started on a Sprite is still running or not (a isAnimPlaying("") kind of method)?

    Could you give out some help as far as those three items are concerned (they are all quite important). Thanks a lot :).
     
  35. Panajev

    Panajev

    Joined:
    Mar 26, 2012
    Posts:
    42
    This is indeed quite useful, thanks :).

    The way I solved it currently, before playing around with UIToolkit (really nice library) is by using overlapping rectangular box colliders (4 colliders in total for the DPad) which overlap where the diagonals would be (two colliders overlap on the top-left, two on the top-right, two on the bottom-right, and two on the bottom-left) and then querying with a physics raycast operation if a touch hit either one of them or more than one of them. It worked quite well for this DPad.
     
  36. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @panajev, any additions to the documentation would of course be superb. The community can absolutely jump in and help out with stuff like that as the docs are definitely not up to date. You will usually not adjust anchor info directly and instead use the positioning extension methods. See the source for how it does it.
     
  37. pweeks

    pweeks

    Joined:
    Mar 29, 2011
    Posts:
    104
    i added infinite loop a few weeks ago, and I think Prime merged the push...set the animation loop to -1 and it will loop infinite
     
  38. milox

    milox

    Joined:
    Jun 2, 2012
    Posts:
    1
    Nevermind, solved it...
     
    Last edited: Jun 22, 2012
  39. Ves

    Ves

    Joined:
    Apr 6, 2011
    Posts:
    23
    Is there a way to get the width of a horizontal container? I tried using the matchSizeToContentSize for a container that has seven buttons, but it still returns 0 for width.

    EDIT: Nevermind. Apparently, if I put it after the endUpdates, it works.
     
    Last edited: Jun 24, 2012
  40. Ves

    Ves

    Joined:
    Apr 6, 2011
    Posts:
    23
    Is there a way to add a text instance to a panel?

    Also... it seems that the progress bar background has been taken out; was this intentional?
     
    Last edited: Jun 24, 2012
  41. Panajev

    Panajev

    Joined:
    Mar 26, 2012
    Posts:
    42
    Hey Prime31,

    a small public service announcement. The latest TexturePacker, free version too AFAIK, offers Unity3D as output format. Basically, JSON data with .txt extension. So, the renaming step you mentioned in your tutorials/instructions is not necessary anymore :).

    Also, a small request. Could it be possible to also position items in percentage from a given point (from top left is fine) without changing the anchor point info? It would make the API simpler to use IMHO. Thanks :).
     
  42. Panajev

    Panajev

    Joined:
    Mar 26, 2012
    Posts:
    42
    @Prime31: As I mentioned in my other post, tying up position and anchor information can cause problems and complicate your code. Imagine having several elements, each with their own best anchor position, it would help me position them if I could decouple the anchor info from the positioning part (I tend to lay out my GUI using the percentage based API's you followed). In such a case, if I said positionFromTopLeft(0.5,0.5) would always mean in the center of the screen regardless of the object's anchor info (which would play its influence as a sort of texture offset).

    Edit: perhaps it is already provided with one of the overrides, right? I see overrides with UIxAnchor and UIyAnchor info specified.


    @pweeks: thanks for the addition, I tried it because Prime31 suggested it in relation to something about GoKit so I was like "hey, the same people are behind both so..." and it did work :).
     
    Last edited: Jun 25, 2012
  43. ncst

    ncst

    Joined:
    May 28, 2011
    Posts:
    207
    Has anyone else had a similar problem? I had the same issue, and in the log file for the webplayer, I found the following error:

    Code (csharp):
    1. FieldAccessException: Attempt to access a private/protected field failed.
    2.   at (wrapper managed-to-native) System.Reflection.MonoField:SetValueInternal (System.Reflection.FieldInfo,object,object)
    3.  
    4.   at System.Reflection.MonoField.SetValue (System.Object obj, System.Object val, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    5.  
    6.   at System.Reflection.FieldInfo.SetValue (System.Object obj, System.Object value) [0x00000] in <filename unknown>:0
    7.  
    8.   at UITouchMaker.createTouchFromInput (UIMouseState mouseState, System.Nullable`1 lastMousePosition) [0x00000] in <filename unknown>:0
    9.  
    10.   at UIToolkit.Update () [0x00000] in <filename unknown>:0
     
  44. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    It appears that web players don't like the reflection trickery. For now you will have to roll back a couple releases to get the non-reflected setup. Well see if we can find a suitable workaround without having to resort to web player only code blocks.
     
  45. werneroi

    werneroi

    Joined:
    May 13, 2012
    Posts:
    26
    @prime

    Hi Yo!
    there are two very very very annoying BUGS!
    they exists in the demo files, even the new ones.

    both of the relate to the horizontalScrollContainer

    1. the first graphic file is corrupted when static, once it moves or touched it is ok, but when it is in it first state it is all weird.
    i managed to trick it by adding another graphic to the script before i make the UIHorizonalLayout and make it invisible.

    2. when you flick with your finger a very small gesture, but quick (and it doesn't matter which direction!) the container disappears.
    as simple as that, no way of telling it to come back even when i force it to check if it is out of bounds and then come back.

    i was thinking maybe it has to do with the touch phase that is so short, but i really dont know enough regarding the way you built it, so all my attempts to find a fix for that didn't work so far.

    if you can check it and maybe come up with a fix that will be AMAZING!!!!

    well done all the latest updates.
    I love your product.
     
  46. ncst

    ncst

    Joined:
    May 28, 2011
    Posts:
    207
    Thanks prime31! I looked at rolling back to the earlier version, but it seemed simpler in the end to create a UITouch struct from the UIFakeTouch.cs, then translate all touches into UITouches. That seems to work for Editor/Webplayer, but I'll have to see if it introduced any new problems.

    Thanks for your help, and for a great package!
     
  47. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    I found doing this inside UITextInstance.cs, helps the framerate and clears the text the way you want it:

    Code (csharp):
    1.  
    2.     public string text
    3.     {
    4.         get
    5.         {
    6.             return _text;
    7.         }
    8.         set
    9.         {
    10.             clear();
    11.             _text = value;
    12.            
    13.             // cleanse our textSprites of any excess that we dont need
    14. //          if ( _text.Length < textSprites.Count )
    15. //          {
    16. //                for ( var i = textSprites.Count - 1; i >= _text.Length; i-- )
    17. //                {
    18. //                    var sprite = textSprites[i];
    19. //                    textSprites.RemoveAt( i );
    20. //                    _parentText.manager.removeElement( sprite );
    21. //                }
    22. //          }
    23.  
    24.             _parentText.updateText( this );
    25.             updateSize();
    26.         }
    27.     }
    28.  
    29.  
     
  48. pweeks

    pweeks

    Joined:
    Mar 29, 2011
    Posts:
    104
    for #2, i'm pretty sure this fix (not sure if it made it into the current build but we did a pull request)
    in UIScrollableHorizontalLayout.cs, around line 76, in the function "onTouchMoved", comment out the _activeTouchable.onTouchEnded() call
     
  49. werneroi

    werneroi

    Joined:
    May 13, 2012
    Posts:
    26
    @pweeks

    hey man, thanks for the replay but it is al ready commented out :(

    Code (csharp):
    1.  
    2. public override void onTouchMoved( Touch touch, Vector2 touchPos )
    3.     {
    4.         // increment deltaTouch so we can pass on the touch if necessary
    5.         _deltaTouch += touch.deltaPosition.x;
    6.         _lastTouch = touch;
    7.  
    8.         // once we move too far unhighlight and stop tracking the touchable
    9.         if( _activeTouchable != null  Mathf.Abs( _deltaTouch ) > TOUCH_MAX_DELTA_FOR_ACTIVATION )
    10.         {
    11.             //this is broken and passes a touch through to the scrollable item even if scrolling
    12.             //_activeTouchable.onTouchEnded( touch, touchPos, true );
    13.             _activeTouchable.highlighted = false;
    14.             _activeTouchable = null;
    15.         }
    16.  
    17.  
    18.         var newOffset = _scrollPosition + touch.deltaPosition.x;
    19.  
    20.         // are we dragging above/below the scrollables boundaries?
    21.         _isDraggingPastExtents = ( newOffset > 0 || newOffset < _minEdgeInset.x );
    22.  
    23.         // if we are dragging past our extents dragging is no longer 1:1. we apply an exponential falloff
    24.         if( _isDraggingPastExtents )
    25.         {
    26.             // how far from the top/bottom are we?
    27.             var distanceFromSource = 0f;
    28.  
    29.             if( newOffset > 0 ) // stretching down
    30.                 distanceFromSource = newOffset;
    31.             else
    32.                 distanceFromSource = Mathf.Abs( _contentWidth + newOffset - width );
    33.  
    34.             // we need to know the percentage we are from the source
    35.             var percentFromSource = distanceFromSource / width;
    36.  
    37.             // apply exponential falloff so that the further we are from source the less 1 pixel drag actually goes
    38.             newOffset = _scrollPosition + ( touch.deltaPosition.x * Mathf.Pow( 0.04f, percentFromSource ) );
    39.         }
    40.  
    41.         _scrollPosition = newOffset;
    42.         layoutChildren();
    43.  
    44.         // pop any extra velocities and push the current velocity onto the stack
    45.         if( _velocities.Count == TOTAL_VELOCITY_SAMPLE_COUNT )
    46.             _velocities.Dequeue();
    47.         _velocities.Enqueue( touch.deltaPosition.x / Time.deltaTime );
    48.     }
    49.  
    50.  
    as i said, you can see it happen in the demo scene when you run it on an iphone or ipad.
     
  50. pweeks

    pweeks

    Joined:
    Mar 29, 2011
    Posts:
    104
    hmm...lemme check our version and see if something else changed that i forgot about...i know that one line was definitely something that hosed us on "quick swipes"...