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

Pages: [1] 2 3
1
Sorry to resurrect this one again, but I came across this bug in 3.9 as well and wanted to share my fix.

In UIScrollView.cs, after this line:
  1. Vector3 constraint = mPanel.CalculateConstrainOffset(bounds.min, bounds.max);

Add this code:
  1. // modify the offset amounts according to ScrollView movement
  2. if (movement == Movement.Custom)
  3. {
  4.         constraint.x *= customMovement.x;
  5.         constraint.y *= customMovement.y;
  6. }
  7. else if (movement == Movement.Horizontal)
  8. {
  9.         constraint.y = 0.0f;
  10. }
  11. else if (movement == Movement.Vertical)
  12. {
  13.         constraint.x = 0.0f;
  14. }
  15.  

2
Please excuse the dead-thread-resurrection, but I've been experiencing this issue with NGUI 3.6.3 and Unity 4.6.9f1 and I thought I'd post my solution for it in case anyone else has the same problem in the future and isn't making use of SendMessage.

In my case, the symptoms were exactly the same as Nicki, but the culprit was different.  I was making this call:
  1. NGUITools.ImmediatelyCreateDrawCalls(myPanel.gameObject);
while myPanel was inactive in the Hierarchy.  This made for bad times.

Hope it helps someone out there!

3
Doh, of course. 

I normally don't add click handling code within the component itself, I usually compose my components in a different class and assign delegates there.  Stupid mistake, thanks for the help!

4
Has anyone come across this?  I've used UIEventListener.Get to add delegates successfully so many times, all of a sudden this particular one always throws this error (even though the function does get called).

  1. public Class SomeComponent : MonoBehaviour
  2. {
  3.     void Start()
  4.     {
  5.         UIEventListener.Get(this.gameObject).onClick += OnClicked;
  6.     }
  7.  
  8.     private void OnClicked(GameObject go)
  9.     {
  10.         Debug.Log("OnClicked");
  11.     }
  12. }
  13.  

Clicking this GameObject in game will print this in the console:
Quote
Failed to call function OnClick of class SomeComponent
Calling function OnClick with no parameters but the function requires 1.

OnClicked

Everything still works but I have no idea why Unity is throwing this error.  Anyone see this before?

This thread may be relevant too: http://answers.unity3d.com/questions/55194/suggested-workaround-for-sendmessage-bug.html

5
Just a guess, but try putting your UIPanel and UIDraggablePanel components on the same GameObject, instead of separately nested.  Does that help?

6
For the amount of custom code, you should try to find a solution and have them outside the NGUI folder

We do that in most cases but sometimes we've fixed bugs on our own or had to expose some private methods.  Every change is marked and in perforce so when we have to merge it won't be terrible, I just don't want to until we need something from the updates.  Right now we're set.

Custom mods? You should have gotten the Pro version. Your update process would have been painless, and likely auto-merged by the system.

I thought the pro version just included access to the git repo, that it just basically gives access to "nightly builds", which we aren't really interested in.  I like a stable build that does everything I want more than a "cutting edge" build.  Maybe I misunderstood what the pro version offers.

7
2.2.6c is a pretty safe update. It has been out for some time and it doesn't create any new bugs (it did but they got fixed with B and C editions).

