Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - OnlineCop

Pages: [1]
1
NGUI 3 Support / Update the FAQ forum page
« on: November 26, 2013, 07:11:00 PM »
Several things changed between NGUI 2 and 3, and I would like to request the FAQ to either point to how-to's, documentation, or even those nice YouTube videos explaining how to do things.

For example, I used to use Tweens with
  1. TweenScale.Begin(gameObject, scaleTime, newScale).onFinished += MyOnTweenFinished;
I'm not sure how it's changed, or where to look to see how to do it now with 3.0.7. Do I use
  1. EventDelegate.Add(myTween.onFinished, MyOnTweenFinished);
or something else?

This, and other changes to NGUI, are many of my Frequently Asked questions.

EDIT:
Just saw that we're now getting a dedicated Documentation section (http://www.tasharen.com/forum/index.php?board=12.0). Yay!
So maybe the FAQ could point to either the entire section OR to individual threads, like http://www.tasharen.com/forum/index.php?topic=6760 (for Tweens).

2
NGUI 3 Support / NGUI 2.7.0: Add 'relativeSizeOffset' to UIStretch
« on: September 12, 2013, 12:38:14 PM »
I would like to propose an added effect to UIStretch.cs: a "relative size" offset (in pixels), which works in tandem with relativeSize.

I want to have one sprite always be exactly 10 pixels smaller than another (it's for a "gloss" foreground overlay on a button). When the button background gets resized, the overlay scales to be the same. Using 'relativeSize' by itself doesn't work for me, since a percentage means that it doesn't line up correctly.

I'm not well-versed in creating patches, but wanted to share this in case it is useful:

Add a new variable at the top called 'relativeSizeOffset':
  1.    /// <summary>
  2.    /// When Style is Both, Vertical, or Horizontal, make the scale relativeSize + this amount.
  3.    /// </summary>
  4.  
  5.    public Vector2 relativeSizeOffset = Vector2.zero;
  6.  
Then at the bottom of the Update loop, modify the line:
  1.             if (style == Style.Both || style == Style.Horizontal) localScale.x = relativeSize.x * rectWidth;
  2.             if (style == Style.Both || style == Style.Vertical) localScale.y = relativeSize.y * rectHeight;
  3.  
to be:
  1.             if (style == Style.Both || style == Style.Horizontal)
  2.             {
  3.                localScale.x = Mathf.Max(0f, (relativeSize.x * rectWidth) + relativeSizeOffset.x);
  4.             }
  5.             if (style == Style.Both || style == Style.Vertical)
  6.             {
  7.                localScale.y = Mathf.Max(0f, (relativeSize.y * rectHeight) + relativeSizeOffset.y);
  8.             }
  9.  

To use this, I:
  • Attach the UIStretch component to my button's "gloss" foreground sprite
  • Set "Widget Container" to point to the button's background sprite
  • Set the "Style" to Both
  • Set 'relativeSize.x' to 1.0
  • Set 'relativeSizeOffset.x' value to -10.0

Now any resizing done to the button's background is carried up to the button's foreground.

Comments? Suggestions?

3
NGUI 3 Support / Atlas prefabs store source names instead of GUIDs
« on: September 09, 2013, 01:19:40 PM »
We created an atlas with images that have the naming convention Item_WIDTHxHEIGHT:
  1. Btn_Close_48x48
  2. Btn_Goals_48x48
  3. Btn_Options_48x48
  4. Btn_Pause_48x48
  5. Btn_Play_48x48
  6.  

The artists then decided that the images should be larger, so scaled up the images. We renamed the files to match their new dimensions:
  1. Btn_Close_64x64
  2. Btn_Goals_64x64
  3. Btn_Options_64x64
  4. Btn_Pause_64x64
  5. Btn_Play_64x64
  6.  

Unfortunately, the NGUI atlas stores the source image names in the atlas' prefab, instead of the source image GUIDs which means that all of our UIImageButtons and UISprites broke.

Is there a way that the GUIDs of the images could be stored in the atlas prefabs instead of the image names? Then if we rename the source image names, the atlas would still point to the correct images.

4
I've got multiple transforms positioned around my environment: some are sources (where the TweenPosition tween begins) and the others are destinations (where the TweenPosition tween ends). I randomly choose one source and one destination Transform, instantiate my object, and call:
  1. TweenPosition tween = TweenPosition.Begin(newMonster.gameObject, 5.0f, randomDest.transform.position);
  2. tween.from = randomSource.transform.position;
  3. tween.to = randomDest.transform.position;
  4.  
This appears to work correctly when the randomSource and randomDest are located under the same parent, with the same scale.

It does not work correctly if they are in different parents, with different scales.

If I modify NGUI/Scripts/Tweening/TweenPosition.cs to use '.position' instead of '.localPosition', it appears to work fine when this is the the case.

Is there a reason why '.localPosition' is being used instead of '.position' ?

5
NGUI 3 Support / Request: UIButton alignment options
« on: July 17, 2013, 01:06:29 PM »
EDITED for clarity:

There are three UIWidget-derived objects in NGUI: UILabel, UISprite, and UITexture. The UIWidgetInspector class utilizes this fact and offers a pivot alignment control within the Unity Inspector, which is awesome for when I want to align these against one edge, then change my mind and align them against a different edge.

The UIButton and UIImageButton classes do NOT derive from UIWidget, however, and I wonder how difficult it would be to create the same kind of pivot alignment controls for those. I find myself resizing buttons (by resizing the UISprite and UILabels within them) in the editor, which requires adjustment to the parent GameObject and its BoxCollider each time.

In order to manually set a button's pivot to the bottom-right, I need to:
  • Scale the child UISprite to the desired size, then offset it by -1/2 its x scale and 1/2 its y scale (the sprite will appear too high and too far left)
  • Use the same x and y positions for the UILabel as the UISprite (the label should appear to be centered over the UISprite, which is up and left of the main UIButton's center point)
  • On the parent UIButton's BoxCollider, match both the UISprite's x and y positions as well as the x and y scales (the collider should now align over the top of the sprite)
  • Now, the button's pivot should be in the bottom-right corner of the button

.. ...
Once the button's pivot is in the bottom-right corner, if I decide to increase the offset from the edge of the panel, there's no need to recalculate the UISprite's dimensions (plus the edge offset) each time: I can simply set the GameObject's position directly to the desired offset.

But if I want to change the pivot (like if I decide the button should go in a different corner, or even centered in the panel), I have to repeat steps 1-4 again with the new offsets.

Could I request a similar "one-button solution" like we have with the UIWidgetInspector's alignment tools, for UIButtons an UIImageButtons? That would be awesome!

6
I am using scale and position tweens for a twitch game. The GameObjects currently move, rotate, and scale around the screen correctly.

I am going to need a pause feature in the game, but pausing the game should not affect background animations, music, and some other UI element tweens.

I searched for other ways to "pause" a game and found many results here that discuss how to do this with Time.timeScale, but I don't believe that would work best for all the background things that I need to keep going.

Since I'll know my tween's initial duration as well as the starting and ending positions/scales, could I just grab its current tween time, then unsubscribe the tween? Then when the player resumes, I could manually interpolate the values (or restore them from saved values) and resubscribe the tween to "finish" their operations.

Or is there a better way already in place?  ;)

Pages: [1]