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.

Messages - OnlineCop

Pages: 1 [2] 3 4
NGUI 3 Support / Re: A question for ex-pirates!
« on: September 22, 2013, 01:36:54 PM »
One of my coworkers actually introduced us to NGUI, and added it (either his own license or a pirated copy) into some of our project SVN repos for us to see "NGUI in action." Management turned a blind eye since we were still in development stage and we didn't know whether we'd keep it. We decided that we would need a company-purchased version when we found that our version was several iterations behind, so we could update it as needed (without having to pull that co-worker from his other projects to go update it for us). Since then, it's actually been retro-fitted into most of our older projects because it's just that good and shrinks our app ship sizes and draw calls considerably.

Then someone noticed that NGUI was on sale a few months ago, for only a day or so. Almost every one of us (all of the engineers and most of our artists) bought our own personal licenses during that sale, so we could use our own copies for our personal projects.

So you got around a dozen orders because we had already been using it, loved it, and because a coworker happened to see the sale (if it wasn't for him, none of us would have know it had been discounted). I'm personally deliriously happy with my purchase (I'd have bought the Pro version, but couldn't clear that with my wife :P ) since I can add it to every new project I create, and the UI is usually the first things that go in. (Actually, a lot of the game mechanics leverage off of NGUI now: not just UI elements, so NGUI is a very embedded part of my workflow.)

TL;DR version: We started with a personal or pirated version at work: everyone loved it so much that we bought a legit copy for work AND each of us bought personal copies.

Now, if you ever discount your Pro (git access) license, I would not mind an email or PM informing me of the 1-day-only event. (In fact, neither would many of my co-workers.) :D

NGUI 3 Support / Re: Help with Colliders
« on: September 21, 2013, 02:59:56 PM »
How far forward is the entire popup? Try setting the entire popup tree, including the background dimmer with its collider, closer to the camera than anything else. The negative z depth should correctly block all click/hover events behind it.

NGUI 3 Support / Re: How to change lambda to NGUI 3.0
« on: September 21, 2013, 02:54:13 PM »
I'm going off of 2.7.0, so can't help with 3.0 directly, but does onValueChange take parameters? For 2.7.x, .onPress took both GameObject and bool, so I would write its lambas as:
myButton.onPress += (go, state) => { isDirty = true; };
Do parentheses make any difference (" += (x) =>"  vs. " += x =>" ) ?

NGUI 3 Support / Re: Moving the UI camera
« on: September 19, 2013, 08:18:19 AM »
Are you using the same camera to display your HUD (menus, buttons, etc.) as your other stuff, or do you have your HUD drawn over the top of a second camera?

Typically, I've moved my world camera and then have my UICamera with my 2D GUI elements drawn on top of them. That way, nothing from the 3D camera "clips" my 2D stuff. But your setup may be different.

I've seen it a few times with dynamic fonts in 2.7.0 and earlier. Something we do to "hack" this: create a UILabel, position it very close to the camera, and fill it with a space (so it's "empty" without actually having 0 character length). Then everything starts working again.

It's a work-around, but it works, so we've implemented it in places that this happens for us.

NGUI 3 Support / Re: Tween Enable
« on: September 18, 2013, 10:27:00 AM »

NGUI 3 Support / Re: How to stop tweens starting automatically...?
« on: September 18, 2013, 10:22:44 AM »
While tweens are enabled, they run. If you loop through and disable them (tween.enable = false), the tweens "pause" and re-enabling them will resume them. I use this whenever I pause my game: I simply disable all the tweens, which makes my objects freeze: their color, scale, and position tweens all resume again after I re-enable them:
  1.   public void PauseAllTweens()
  2.   {
  3.     if (gameObject != null) {
  4.       UITweener[] tweens = gameObject.GetComponents<UITweener>();
  5.       foreach (UITweener tween in tweens) {
  6.         tween.enabled = false;
  7.       }
  8.     }
  9.   }
  12.   public void UnpauseAllTweens()
  13.   {
  14.     if (gameObject != null) {
  15.       UITweener[] tweens = gameObject.GetComponents<UITweener>();
  16.       foreach (UITweener tween in tweens) {
  17.         tween.enabled = true;
  18.       }
  19.     }
  20.   }

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>
  5.    public Vector2 relativeSizeOffset =;
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;
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.             }

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?

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

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

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.

NGUI 3 Support / Re: One UITween for multiple objects
« on: September 09, 2013, 10:49:38 AM »
I have not found a "one tween to rule them all" solution like you're proposing. Each GameObject child needs its own tween, since each child has its own material instance that is being colored. I had the same issue when I received some "programmer art" that needed to be colorized: I had to actually traverse the hierarchy and attach tweens to all the children GameObjects.