Thanks, that's good to know.  I'm not sure which version we have (readme wasn't added to the depot, oops) but it's at least 5 months old and has a decent amount of custom code in it, so I'll still hold off on upgrading for now.  The new feature list is attractive though so it'll probably warrant an update before release.

8
Ugh, serves me right for not checking the change log first.  Still, would be nice if any of the 4 threads here on the subject had been updated.  Thanks for pointing it out.

I'll leave this here in case anyone finds it useful.  We probably won't change versions until the next project, so it's still useful for this current one (at least that's what I'm telling myself) :)

9
Doh!! Haha! Really? What's the script name?

10
Hey everyone,

I've seen a few threads in the past mentioning this issue, and having struggled with it myself, I decided to post a guide on the solution that I've come up with.  I quickly want to point out that I have not yet battle tested this code or profiled it, or spent extra time optimizing, and I in no way guarantee its fitness or reliability.  So use at your own risk!  That said, it seems to be performing admirably in my game so far.  Carrying on...

The problem
Items outside of the clip area on a UIDraggablePanel are still active.  I think most people probably don't want their buttons clickable when they aren't visible.  The typical NGUI solution is to put blocking colliders around your clipping area, above (in the z dimension) your clipped content.  This works just fine but requires some extra labor and for some is annoying to deal with, especially in instances (like in my own game) where multiple UIDraggablePanels are adjacent to one another.

The code based solution
I've written a component that monitors whether or not it is within the clipping rect of a UIDraggablePanel.  When its state (in-bounds, or out-of-bounds) changes, it fires a delegate.  You also get to define the rectangle you want to use for determining whether or not your component is considered in bounds.

Here's an illustration showing how it works:


If you don't want to use delegates, you can also add in your own code here.  Either way, you can write your own code that handles what to do in this situation.  I've included some examples via in line comments.  I'm currently using it to automatically disable / enable the collider of the GameObject the component is attached to.

How to use
You'll need to modify two NGUI files in order to get the component to compile:

  • Add the following function to the UIPanel class in UIPanel.cs:
  1.         /// <summary>
  2.         /// Returns a Rect which describes the clipping area of this panel in Screen (pixel) coordinates.
  3.         /// This is the same area that is drawn with a magenta outline in the Scene gizmos.
  4.         /// </summary>
  5.         public Rect ClippingRectScreen
  6.         {
  7.                 get
  8.                 {
  9.                         Rect r = new Rect();
  10.                         Vector2 size = new Vector2(mClipRange.z, mClipRange.w);
  11.  
  12.                         if (size.x == 0f) size.x = mScreenSize.x;
  13.                         if (size.y == 0f) size.y = mScreenSize.y;
  14.                                                                
  15.                         Vector3 screenPos = UICamera.currentCamera.WorldToScreenPoint(transform.position);
  16.                                                                
  17.                         r.width = size.x;
  18.                         r.height = size.y;
  19.                         r.center = new Vector2(mClipRange.x + screenPos.x, mClipRange.y + screenPos.y);
  20.                                                                
  21.                         return r;
  22.                 }
  23.         }
  24.  
  • Add the following function to the UIDraggablePanel class in UIDraggablePanel.cs:
  1.         /// <summary>
  2.         /// Returns a Rect which describes the clipping area of this panel in Screen (pixel) coordinates.
  3.         /// This is the same area that is drawn with a magenta outline in the Scene gizmos.
  4.         /// </summary>
  5.         public Rect ClippingRectScreen
  6.         {
  7.                 get
  8.                 {
  9.                         return mPanel.ClippingRectScreen;
  10.                 }
  11.         }
  12.  

    Now you're ready to use the component, which is attached.  It uses a simple Axis Aligned Bounding Box hit test (not a Raycast) to determine whether or not the component is within the clip rect of the panel.  The component's "hit rectangle" (named boundsRect) is defined explicitly on the component, though you can have the component simply match the dimensions of the collider on the same GameObject if you choose.  The rect is shown via a Gizmo -- a pink box in the scene view.  I've found that having the rect around 50-60% of the size of the collider results in the behavior I'm looking for.

    It's relatively short and fairly heavily documented in-line, so read in there if you'd like to know more about it, or modify it.  If you want to use a different type of collision test, for example, you can use my code as a starting point for how to get the 2 rectangles in question.

    I hope this helps some people!  Also feel free to check out my company's site or my twitter if you're interested, where I periodically post about Unity gamedev topics.

    11
    NGUI 3 Support / Re: [feature request] UICenterOnChild Event Callback
    « on: November 29, 2012, 09:02:49 PM »
    += means adding multiple listeners, in this case, it is unnecessary.

    To be clear, += means to append a listener to the delegate list, instead of replacing them.  Using = overwrites any other listeners that may be attached to that delegate.

    For that reason, I think this should be +=, I don't want my UIDraggablePanel's other delegates being overwritten by this component.

    12
    NGUI 3 Support / Re: iOS Cross compilation failed on OSX (works on Windows)
    « on: November 15, 2012, 06:08:40 PM »
    Not to resurrect a dead thread, just wanted to note that I had the same error and removing the free version did fix the issue.  I can also confirm that the full version of course works fine. 

    I think the problem stems from the free version's .DLL.  I believe the AOT compiler doesn't probe .dll the same way it would source code.  You could probably write a dummy class that references all methods contained in the DLL in order to work around it but since the error doesn't list which ones it has a problem with, I think upgrading to the full version is probably the easier route :)

    13
    NGUI 3 Support / Re: Automatically resizing labels?
    « on: September 26, 2012, 08:33:41 PM »
    Thanks for the code, but that part I understand already.  I was wondering if there was a way to get "calculatedPrintedSizeX" already in the supplied code, but I don't see one.  I'll go ahead and add my own in.

    14
    NGUI 3 Support / Re: Automatically resizing labels?
    « on: September 26, 2012, 06:33:38 PM »
    Maybe you should have something like that by default in NGUI ? if there is a lineWidth != 0 AND we pressed a boolean then the label should stretch.

    I second that :)

    @ArenMook

    What's the proper way to do this if we want to have a lineWidth set (limited) on the label?  I'm using a label for speech bubbles that size to the text supplied, and also wrap to the next line once they're larger than a certain width.  For labels with lineWidth set, relativeSize.x is always based on lineWidth, even if the content is shorter than the lineWidth.  I think the variable I'd like to get at is the local variable "x" in UIFont::CalculatePrintedSize.  It looks like that's the size of the rendered text in pixels, which would work great for my purposes. 

    I can hack it in, but I suspect there's a better way to go about it :)

    15
    Beautiful :)

    I know it was a silly little issue, but it was coming into play a lot after running the game for awhile.  Thanks so much!

    Pages: [1] 2 3