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 - ryan

Pages: [1] 2
1
Misc Archive / Empires & Allies, made with NGUI
« on: May 05, 2015, 12:32:47 PM »
Empires & Allies is now available worldwide. Welcome to the battlefront, Commanders.

Download for Android: http://bit.ly/Empireall
Download for iOS: http://bit.ly/EADownload

Like us on Facebook! https://www.facebook.com/EmpiresAndAllies

2
NGUI 3 Support / UIScrollView optimization
« on: February 18, 2014, 05:02:55 PM »
I have a use case where UIScrollView.LateUpdate is taking about 20ms to run on an iPad 2.  Part of the problem is that I have way too many widgets in the scroll view, but the other part is that one of its children has a pulsing color, causing UIScrollView to recalculate the bounds of its children every frame.  It's deciding whether to change the alpha on the scroll bars, but there are no scroll bars.  I've locally changed this line near the top of LateUpdate:

      if (showScrollBars != ShowCondition.Always)

to this:

      if (showScrollBars != ShowCondition.Always && (verticalScrollBar || horizontalScrollBar))

I can also change showScrollBars to Always on my prefab, but that's too easy.

3
NGUI 3 Support / UIInput bugs in 3.0.8f3
« on: December 31, 2013, 04:15:34 PM »
If I open and run the Tutorial 9 scene from the examples, click the input and type in some characters, then use the left arrow key multiple times to move the carat back, it only moves one character before getting stuck.  It looks like it's actually adding some invisible characters to the string, as I see some odd artifacts in the inspector which also become visible in the game window if I switch to a dynamic font.

Possibly related, when running in the editor on Mac, cmd-x/cmd-c/cmd-v to cut/copy/paste are also inserting an x, c, or v character.  This only happens in the editor, not when building and running the app, so I consider it a minor issue.  I ran into this a while back with a separate product, and I think it was actually a unity problem where the editor wasn't reporting events properly when the command key was involved, but maybe there's something you can do about that.