One advantage to this system, though, is that I can pause my game (and all these color, scale, and position tweens stop right where they are mid-iteration) and resume them afterward with no need to recalculate logic (like "where were they going? how fast? how much time is left to have to create my own lerp?).

  1.     // You can pause the entire object by disabling its tweens, since TweenScale, TweenColor, and
  2.     // TweenPosition all resume perfectly once they are re-enabled.
  3.     //
  4.     // 'canAcceptInput' is a global flag used when identifying NGUI click events: when false, we
  5.     // don't consider this object's collider; when true, we do
  6.     public void PauseObject()
  7.     {
  8.         if (gameObject != null) {
  9.             UITweener[] tweens = gameObject.GetComponents<UITweener>();
  10.             foreach (UITweener tween in tweens) {
  11.                 tween.enabled = false;
  12.             }
  13.         }
  14.         canAcceptInput = false;
  15.     }
  18.     // Re-enabling the scale, color, and position tweens effectively unpauses the object.
  19.     public void UnpauseObject()
  20.     {
  21.         if (gameObject != null) {
  22.             UITweener[] tweens = gameObject.GetComponents<UITweener>();
  23.             foreach (UITweener tween in tweens) {
  24.                 tween.enabled = true;
  25.             }
  26.         }
  27.         canAcceptInput = true;
  28.     }
  31.     // Attach a color tween to each child element, as long as it has a renderer attached.
  32.     public void SetObjectColor(Color newColor, float colorTime)
  33.     {
  34.         // Loop through each child transform and, when they have renderers attached to them, tween their colors
  35.         foreach (Transform child in this.transform) {
  36.             if (child.renderer != null) {
  37.                 TweenColor tween = TweenColor.Begin(child.gameObject, colorTime, newColor);
  38.                 tween.onFinished += OnObjectColorFinished;
  39.             }
  40.         }
  41.     }
  44.     // Called as soon as each color tween has run its course.
  45.     // This callback does not get fired while a tween is paused (disabled) but it WILL get called
  46.     // once the tween is unpaused (re-enabled).
  47.     public OnObjectColorFinished(UITweener tween)
  48.     {
  49.         // Do something once the color tween has completed
  50.     }

NGUI 3 Support / Re: Update issue with image button
« on: September 06, 2013, 03:39:42 PM »
I had updated to 2.6.5 earlier this week, and saw the same. 2.6.5b appears to have the same issue.  :-\

NGUI 3 Support / Re: Pivot and UISprite
« on: September 05, 2013, 09:22:58 AM »
It sounds like Warka0OO wants to change the pivot of his UISprite, then rescale the object, which would leave the left/right edge where it was, but it would change its center point as it grows.

It would effectively mimic the functionality of UIWidgetInspector.AdjustPosAndScale(), but dynamically instead of inside the Unity Scene view.

That's just my guess, anyway.  :P

NGUI 3 Support / Re: Getting nice small text, possible?
« on: August 29, 2013, 11:38:01 AM »
This may be a little late to the game, but I wanted to show off some things we've discovered in our tests:

We imported the same font in various scales (18, 21, 24, 28, and 36-points). In the top-left corner of this image, we show them at their "native" resolutions (the same scale that they were imported into Unity/NGUI with).

In the top-right corner, we've taken the 18-point font and scaled it up all the way to 36-point. As you can see, it gets blurry.

In the bottom, we started with the 36-point font and scaled it down. In my opinion (but I'm no artist), it looks even crisper than the "native" import. Of course, the texture is just that much bigger in memory.

So if you're okay with a little more of a memory footprint, I'd suggest importing it as large as you expect you'll ever see it in your app, and just downscale it. After all, if you reuse the same font (just different scales) all over the place, it's optimized enough that it's only using a single texture for all those various draw calls.

NGUI 3 Support / Re: UiButtonColor on game object
« on: August 28, 2013, 01:03:10 PM »
The example code I provided was in C#. You can convert C# to Javascript by swapping the order of the [type][variable] declarations to [variable]:[type], like so:
  1. public Cube myCube; // This is the C# style
  2. public myCube : Cube; // This is the Javascript style
To convert functions, replace the return type (such as "void") with the word "function" and append its return type to the end:
  1. void MyCubeWasClicked(GameObject go) { // C# style
  2. function MyCubeWasClicked(go : GameObject) : void { // JS style, declares functions with a "function" keyword, and the return type goes on the end

You can use the same NGUI-based tweens in the same way for imported models, but remember that by design, they only modify the current/specified GameObject: it does not traverse the hierarchy and modify the child GameObjects. This way, if your model is of a 3D face, applying a color tween will affect, say, the skin only but leave the rest of the children (like eyes, hair, eyebrows, etc.) alone. To modify those, you will need to recurse through its hierarchy yourself and apply the same tween to them all.

NGUI 3 Support / Re: UiButtonColor on game object
« on: August 27, 2013, 09:15:28 AM »
If you are using the stock Cube, I would suggest using the TweenColor component instead.

  1. public Cube myCube; // Attach this to your cube
  3. void Start() {
  4.    UIEventManager.Get(myCube.gameObject).onClick += MyCubeWasClicked; // <-- Tween the color faster if you want it to be "instantly" colorized
  5. }
  7. void MyCubeWasClicked(GameObject go) {
  8.    TweenColor tween = TweenColor.Begin(go, 1.0f,;
  9. }
  11. void Destroy() {
  12.    UIEventManager.Get(myCube.gameObject).onClick -= MyCubeWasClicked;
  13. }

Pages: 1 [2] 3 4