Giter Site home page Giter Site logo

uitoolkit's Introduction

ODD Games & UIToolkit

Here at ODD Games we are working on some really awesome UI tools for Unity and it's all built on top of the UIToolkit code base.

Coming Soon as of (12/03/2014):

  • TexturePacker 'Rotatation' support
  • Simplified pivot/anchoring system (you can directly modify these properties and have your control update immediately)
  • AlphaBlending with automatic Z-Sorting (this replaces the AlphaTesting)
  • zPos on all elements
  • New UIElement.create methods so controls can be created inline with anchoring
  • Updated demo's

UIToolkit for Unity

UIToolkit aims to make creating interactive menu systems and HUDs with a single draw call for multiple resolutions dead simple. That's quite a mouthful and a tall order. The library comes with a bunch of different UI widgets out of the box and it makes creating your own widgets extremely simple. Some conveniences for dealing with HD resolutions (iPhone 3 vs iPhone 4 for example) are optionally provided and include:

  • automatic texture swapping to a double resolution texture for HD
  • automatic reconfiguration of UV coordinates
  • automatic handling of double resolution UIFonts
  • methods for relative positioning with offsets in pixels or percents

Check out an introduction video here

Included UI Components

Note: all touchable UI components can have highlightedTouchOffsets added. This mimics what Apple does with their iOS controls by adding a padding around the control that is activated when the control is being touched. For example, if you set the highlightedTouchOffsets to have an extra 30 pixel offset and a user touches the button, they can slide their finger an extra 30 pixels outside the boundary of the button. You can experience this by opening any Apple app on your iPhone with a button in it and touch your finger on it than slide it around off the button further and further until it is deselected.

  • UISprite: the base of every component that can be seen. All UISprites can have animations added to them that can be played on demand.
  • UIButton: standard button with selected state, optional sound on touch down and delegate action on touchUpInside
  • UIContinousButton: UIButton that can either report every frame that a finger remains on it or when a finger touches down or up
  • UIToggleButton: 3 state button that can be used just like a checkbox if desired
  • UIProgressBar: standard progress bar that offers 2 modes of progression: texture stretching or just revealing the texture as progress advances
  • UISlider: slider that works in both the horizontal and vertical direction
  • UIKnob: rotating knob control
  • UIText and UITextInstance: reads in a .fnt file and displays text including line breaks (base code courtesy of Eskema: http://eskemagames.blogspot.com/)
  • UIJoystick: joystick control with configureable dead zone and background image
  • UISwipeDetector: control that is capable of detecting swipes in any combination of directions (up, down, left, right)

Included UI Components

  • UIHorizontalLayout: lays out any children added to it horizontally. Spacing between the elements is configureable.
  • UIVerticalLayout: lays out any children added to it vertically. Spacing between the elements is configureable.

License

Attribution-NonCommercial-ShareAlike 3.0 Unported with simple explanation.

Setup

  1. Create a new layer, which in the example scenes is named "UILayer".
  2. Create an empty GameObject and position it at 0, 0, 0.
  3. Now drag the UI.cs script to this object. Be sure to set the UILayer that you chose in the previous step in the inspector in the UILayer slot.
  4. Go to the main camera and remove the UILayer (in this example "UILayer") from the Culling Mask so that your GUI doesn't get rendered twice.
    • Create a new GameObject
    • Set it as the child of the UI GameObject that was just created
    • Assign it to the newly created 'UILayer' (like this.)
    • Drag the UIToolkit.cs script onto it. (You can create multiple UIToolkit child objects that each have their own texture atlas for when one isn't enough). Your object hierarchy should look like this.
  5. Set the texturePackerConfigName in the inspector (more on this later). Make sure your texture packer .txt config file your texture atlases are in the Resources folder so they can be loaded at runtime.
  6. Do not try to create your UI in Awake as the UI script may not be done initializing yet. Use Start instead.

Exporting Sprite Sheets with Texture Packer

UIToolkit uses the output from the free version of the excellent Texture Packer program. It is dead easy to use and makes updating your atlases later a breeze. To get things going with Texture Packer all you need to do is:

  1. Drag and drop all your images into Texture Packer's right pane.
  2. In the Output pane (bottom left) set the Data format to json, set the Data file to be in a Resources folder in your project and set the Texture file to be in the Assets/Resources folder (or any other Resources folder in your project)
  3. In the Geometry pane, you will need to uncheck Autosize and set the texture size as a power of 2, square texture. Pick the smallest size that fits your sprites.
  4. Choose File -> Publish (Command-P) to export the json config file and the texture. Make sure they both have the same name. Note: you must rename the .json file to .txt. Unity currently will not recognize .json files as TextAssets.

Supporting HD and SD Resolutions

UIToolkit offers some conveniences for handling SD and HD resolutions with the same code. There are some naming conventions that must be adhered to for this to work. First off, you will need to have a second texture that is double the resolution of your standard texture that has the same name with "2x" appended to it. If you want to support both resolution types check the autoTextureSelectionForHD variable in the inspector of your UI game object. You will also need a second Texture Packer config file with "2x" appended to it to go along with the double sized texture.

There are also some methods available to assist with relative layout so you can code once and deploy on multiple resolutions. The UISprite class has extensions for positioning relatively from any screen corner. For example, to make a button be in the bottom left corner inset a bit from the corner on both the iPad and iPhone all you would need to do to get the position is:

button.positionFromBottomLeft( 0.05f, 0.05f, )

Working with UIFonts

Text support is included with the UIText class. Your font bitmap can be created with Hiero, Angelcode or Glyph. If you want to support both HD and SD resolutions you will need to export a .fnt file for both resolutions. Both files should be placed in a Resources folder in your project and the HD version should have "2x" appended to the name to take part in auto HD switching at runtime. Add the exported bitmap font png to your texture atlas in Texture Packer and you are good to go, just be sure the image name is the same as the .fnt filename. Note: you must rename the .fnt file to .txt. Unity currently will not recognize .fnt files as TextAssets.

Once you have a UIText instance loaded up with your specific font file you can make as many UITextInstances as you want by just calling addTextInstance. Newlines can be added with the standard "\n" and you can modify the returned UITextInstance at any time and the text will automatically be rebuilt.

uitoolkit's People

Contributors

acron0 avatar cayse avatar crushy avatar frittenkeez avatar getluky avatar githubbar avatar jools-adams avatar matkins85 avatar mortennobel avatar mspacemedia avatar nsxdavid avatar oddgames-david avatar pjezek avatar potatoirl avatar prime31 avatar reissgrant avatar tayl0r avatar yuriks avatar zentuit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uitoolkit's Issues

Easing.back

I am using positionFromTo and easing.back
it seems not to be any 'back' effect occurs...

Plan to support Trim feature of TexturePacker

This is a proposed plan to support TexturePacker's trim feature in UIToolkit. The changes would touch a lot of files, so looking for feedback before attempting.

The current code does not support the Trim feature of TexturePacker. This is perhaps one of the more important ones.

Trim finds the smallest rect that encompasses the pixels of an image that are not alpha=0 for each sprite that is packed into the atlas. Many times artists will animate things in sprites and rely on trim to remove this information during packing. This can result in huge savings in texture space.

However, to properly display trimmed sprites from the atlas, the sprites vertices must be moved to account for the discarded part of the image.

To make this work in UIToolkit, I've identified the following changes so far:

The UITextureInfo structure needs to keep track of the original size of the sprite (before it as packed and trimmed). TexturePacker emits this as "sourceSize". Unfortunately the identifier sourceSize was improperly already used in UITextureInfo for the property "sourceSpriteSize" in the control file. But to keep things simple, I suggest:

public struct UITextureInfo
{
    public UIUVRect uvRect;
    public Rect frame;
    public Rect sourceSize;
    public Vector2 originalSize;
}

Original size will need to be parsed (snipet from loadTexturesFromTexturePackerJSON):

        var originalSize = (Hashtable)((Hashtable)item.Value)["sourceSize"];
        var originalW =   int.Parse( originalSize["w"].ToString() );
        var originalH = int.Parse(originalSize["h"].ToString());

        var ti = new UITextureInfo();
        ti.frame = new Rect( frameX, frameY, frameW, frameH );
        ti.uvRect = new UIUVRect( frameX, frameY, frameW, frameH, textureSize );
        ti.sourceSize = new Rect( sourceSizeX, sourceSizeY, sourceSizeW, sourceSizeH );
        ti.originalSize = new Vector2(originalW, originalH);

Optimally, an optimization would be to also maintain a bool which tells us if the image was trimmed. This is the "trimmed" property in the control file.

To use this information the code will have to be refactored to understand that when the UVs are changed the vertices might have to also change.

The following code is an example of how this logic would work for a centerized sprite. This is the code I use for camera facing sprites in 3D space (my own custom extension to UIToolkit):

void  AssignUV(UITextureInfo textureInfo)   // EXAMPLE ONLY
{

    float w = textureInfo.originalSize.x;
    float h = textureInfo.originalSize.y;

    float hw = w / 2.0f;
    float hh = h / 2.0f;

    float left   = (textureInfo.sourceSize.xMin - hw);
    float right  = (textureInfo.sourceSize.xMax - hw);
    float top    = (textureInfo.sourceSize.yMax - hh);
    float bottom = (textureInfo.sourceSize.yMin - hh);

    Vector3[] vertices = new Vector3[4];
    vertices[0] = new Vector3(left, top, 0);
    vertices[1] = new Vector3(left, bottom, 0);
    vertices[2] = new Vector3(right, bottom, 0);
    vertices[3] = new Vector3(right, top, 0);

    OurMesh.vertices = vertices;

    Vector2[] UVs = new Vector2[4];

    UVs[0] = textureInfo.uvRect.lowerLeftUV + Vector2.up * textureInfo.uvRect.uvDimensions.y; // Upper-left
    UVs[1] = textureInfo.uvRect.lowerLeftUV; // Lower-left
    UVs[2] = textureInfo.uvRect.lowerLeftUV + Vector2.right * textureInfo.uvRect.uvDimensions.x; // Lower-right
    UVs[3] = textureInfo.uvRect.lowerLeftUV + textureInfo.uvRect.uvDimensions; // Upper-right

    OurMesh.uv = UVs;

}

This basic strategy would be adapted in UIToolkit.

The difficulty in this change is that UIToolkit currently makes the assumption that UV changes are very distinct of Vertex changes. And in many places where it will need to keep track of UV information it keeps and passes the UIUVRect of the UITextureInfo struct. For example, the Sprite Animaiton system has an array of UIUVRects for the animation frames. This will have to be refactored to an array of UITextureInfo structs. Similarly with many other places in the code.

It is the passing/tracking ofUI UVRects instead of UITextureInfo throughout the code that makes this refactor tricky.

I've not looked into how clipping might be impacted by this as I don't quite yet have my head around the clipping implementation.

There are other implications, as the actual "size" of the sprite is represented by something other than how the verts are positioned on the screen. This might impact touchable areas as well.

It is worth noting that support for the rotated property (another key feature of TexturePacker) can easily be part of this refactor. In fact to support rotated, moving from passing/storing UITextureInfo's instead of UIUVRects is pretty much required anyway.

How to add a simple background

I have been using UIButton for background for the last couple of weeks for background but now i need to start optimizing.
I just need a background which i can hide manually.
What should I use and how (currently trying with UISprite,not having good results)? (i am willing to tweak the UIToolkit, adding constructors and all that)

How to properly position?

Hi,

I'm trying to make a in-game menu layout, so I decide to create a simple menu containing 2 UIHorizontalLayouts "stacked" with 3 elements each, so:

but1 | but2 | but3
but4 | but5 | but6

So, I write this, that makes some sense to me:

        var layout1 = new UIHorizontalLayout(spacingBetweenItems);
        layout1.beginUpdates();
        layout1.verticalAlignMode = UIAbsoluteLayout.UIContainerVerticalAlignMode.Top;
        layout1.addChild(but1, but2, but3);
        layout1.pixelsFromTopLeft(bannerHeight + spacingBetweenItems, spacingBetweenItems);
        layout1.endUpdates();
        layout1.matchSizeToContentSize();

        var layout2 = new UIHorizontalLayout(spacingBetweenItems);
        layout2.beginUpdates();
        layout2.verticalAlignMode = UIAbsoluteLayout.UIContainerVerticalAlignMode.Top;
        layout2.addChild(but4, but5, but6);
        layout2.pixelsFromTopLeft((int)(layout1.height + Mathf.Abs(layout1.position.y)) + spacingBetweenItems, spacingBetweenItems);
        layout2.endUpdates();
        layout2.matchSizeToContentSize();

The interesting part is layout2.pixelsFromTopLeft((int)(layout1.height + Mathf.Abs(layout1.position.y)) + spacingBetweenItems, spacingBetweenItems);.
In my case, layout1.position.y gives me a negative value (still don't know why, so if someone know an explanation would be appreciated), so that's why I use the absolute value (yeah, it's more like a temporal fix or something like).

I'm using iPhone's HD resolution (640x960) and things work fine, but when I do on iPhone's resolution (320x480) things doesn't seem to work the same way.

However, I've come up with something:
iPhone: layout1.position.y is -59
iPhone HD: layout1.position.y is -118

This is a double size (which makes sense, IMHO). And if I hardcode 118 instead of Mathf.Abs(layout1.position.y), things work great! What's the problem? What should I do? There's a better way of doing all of this?

Note that I'm using 2x textures when switching to iPhone HD

sorting is broken (randomly) on device

havent tracked it down yet...ipod/iphone will sort incorrectly once, then be fine (most of the time)...ipad build sorts incorrectly all the time, even though fine in editor and fine in xcode

positioning routines dont respect scale

make a background container
add items, scrollers, sprites, buttons doesnt matter
change the scale of the container
most items will not be positioned correctly
will debug it when i can,

scroller with buttons goes haywire

create a horizontal scroller
add some sprites
add some buttons to the sprites
add some sprites to the 2nd set of sprites
create a 2nd scroller with same sets
creaete onTouchUpInside routines that hide the scrollers and show a new screen
quickly click with mouse on buttons
new screen will show up but scrollers will randomly not be hidden, wont scroll but the buttons are clickable

How to remove UIText?

How do you clean up the scene, if you want to remove UIText?

they not have a destroy method on them. I can set the UITextInstance to "" and destroy all it's child UISprites, but then the UITextInstances remain in the scene.

What't the preferred way to get rid of them?

Text - missing reference after clear

Once a text instance has clear() called on it, the text can still be changed but it can no longer be animated. I tried this in the demo scene to make sure it wasn't something in my game code. If you try to enter new text to one of the text instances in the IEnumerator modifyTextInstances() method after the text instance is cleared and then try to animate it with a PositionTo then this error comes up:

MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Transform.TransformPoint (Vector3 position)
UISprite.updateTransform () (at Assets/Plugins/UIToolkit/BaseElements/UISprite.cs:311)
UISprite.transformChanged () (at Assets/Plugins/UIToolkit/BaseElements/UISprite.cs:220)

The reason I was trying this out is because changing text in this latest UIToolKit build seems to not remove the pervious text in the text instance. So if I do this:

text1.text = "long test";
text1.text = "short";

the result is:

shorttest

or a jumble of both texts in the same space.

containers not removed from manager on destroy

title says it all...if you destroy a container it is not removed from the manager, and if you recreate it you get errors...simple fix
UIAbstractContainer.cs line 148 added:

    ITouchable touchable = this as ITouchable;
    if( touchable != null )
    {
        this.__manager.removeFromTouchables(touchable);
    }

"Cannot cast from source type to destination type"

Whenever I try to set up UIToolkit I get an "InvalidCastException: Cannot cast from source type to destination type." error. I've just started using UIToolkit so I don't know much about it, but I'm pretty sure I've got everything set up right. My TexturePacker file was renamed to a .txt, so its not that. When I double click the error it takes me to this line of code in the UISpriteManager script:
"var frames = (Hashtable)decodedHash["frames"];"

Any ideas?

layout.height returns 0

Using this code:

        ...
        var spacingBetweenItems = 3;
        var layout1 = new UIHorizontalLayout(spacingBetweenItems);
        layout1.beginUpdates();
        layout1.verticalAlignMode = UIAbsoluteLayout.UIContainerVerticalAlignMode.Top;
        layout1.addChild(tm1, tm2, tm3);
        layout1.matchSizeToContentSize();
        layout1.pixelsFromTopLeft(bannerHeight + spacingBetweenItems, spacingBetweenItems);
        layout1.endUpdates();

Where tm1, tm2 and tm3 are UIContinuousButtons (and have a height of 108), layout1.height returns 0. Is it a bug? What am I doing wrong?

centerize no longer works

I downloaded the package file & then downloaded all the updates and overwrote all the plugins in my Unity project, however the centerize function no longer works. Not sure how to trouble shoot this as it was working fine before.

UITextInstance glyph disappearing on non-Update() changes

Not sure this is worth chasing down, but I was having a problem with sometimes glyphs disappearing inside a UITextInstance. I was updating the instance through a SendMessage call, and doing so quite frequently.

For instance, if the text was supposed to be "10912", it displayed " 0 12", and then when the next update came through, it'd be fine.

It didn't seem to match up to if it got more than one update per frame, but once I started just saving those text updates and applying them in the next Update() call, the problem went away.

Relative positioning broken?

Seems as if the latest refactoring in commit 5f18bc8 has broken the relative positioning.

In short, it looks like IPositionablePositioningExtensions.cs: refreshPositions is just wrong now.

    // Get anchor info
    UIAnchorInfo anchorInfo = sprite.anchorInfo;

    // Get parent anchor position
    Vector3 position = parentAnchorPosition(anchorInfo.ParentUIObject, anchorInfo.ParentUIyAnchor, anchorInfo.ParentUIxAnchor);

Say the screen width is 320. If there is no parent, this would move a Right Anchored object to X of 320.
Then:

    // Add position offset
    if (anchorInfo.UIPrecision == UIPrecision.Percentage)
    {
        position.x += UIRelative.xPercentFrom(anchorInfo.UIxAnchor, anchorInfo.OffsetX);
        position.y -= UIRelative.yPercentFrom(anchorInfo.UIyAnchor, anchorInfo.OffsetY);
    }

This causes it to move it another 320 to the right so 640, becaues UIRelative.xPercentFrom() does this:

    // Get inital offset
    float offset = Screen.width * percentOffset;

    // If anchor is right the offset is flipped
    if( anchor == UIxAnchor.Right )
    {
        offset = Screen.width - offset;
    }
    return offset;

So with screen width of 320, 320 * 0 is 0, but because of Anchor.Right, that's 320-0, or 320. Which gets added and thus 640.

Anyway, anything anchored to the right or bottom of the screen is being thrown off screen.

UIToolkit doesn't work on Android.

Hi!
I try to build & run any demo on Android but it fails with iphone related error.
I updated most up-to-date version of UIToolkit.
So I revert to old version but it works fine.
New version seems error on Android.

Thank you.
Adam.

UISwipeDetector doesn't work on android

Only Up and Left directions work on Android 3.0. Down and right don't work.
All directions work on Win7

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

void detectedSwipe( UISwipeDetector sender, SwipeDirection direction )
{
    if (direction == SwipeDirection.Down)
                    // this doesn't work
    if (direction == SwipeDirection.Up)     
        // this works
}

The way I fixed it is at line 133 of UISwipeDetector.cs:
......
// Check the delta move positions. We can rule out at least 2 directions
if( touch.deltaPosition.x > 0.0f )
touchInfo.swipeDetectionState &= ~SwipeDirection.Left;
if( touch.deltaPosition.x < 0.0f )
touchInfo.swipeDetectionState &= ~SwipeDirection.Right;

    if( touch.deltaPosition.y < 0.0f )
        touchInfo.swipeDetectionState &= ~SwipeDirection.Up;            
    if( touch.deltaPosition.y > 0.0f )
        touchInfo.swipeDetectionState &= ~SwipeDirection.Down;

.......

Deprecated warning message

Upon building to iPhone I am getting the following warning message:

Assets/Plugins/UIToolkit/UI.cs(79,138): warning CS0618: `UnityEngine.iPhoneSettings.generation' is obsolete: `generation property is deprecated. Please use iPhone.generation instead.'

Should be very easy to fix.

Thanks for the fantastic toolkit! Keep up the great work

destroying text smoothly?

Hi!
I'd like to add animation for destroying text smoothly not immediately.
What should I do for that?
Could you give me some code snippet if possible?

Thank you,
Best Regards,
Adam

Hiding and unhiding clipping problem [video]

There's a problem when hiding and unhiding sprites, where part of them will still be rendered on the screen.

Here's a video that demonstrates the problem: http://www.screencast.com/t/F5xv03JoUll

I have a UIObject list of all my UIObjects to be hidden, here's the code responsible:

shopMenuSprites.OfType<UISprite>().ToList().ForEach(x => x.hidden = !x.hidden);
shopMenuSprites.OfType<UITextInstance>().ToList().ForEach(x => x.hidden = !x.hidden);
shopMenuSprites.OfType<UIAbstractContainer>().ToList().ForEach(x => x.hidden = !x.hidden);

UIToggleButton uvFrame after disable wrong

after disabling and re-enabling UIToggleButton the uvFrame points always to UITouchableSprite._tempUVframe which is by default the first (unselected) state of the UIToggleButton. for normal buttons this is ok, but for the toggle it's wrong as it looses it's current state (only visually, not boolean)

did not dare to try to fix this, as UITouchableSprite is the base for all other ones and i'm coming from AS3 so im not yet very used to c#'s inheritance behaviour.

Vertical Panel middle sprite height miscalculated

When creating a vertical panel, and using my own "top" "middle" and "bottom" sprites, the middle sprite is not calculated to be tall enough to connect the top sprite and bottom sprite.

by modifying the "UIVerticalPanel.cs" file line 104, from:

var leftoverHeight = totalAvailableHeight - _topStripeHeight - _bottomStripHeight + 3;

to:
var leftoverHeight = totalAvailableHeight - _topStripeHeight + _bottomStripHeight + 3;

seems to fix the problem.

Mouse Over Bug.

In the UIObject class, I found a Bug that i fixed with a simple Else statement. Here is the after code for the Mouse over effect. Just delete the current parentUIObject function and paste in this replacement. Or you can just add the else statement. When this is finished. The mouse over will start working correctly.

///

/// Setting the parentUIObject automatically sets up a listener for changes to the tranform.
/// When the parent transform changes, UISprite's will automatically call updateTransform to keep their
/// touch frames and actual positions in sync with the parent
/// </summary>


public UIObject parentUIObject
{
    get { return _parentUIObject; }
    set
    {
        if( value == _parentUIObject )
            return;
        // remove the old listener if we have one
        if( _parentUIObject != null )
            _parentUIObject.onTransformChanged -= transformChanged;

        // reparent the UIObject in the same UIToolkit tree as it's children
        //if( value != null && value.parent != parent )
        //  value.parent = parent;

        _parentUIObject = value;

        // if we got a null value, then we are being removed from the UIObject so reparent to our manager
        if( _parentUIObject != null )
        {
            clientTransform.parent = _parentUIObject.clientTransform;
        }
        else
        {
            if( this.GetType() == typeof( UISprite ) )
                clientTransform.parent = ((UISprite)this).manager.transform;
            else
                clientTransform.parent = null;
        }

        // add the new listener
        _parentUIObject.onTransformChanged += transformChanged;
    }
}

playSpriteAnimation with useful loopCount (with solution)

I use the new PlaySpriteAnimation and I see that my animation never stops, the loopCount doesn't count.

I think it's just a bug: in UISpriteAnimation class, row 36, I changed this:

while( _isPlaying && ( loopCount >= 0 || loopCount == -1 ) ){...}

to this:
while( _isPlaying && ( loopCount > 0 || loopCount == -1 ) ){...}

so when loopCount is 0, the while cycle stops and so the animation.

Miscalculation in sprite percent positioning when centerized

Problem in sprite positioning if sprite centerized.
sample:
var sprite = spriteToolkit.addSprite( "spritename.png", 0, 0, 1 );
sprite.centerize();
sprite.positionFromBottomLeft( .0f, 0.f );

sprite must be at bottom left but wrongly in near center left

Solution:
if sprite used centerize(); then
wrong
line 76 pos.y = -UIRelative.yPercentFrom( UIyAnchor.Bottom, percentFromBottom, sprite.height );
must be
line 76 pos.y = -UIRelative.yPercentFrom( UIyAnchor.Bottom, percentFromBottom, 0 );
but only for centrerized sprite

maybe some like:
if (sprite.gameObjectOriginInCenter)
pos.y = -UIRelative.yPercentFrom( UIyAnchor.Bottom, percentFromBottom, 0 );
else
pos.y = -UIRelative.yPercentFrom( UIyAnchor.Bottom, percentFromBottom, sprite.height );

P.S. possibly in anothers metods same error ...

Button and checkbox event problem

Hi,
Sometime buttons and checkbox don't recieve click event in the ScrollableContainerTest scene example.( in the container )
please fix that.

Thanks.

UIRelative - pixelFrom/to doesn't work anymore

Hi,
I saw that any methods of the new version of the UIRelative class that contains "Pixel" doesn't work anymore - yPixelFrom/to and xPixelFrom/to.

The old one calculates the value based on Screen dimension, the new one does nothing like this.

Is it me, or is it just broken?

How to Change Font?

Hi!

I'd like to change font.
But when I use TWL(http://twl.l33tlabs.org/) and BMFont application to create Bitmap font and added(or replace with prototype) to resource but it doesn't work.

Help me.

UIToolkit crashed upon opening downloaded zip

UIToolkit crashed upon opening downloaded zip. I'm using the latest stable version of Unity 3.4.2f2. Just wondering if anyone else had experienced this on Mac OS Lion?

Can someone advise on what parts of the package that I need to copy in say an empty project to begin working with it?

I copied the plugins folder for now. I wish I could see the demos but breaking the cache / temp would mean that all demo scenes would have broken links to assets and scripts.

scrollable containers disappear

create a vertical scroll container, add some images, run on device, touch the buttons, 30-40% of the time (or higher) the scroller will disappear due to all the container values getting messed up, sprites getting bad positions, etc...essentially everything gets clipped so it disappears...i've seen NaN for _scrollPosition in the debugger, not sure why it's happening

Wrong alpha using default shader

Shader problem?

In the picture there are two UIBackgroundLayout (the actual background and the layout that contain those 6 buttons).
The second layout (black box with orange stroke) contains 6 UIToggleButton. As you may see, there's a problem concerning alpha resolution. I'm using a material with the UIToolkit/Alpha Enabled shader. I've tried the three shaders UIToolkit provides, with no result.

Any ideas?

Scrollable Container borked

The Positioning changes seem to have broken the ScrollableContainerTest scene.

Repo: Open that scene, attempt to scroll the scrolalble test container. It'll start off okay and then fly out of view. Probably some sort of "double" applying of translation.

Bug in ScrollableVerticalLayout

This is observable if you try to scroll all the way to the bottom of the vertical scroll in the demo scene.

The console spams:

transform.position assign attempt for 'UIToggleButton' is not valid. Input position is { 0.000000, NaN, 1.000000 }.
UnityEngine.Transform:set_position(Vector3)
UIObject:set_position(Vector3) (at Assets/Plugins/UIToolkit/BaseElements/UIObject.cs:73)
UISprite:set_position(Vector3) (at Assets/Plugins/UIToolkit/BaseElements/UISprite.cs:159)
IPositionablePositioningExtensions:refreshPosition(IPositionable) (at Assets/Plugins/UIToolkit/Support/IPositionablePositioningExtensions.cs:901)
UIAbstractContainer:layoutChildren() (at Assets/Plugins/UIToolkit/BaseElements/UIAbstractContainer.cs:279)
UIAbstractTouchableContainer:layoutChildren() (at Assets/Plugins/UIToolkit/BaseElements/UIAbstractTouchableContainer.cs:283)
c__Iterator0:MoveNext() (at Assets/Plugins/UIToolkit/BaseElements/UIAbstractTouchableContainer.cs:97)

I'm looking into it

Inline Mouse Over effect

/*
I added a couple of functions for the mouse over effect. So if you have a 3 state button like,
var playButton = UIButton.create( "playUp.png","playOver.png", "playDown.png", 0, 0 );
This will work work correctly without having to do the current hack that's in the Kitchen sink tutorial.

*/

using UnityEngine;

public class UIButton : UITouchableSprite
{
public delegate void UIButtonTouchUpInside( UIButton sender );
public event UIButtonTouchUpInside onTouchUpInside;

public delegate void UIButtonTouchDown( UIButton sender );  
public event UIButtonTouchDown onTouchDown; 

public UIUVRect highlightedUVframe;
public AudioClip touchDownSound;


#region Constructors/Destructor



#region Three State Button

public static UIButton create( string filename,string mouseOver,string highlightedFilename, int xPos, int yPos )
{
    return UIButton.create( UI.firstToolkit, filename,mouseOver,highlightedFilename, xPos, yPos );
}



public static UIButton create( UIToolkit manager, string filename,string mouseOver, string highlightedFilename, int xPos, int yPos )
{
    return UIButton.create(manager, filename,mouseOver,highlightedFilename, xPos, yPos, 1 );
}


public static UIButton create( UIToolkit manager, string filename,string mouseOver, string highlightedFilename, int xPos, int yPos, int depth )
{
    // grab the texture details for the normal state
    var normalTI = manager.textureInfoForFilename( filename );
    var frame = new Rect( xPos, yPos, normalTI.frame.width, normalTI.frame.height );

if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER

    var hoveredTI=manager.textureInfoForFilename(mouseOver);
    var highlightedTITwo = manager.textureInfoForFilename( highlightedFilename);

    return new UIButton(manager,frame,depth,normalTI.uvRect,hoveredTI.uvRect,highlightedTITwo.uvRect);

else //This code for for mobile platforms.

    var highlightedTI = manager.textureInfoForFilename( highlightedFilename);
    return new UIButton( manager, frame, depth, normalTI.uvRect, highlightedTI.uvRect);

endif

}

public UIButton( UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame,UIUVRect hoveredUVframe,UIUVRect highlightedUVframe ):base( frame, depth, uvFrame )
{       
    // If a highlighted frame has not yet been set use the normalUVframe
    if( highlightedUVframe == UIUVRect.zero )
    {   
        highlightedUVframe = uvFrame;           
    }
    else if(hoveredUVframe == UIUVRect.zero )
    {
        hoveredUVframe=uvFrame;         
    }
    this.hoveredUVframe =hoveredUVframe;        
    this.highlightedUVframe = highlightedUVframe;   
    manager.addTouchableSprite( this );
}


#endregion


public static UIButton create( string filename, string highlightedFilename, int xPos, int yPos )
{
    return UIButton.create( UI.firstToolkit, filename, highlightedFilename, xPos, yPos );
}


public static UIButton create( UIToolkit manager, string filename, string highlightedFilename, int xPos, int yPos )
{
    return UIButton.create( manager, filename, highlightedFilename, xPos, yPos, 1 );
}


public static UIButton create( UIToolkit manager, string filename, string highlightedFilename, int xPos, int yPos, int depth )
{
    // grab the texture details for the normal state
    var normalTI = manager.textureInfoForFilename( filename );
    var frame = new Rect( xPos, yPos, normalTI.frame.width, normalTI.frame.height );

    // get the highlighted state
    var highlightedTI = manager.textureInfoForFilename( highlightedFilename );

    // create the button
    return new UIButton( manager, frame, depth, normalTI.uvRect, highlightedTI.uvRect );
}


public UIButton( UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UIUVRect highlightedUVframe ):base( frame, depth, uvFrame )
{
    // If a highlighted frame has not yet been set use the normalUVframe
    if( highlightedUVframe == UIUVRect.zero )
        highlightedUVframe = uvFrame;

    this.highlightedUVframe = highlightedUVframe;

    manager.addTouchableSprite( this );
}

#endregion;


// Sets the uvFrame of the original UISprite and resets the _normalUVFrame for reference when highlighting
public override UIUVRect uvFrame
{
    get { return _uvFrame; }
    set
    {
        _uvFrame = value;
        manager.updateUV( this );
    }
}


public override bool highlighted
{
    set
    {
        // Only set if it is different than our current value
        if( _highlighted != value )
        {           
            _highlighted = value;

            if ( value )
                base.uvFrame = highlightedUVframe;
            else
                base.uvFrame = _tempUVframe;
        }
    }
}


// Touch handlers

if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER

public override void onTouchBegan( UIFakeTouch touch, Vector2 touchPos )

else

public override void onTouchBegan( Touch touch, Vector2 touchPos )

endif

{
    highlighted = true;
    /*
    initialTouchPosition = touch.position;
    */
    if( touchDownSound != null )
        UI.instance.playSound( touchDownSound );


    if( onTouchDown != null )
        onTouchDown( this );




}

if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER

public override void onTouchEnded( UIFakeTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )

else

public override void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )

endif

{
    highlighted = false;

    // If the touch was inside our touchFrame and we have an action, call it
    if( touchWasInsideTouchFrame && onTouchUpInside != null )
        onTouchUpInside( this );
}

}

Unable to run demos

I tried opening KitchenSink.unity in DemoScenes/ and got 4 warnings for "The referenced script on this behavior is missing."

Same for ColorPicker.unity.

Making git repository Unity friendly(er)

This repository contains a lot of binary files that it should not.

Here are the guidelines for using Unity with SCM:

http://unity3d.com/support/documentation/Manual/ExternalVersionControlSystemSupport.html

Currently if I clone down this repo, it can be a bit of a mess to get it working. The primary problem is that there are various binary files in the Library folder that are causing the issues.

The .gitignore seems to be correct (I have to look closer) but never-the-less files are being tracked and thus flowing into the commits that should not.

I'd like to clean this up, but wanted to check first to make sure there wasn't some reason this wasn't already done as per the documentation.

Problem with xPos and yPos

I have tried updating UIToolkit to the master branch but am experiencing a problem.

I was changing xPos and yPos of UITextInstance's to reposition them but that doesn't appear to be working anymore.

Is this a problem or am I doing this wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.