4
NGUI 3 Support / Weird culling of nested widgets in clipped panels
« on: December 13, 2013, 01:59:58 PM »
Now that we're allowed to nest widgets inside other widgets, I've started using that with the new anchor system to lay things out.  I've noticed when using a scroll view with soft clipping (probably any clipping) that once a parent sprite is no longer visible inside the scroll view, any of its children will suddenly disappear, even if they extend outside the bounds of the parent.  This is most obvious if I've used a 2x2 empty widget to anchor the position of a group of widgets, but happens in other cases, too.  (For now I've made those empty widgets encompass the bounds of their children, so I've got a workaround, but thought I'd mention the problem.)

For an example, open up the example scroll view scene with the soft clipped panel.  In one of the items in the scroll view, make the orc armor sprite a child of the sliced sprite, and drag it over so its center is on the left or right edge of the sliced sprite.  Make the "New!" label a child of the orc armor and place its horizontal center on the edge of the sprite.  Now press play and drag the scroll view so that the sliced sprite is outside the clip rect.  You should see the orc armor and the text disappear immediately (except when actively moving the scroll view).

5
NGUI 3 Support / NullReferenceException in UIRect.GetLocalPos
« on: December 10, 2013, 04:25:22 PM »
I may be doing something wrong or using the new anchor system in an unintended way, but…

I have a prefab containing a UIPanel with soft clipping anchored to a parent transform, basically set up to fill the screen minus some padding.  In the Start method of a component of mine in the prefab, I'm modifying the anchor's absolute values based on some other state, then calling UpdateAnchors on the panel so that GetViewSize will return the correct value:

  1. scrollView.panel.bottomAnchor.absolute += footerPadding;
  2. scrollView.panel.UpdateAnchors();

This causes the following exception:

  1. NullReferenceException: Object reference not set to an instance of an object
  2. UIRect.GetLocalPos (.AnchorPoint ac, UnityEngine.Transform trans) (at Assets/Plugins/Client/NGUI/Scripts/Internal/UIRect.cs:212)
  3. UIPanel.OnAnchor () (at Assets/Plugins/Client/NGUI/Scripts/UI/UIPanel.cs:758)
  4. UIRect.UpdateAnchors () (at Assets/Plugins/Client/NGUI/Scripts/Internal/UIRect.cs:309)
  5. MyClass.Start () (at Assets/Scripts/.../MyClass.cs:344)
  6.  

I was able to fix the error by modifying UpdateAnchors in UIRect:

  1.         public void UpdateAnchors ()
  2.         {
  3.                 if (!mAnchorsCached) CacheAnchors();
  4.                 if (isAnchored) OnAnchor();
  5.         }
  6.  

I'm not sure if this is the best fix, or if I should be calling something else from my code to get things to recalculate.  I need to be able to get the correct size of the scroll view later in my Start method to be able to correctly size and position some other elements.

6
NGUI 3 Support / UIAtlasMaker public API
« on: November 12, 2013, 06:16:29 PM »
Would you mind exposing more of the atlas maker's functionality?  I'm trying to automate updating all of the sprites in an atlas from a directory containing the textures, and it's really slow doing it one at a time, and I can't remove sprites with what's currently public.  I'm looking for something along these lines:

  1.         public static void UpdateAtlas(UIAtlas atlas, List<Texture> textures, bool keepSprites)
  2.         {
  3.                 if (atlas != null && textures != null)
  4.                 {
  5.                         List<SpriteEntry> sprites = CreateSprites(textures);
  6.                         ExtractSprites(atlas, sprites);
  7.                         if (!keepSprites)
  8.                         {
  9.                                 sprites.RemoveAll((se) => (textures.Find((t) => t.name == se.name) == null));
  10.                         }
  11.                         UpdateAtlas(atlas, sprites);
  12.                 }
  13.         }
  14.  

7
NGUI 3 Support / UICamera's touch API
« on: October 30, 2013, 02:09:38 PM »
I'm trying to integrate a project's input processing with the work NGUI's already doing in UICamera.  In the past, I've had a separate class that looks at Unity's Input.touches and just does a raycast to see if it's a UI touch and ignores it, but this seems wasteful since I should just be able to ask UICamera.  I see onCustomInput as a handy place to hook in after UICamera has done its work, but getting access to its MouseOrTouch instances is a little wonky.

There's no public access to the mMouse, so if I want to know if a mouse click was on a UI object, I have to figure it out myself.  This is in spite of the fact that mMouse is included in the calculations for touchCount and dragCount.  I do have access to the touches through GetTouch, but this potentially dirties the list of touches if I ask for a touch ID that has been removed.  Also, if I want to account for controller input, onCustomInput is called between mouse/touch processing and controller processing, so that could be problematic.

Of course I can make changes, but for now I'm trying to avoid any custom changes to NGUI to make updating easier.  Am I over-thinking/over-complicating things?  Is there an easier way to go about deciding whether or not to process a touch?

8
So I've got a draggable panel with a scrollbar, and the panel is set to only show the scrollbar when dragging.  That works great, but if I use the scroll wheel, this doesn't make the scrollbar visible like I would expect from a native Mac app.  I changed line 603 of UIDraggablePanel from this:

  1. if (showScrollBars != ShowCondition.WhenDragging || mDragID != -10)
  2.  

to this:

  1. if (showScrollBars != ShowCondition.WhenDragging || mDragID != -10 || mMomentum.magnitude > 0.01f)
  2.  

which makes the scrollbar visible while using the scroll wheel, and has the added benefit of leaving it visible after a drag while momentum is still being applied.  That threshold could maybe be tuned a little bit.  I started with 0.0001f as is used a few lines further down in the class, but that left the bar showing for a bit too long.  Any chance this, or a similar change, could be incorporated?

9
NGUI 3 Support / Font kerning not serialized?
« on: January 11, 2013, 03:24:02 PM »
Looking into a problem with some font spacing today, I noticed that my font prefabs don't have any of the kerning information serialized.  After a little digging, I found that the kerning is stored in a struct, and apparently Unity doesn't support serialization of user-defined structs.  I did this to get the kerning serialized:

  1. diff old/Assets/NGUI/Scripts/Internal/BMGlyph.cs new/Assets/NGUI/Scripts/Internal/BMGlyph.cs
  2. 16c16,17
  3. <       public struct Kerning
  4. ---
  5. >       [System.Serializable]
  6. >       public class Kerning
  7. 67,69c68
  8. <                               Kerning k = kerning[i];
  9. <                               k.amount = amount;
  10. <                               kerning[i] = k;
  11. ---
  12. >                               kerning[i].amount = amount;

10
NGUI 3 Support / Null pointers in BetterList and UIPanel
« on: December 14, 2012, 08:36:59 PM »
We're in the middle of debugging an issue here that I think is related to unloading some bundles, which has exposed some NullReferenceExceptions in BetterList.Contains and UIPanel.GetDrawCall:

  1. NullReferenceException: Object reference not set to an instance of an object
  2.   at BetterList`1[UnityEngine.Material].Contains (UnityEngine.Material item) [0x00000] in <filename unknown>:0
  3.   at UIPanel.UpdateTransforms () [0x00000] in <filename unknown>:0
  4.   at UIPanel.LateUpdate () [0x00000] in <filename unknown>:0
  5.  
  6. NullReferenceException: Object reference not set to an instance of an object
  7.   at UIPanel.GetDrawCall (UnityEngine.Material mat, Boolean createIfMissing) [0x00000] in <filename unknown>:0
  8.   at UIPanel.Fill (UnityEngine.Material mat) [0x00000] in <filename unknown>:0
  9.   at UIPanel.LateUpdate () [0x00000] in <filename unknown>:0
  10.  

The BetterList error should be easy to fix:

  1. for (int i = 0; i < size; ++i) if (buffer[i] != null && buffer[i].Equals(item)) return true;
  2.  
  3. instead of
  4.  
  5. for (int i = 0; i < size; ++i) if (buffer[i].Equals(item)) return true;
  6.  

Unfortunately no line numbers are available in the builds we've seen this in, but I think a null material is sneaking in somewhere when we unload some bundles containing our UI, so UIPanel.GetDrawCall is probably failing on:

  1. GameObject go = new GameObject("_UIDrawCall [" + mat.name + "]");

Whether or not that should be fixed, or how best to fix it without a reliable repro, I'll leave up to you.  That specific error is easy enough to guard against, but if UIDrawCall instances are left hanging around with null materials, that's obviously a bad state that we shouldn't be letting NGUI get into.  We're working on fixing the source of the problem in our code, but I figured these were worth pointing out in case you wanted to deal with them.

11
NGUI 3 Support / Password fields don't respect line width
« on: November 09, 2012, 05:12:43 PM »
I'm seeing odd behavior using a password UIInput with a UILabel that has a line width set.  While entering text into the field, it seems to try to respect the line width, but it does so inconsistently.  The number of stars will increase or decrease as I enter characters, and sometimes the input carat will disappear and later reappear as I'm typing.  When the input loses focus, the label just shows the full number of stars, ignoring the line width completely.

This is with 2.2.3 on unity 3.5.6.

12
NGUI 3 Support / UICamera bug with bundled UIs
« on: November 01, 2012, 08:16:25 PM »
We're using asset bundles with some of our UI, and we discovered that apparently OnDestroy doesn't get called on objects destroyed as a result of a bundle being unloaded.  (At least this is what one of our other engineers tells me.)  That means if you unload a bundle that contained a UICamera, the static list of cameras isn't being properly cleaned up.  Patch below (against a slightly out of date version of NGUI) :

  1. Index: UICamera.cs
  2. ===================================================================
  3. --- UICamera.cs (revision 9034)
  4. +++ UICamera.cs (working copy)
  5. @@ -371,6 +371,8 @@
  6.  
  7.         static int CompareFunc (UICamera a, UICamera b)
  8.         {
  9. +               if (a == null) return b == null ? 0 : 1;
  10. +               if (b == null) return -1;
  11.                 if (a.cachedCamera.depth < b.cachedCamera.depth) return 1;
  12.                 if (a.cachedCamera.depth > b.cachedCamera.depth) return -1;
  13.                 return 0;
  14. @@ -387,7 +389,7 @@
  15.                         UICamera cam = mList[i];
  16.                        
  17.                         // Skip inactive scripts
  18. -                       if (!cam.enabled || !cam.gameObject.active) continue;
  19. +                       if (cam == null || !cam.enabled || !cam.gameObject.active) continue;
  20.  
  21.                         // Convert to view space
  22.                         currentCamera = cam.cachedCamera;
  23. @@ -418,6 +420,7 @@
  24.                 for (int i = 0; i < mList.Count; ++i)
  25.                 {
  26.                         UICamera cam = mList[i];
  27. +                       if (cam == null) continue;
  28.                         Camera uc = cam.cachedCamera;
  29.                         if ((uc != null) && (uc.cullingMask & layerMask) != 0) return cam;
  30.                 }
  31.  


13
NGUI 3 Support / UIEventListener is missing OnKey
« on: September 25, 2012, 04:49:26 PM »
I've added it locally.  Could this be integrated in a future release?

  1.         public delegate void KeyCodeDelegate (GameObject go, KeyCode key);
  2.         public KeyCodeDelegate onKey;
  3.         void OnKey (KeyCode key)                { if (onKey != null) onKey(gameObject, key); }
  4.  

14
NGUI 3 Support / Particle systems and UI scale
« on: September 21, 2012, 07:50:49 PM »
I'm trying to add a little flashiness to my UI with some particle systems, and I'm running into a problem.  I've got a particle system set up that I instantiate as a child of some UI widget, it's in the same layer as the UI and drawn using the same camera, everything looks great.  Switching from an iPad2 to an iPad3, however, gives me particle effects that are a quarter of the size.  On the retina display, the root of my UI hierarchy is being scaled up to twice the height and width to fill the extra pixels, but that scale doesn't affect the particle systems.  Has anybody had any luck dealing with this issue?  The best solution I can think of is to create separate versions of the effects to use on retina displays.

15
NGUI 3 Support / UIButton bug with disabled color
« on: August 15, 2012, 02:39:46 PM »
If a UIButton's tweenTarget is not set, setting isEnabled on the button doesn't change the button's color unless I've already moused over or pressed the button.  Looks like the problem is in UIButton's UpdateColor method:

  1.         if (tweenTarget)
  2.         {
  3.                 if (!mInitDone) Init();
  4.                 // stuff...
  5.         }
  6.  

This version works better:

  1.         if (!mInitDone) Init();
  2.         if (tweenTarget)
  3.         {
  4.                 // stuff...
  5.         }
  6.  

Pages: [1] 2