Search Unity

GUISpriteUI GUI Object Library with Controls (Updated)

Discussion in 'iOS and tvOS' started by prime31, Jan 13, 2010.

  1. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,427
    One more quick update, test asset bundles are now available here. This latest update includes a GUIJoystick control as well and an example scene is in the bundle.
     
  2. robotmechanic

    robotmechanic

    Joined:
    Dec 29, 2009
    Posts:
    102
    Awesome, Thanks for the update and for making my life a little easier with GUISprite! :)

    So I am still using the default joystick controllers (GUITexture) and I wanted to put a background behind it using GUISprite but no what I do to the depth of the GUISprite, it always renders in front of the Unity GUITexture.

    Moving the GUITexture in the Z direction (-1 ) should move my texture in front I thought but it's not working. Any ideas or suggestions?
     
  3. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,427
    I can't say I use GUITextures at all but one thing that could be the issue is the layer and camera used for the GUITexture. It is possible that you are using the main camera for the GUITexture and it is getting rendered before the GUISpriteUI camera. That is just a guess though. You can save yourself a draw call by using GUISpriteUI for both images so that is probably the easiest option.
     
  4. robotmechanic

    robotmechanic

    Joined:
    Dec 29, 2009
    Posts:
    102
    uprise78,

    I didn't realize a second camera gets dynamically created at runtime till you mentioned it. I fiddled with the camera settings but no matter what I did, the main camera gets rendered behind the GUISpriteUI camera.

    Oh well. :?

    Now that you have added a controller stick I'll try to get that working next.

    Thanks for your help and for GUISpriteUI. :D
     
  5. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,427
    There is a joystick demo included in the test package. It is pretty easy to setup once you see the few lines of code required.
     
  6. robotmechanic

    robotmechanic

    Joined:
    Dec 29, 2009
    Posts:
    102
    I hope so. I'll check it out. :wink:

    Is there a way to just horizontally scale a 4x4 GUIsprite? I don't need any fancy colors so a solid square block is enough for what I need to do.

    I was trying to follow the progress bar example that you included in the scene file which seems to animate by texture coordinates but I am having trouble modifying it.

    For example, progressBar.width doesn't return an error but if I put something like,

    progressBar.width = player.health;

    in an update() function, nothing seems to happen.

    Any tips or advice would be appreciated.

    :)
     
  7. thetnswe

    thetnswe

    Joined:
    Aug 23, 2010
    Posts:
    37
    Unfortunately it doesn't work on my PC... I've been getting some weird error ... and found out that most of the class contaings Touch which seems to be no where in the original project... How can I fix it? Did I miss to include some class type ??
     
  8. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,427
    @thetnswe, I haven't done anything to make the code work on PC. It is fully designed for the iPhone but as @jmcclure mentioned there are just a few things that need to be changed.

    As for the missing classes, if you are using the most recent version from GitHub it is converted for use on Unity 3. If you grab an older version of the git repo you will find one that uses the old iPhone* classes.
     
  9. robotmechanic

    robotmechanic

    Joined:
    Dec 29, 2009
    Posts:
    102
    Prime31,

    Is there an easy way to turn off all GUIsprites in one call?
     
  10. pavees

    pavees

    Joined:
    Jan 1, 2009
    Posts:
    116
    I am getting an Error when i added the unity Package to My project. I am using iPhone Unity 1.7


    wat is the error in here..
     

    Attached Files:

    Last edited: Jan 24, 2011
  11. Eskema

    Eskema

    Joined:
    Jun 23, 2010
    Posts:
    310
    The actual version is only for unity3, you must download the old version to use unity 1.7
     
  12. Eskema

    Eskema

    Joined:
    Jun 23, 2010
    Posts:
    310
    Some good news for the users of this plugin, I've created a new extension and now we have bitmap fonts included, check out the new guitext extension.

    You only need to use a program like, angelcode, hiero or glyph to create your bitmap font, export the .fnt file to your project, add the font image to your spritesheet/atlas and code a little your new text functions.

    How to use it?

    Add the guitext script to your guimanager object, change the maxsprite count to reflect the new amount of sprites needed, each char is a sprite, so depending on how much text declare something like 400 sprites.

    Declare a typical object

    Code (csharp):
    1. GUItext mytext;

    Then in your script get the new text component and load the font config file
    Code (csharp):
    1.  
    2. mytext = GetComponent<GUItext>();
    3. mytext.LoadConfigfile("acmeexported");
    4.  
    And create your text
    Code (csharp):
    1.  
    2. //this will be text 0
    3. mytext.DrawText("hello\nman", vec1, 1.0f, 2);
    4. //this will be text 1  
    5. mytext.DrawText("testing bitmap fonts", vec2, 0.7f, 2);
    6. //this will be text 2
    7. mytext.DrawText("with only 1 draw call for everything", vec3, 0.7f, 2);
    8. //this will be text 3
    9. mytext.DrawText("kudos", vec4, 1.0f, 2);
    10.  
    And that's it, you have finally your text sprites batched with the rest of gui elements, no need for more "official" guitext anymore

    Cheers,
     
  13. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    Just found this and have a few questions:

    1. Can this be used with Windows stand-alones also?
    2. Could the sprites be used in 3D perspective (ie. for gauges / instruments in a 3D HUD)?
    3. Where's the latest version located (the first post is over a year old)?

    Many thanks! :)
     
  14. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,427
    @bigkahuna, should work fine in standalone. You will just want to adjust the size of the ortho camera that it creates to fit te screen. The camera is ortho so it wouldn't work for 3D perspective. The latest version is in the Github repo linked in a previous post.
     
  15. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    The latest link to github gives me a 404 error, is there a more recent link?
     
  16. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,427
    I'm on iPhone, but I believe if you replace "uprise78" in the link with "prime31" it will work or just search for prime31. I'll edit it when I get to a computer.
     
  17. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
  18. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    Hi !

    As you're in the process of rewritting GUISpriteUI to UIToolKit, should we wait for it if we are new to your project ?

    Thanks !
     
  19. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,427
    nah0y, there are a couple really key changes coming in the next few days. Once they are in, you should be good to start using it. The new repo is located here.

    Currently, everything is up and running fine but it isn't easy/convenient enough to use for my taste. You have to manually make your texture atlas and manually enter the coordinates right now which is really annoying and error prone. The next update coming soon will allow you to just use the free version of the excellent Texture Packer program to create your texture atlas. Creating a button used to look like this:

    Code (csharp):
    1. // params are a Rect of the location/size of the sprite, layer and the UV coordinates
    2. UISpriteButton playButton = UI.instance.addSpriteButton( new Rect( 10, 10, 108, 37 ), 3, new UIUVRect( 0, 0, 108, 37 ) );
    and it will soon look like this:

    Code (csharp):
    1. // sprite name and location (layer is optional)
    2. UISpriteButton playButton = UI.instance.addSpriteButton( "imageName", new Vector2( 10, 10 ) );
    Besides that, the code changes are mostly under the covers so if you did start playing around with it you would just need to change your button/element creation code to use the new, cleaner format. The HD support is already live which includes automatic texture swapping and even font size swapping when in HD. There is also the start of a relative positioning system so that you can layout a UI for HD/SD/iPad all using the same (or very similar) code. For example,

    Code (csharp):
    1. // get a vector that is 30% from the right side of the screen and 10% from the top
    2. var buttonPosition = UI.relativeVec2( .3f, UIxRelativeTo.Right, .1f, UIyRelativeTo.Top );
     
  20. kliucn

    kliucn

    Joined:
    Apr 11, 2011
    Posts:
    13
    COOL, thanks
     
  21. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,427
    Quick heads up, there was a huge commit with a good portion of the new stuff including Texture Packer support for dead simple sprite sheet creation and most importantly, a README that explains what is going on with the package. Tomorrow should have one last major push to get all the UI elements up to date.