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

Pages: [1]
1
NGUI 3 Support / Re: Dynamically create/show text?
« on: August 19, 2013, 11:08:20 AM »
Ah yes, I just found out about AddChild last night and I am using it now, works great!

Thanks for the example lime-green.at, I wasn't calling MakePixelPerfect and that was my problem. Using the AddChild method + MakePixelPerfect is setting everything up correctly.

Thanks guys!

2
NGUI 3 Support / Dynamically create/show text?
« on: August 19, 2013, 12:00:18 AM »
I need to show some feedback text when the player gets something, for example, pickup a hidden token, and "YOU FOUND A GOLDEN TOKEN!" appears on the screen for a few seconds.
Right now, I am instantiating a Prefab which is setup this way: UIRoot-Camera-Panel-UILabel, and I destroy it after X seconds.

But, I already have a main HUD with a UIRoot-Camera-Anchor-Panel present in the scene for my normal HUD, so the way I am doing it above seems over-complicated and creates another UI Camera as well.

Does NGUI have a "CreateHUDText" function/tool I am un-aware of? What would be the better way to show a temporary on-screen message with NGUI?

Thanks for your time!
Stephane

3
NGUI 3 Support / Re: Event for Drag ended?
« on: April 17, 2013, 10:48:20 AM »
Here's a way:
  1. bool wasDragging = false;
  2.  
  3. void OnPress(bool pressed)
  4. {
  5. if (!pressed && wasDragging)
  6. {
  7. wasDragging = false;
  8. //do onDragEnded stuff
  9. }
  10. }
  11.  
  12. void OnDrag(Vector2 delta)
  13. {
  14. wasDragging = true;
  15. }
  16.  
  17.  

Hey Nicki,
Thanks for the example, should work like a charm :)

I'll implement it when I get back home tonight and give it a try.

Stephane

4
NGUI 3 Support / Event for Drag ended?
« on: April 16, 2013, 11:09:46 PM »
Hey guys,
I use the "OnDrag" Event Listener to detect when I'm dragging on a UI element (not drag & drop, just dragging over an area), and I need to know when the Drag ends, for example, when the user lifts its finger. I know about the "OnDrop" and "OnDragFinished" events, but those are part of the UIEventListener class like the "OnDrag" one, and are mostly for detecting when the user drops whatever object he was "moving" correct?

Here's my code:
  1. UIEventListener.Get( preloadBtn ).onDrag += CheckForPreloadNGUI;
  2.  
  3. // The behavior I need is this:
  4. UIEventListener.Get( preloadBtn ).onDragEnded += CancelPreloadNGUI;
  5.  

There is no "OnDragEnded" or "OnDragFinished" that use the "UIEventListener" class, so how can I achieve this? Do I have to use the "OnPress" event to detect when the Drag ends?

Thanks in advance!
Stephane

5
NGUI 3 Support / Re: Failed to wait on a semaphore (errno:15)
« on: April 11, 2013, 03:53:19 AM »
Aren, I have a similar error except mine doesn't crash the game or anything:

Failed to post to a semaphore (errno:15)

Could this be related to NGUI? I never saw this error before I started using NGUI.

Thanks,
Stephane

6
NGUI 3 Support / Re: How to handle each touch separately?
« on: October 15, 2012, 12:53:38 PM »
Hey Aren,
yes I know about .currentTouchID, but it doesn't help me in this case( and that might very well be because I'm not experienced enough to figure out how to use it in my particular case ), my problem was that I was using UICamera.lastHit.collider globally instead of per object touched, so whenever I put a second finger on another object, UICamera.lastHit.collider would change and the first touch was getting canceled.

Now what I'm doing is checking UICamera.lastHit.collider only for the object being dragged on, against the object being dragged on, for each object being dragged on separately. It's working great except I have duplicate code for each object I'm checking, in their Drag() function. So I just need to make 1 function work for every object and get rid of the duplicated code.

Thanks for the quick reply,
Stephane

7
NGUI 3 Support / How to handle each touch separately?
« on: October 14, 2012, 07:39:59 PM »
Hey all,
so I've got my "Update Touch On Drag Past Threshold" working (if finger drags away from button, cancel touch. If finger drags onto another button, update touch...).
But, when testing on the device, I realized that when I place a second finger on the screen, it cancels/updates my first finger touch. What I need to do is handle each touch separately, independent of each other, so that touch 1 doesn't care about touch 2 and vice-versa.

Here's my current code below, and if anyone could point me in the right direction, it would be a huge help :)

  1. public void AccelDrag( GameObject go, Vector2 delta )
  2.         {
  3.                 // Check if user dragged his finger passed the treshold,
  4.                 // and update which UI Element was dragged on
  5.                 HandleTouchTreshold( accelBtn );
  6.                
  7.                 // Turn accel on if we dragged onto it
  8.                 if( UICamera.lastHit.collider != null && !accelOn )
  9.                 {
  10.                         // Send a message instead of "accelOn = true" to re-play button OnPress animations/events
  11.                         accelBtn.SendMessage("OnPress", true, SendMessageOptions.DontRequireReceiver);
  12.                 }
  13.         }
  14.  
  15. public void BrakeDrag( GameObject go, Vector2 delta )
  16.         {
  17.                 // Check if user dragged his finger passed the treshold,
  18.                 // and update which UI Element was dragged on
  19.                 HandleTouchTreshold( brakeBtn, UICamera.currentTouchID );
  20.                
  21.                 // Turn brake on if we dragged onto it
  22.                 if( UICamera.lastHit.collider != null )
  23.                 {
  24.                         // Send a message instead of "brakeOn = true" to re-play button OnPress animations/events
  25.                         brakeBtn.SendMessage("OnPress", true, SendMessageOptions.DontRequireReceiver);
  26.                 }
  27.         }
  28.  
  29. // =================== Function to handle touch treshold ================= //
  30. public void HandleTouchTreshold( GameObject lastGameObject )
  31.         {
  32.                 // Store the last hit gameobject.
  33.                 // If it's null, send OnPress(false) to the lastGameObject, and stop execution.
  34.                 Collider hitCollider = UICamera.lastHit.collider;
  35.                 if( !hitCollider )
  36.                 {
  37. //                      Debug.LogWarning("DRAGGED PAST TRESHOLD");
  38.                         lastGameObject.SendMessage( "OnPress", false, SendMessageOptions.DontRequireReceiver );
  39.                         return;
  40.                 }
  41.                
  42.                 // Detect which UI element we dragged onto
  43.                 GameObject activeGameObject = null;
  44.                 foreach( GameObject go in availableUIElements )
  45.                 {
  46.                         if( hitCollider == go.collider ) activeGameObject = go;
  47.                         else go.SendMessage( "OnPress", false, SendMessageOptions.DontRequireReceiver );
  48.                 }
  49.                
  50.                 // Now that we know the last hit object AND the active object( the one we dragged onto )
  51.                 // we can switch focus to the new object, and activate it.
  52.                 if( hitCollider != lastGameObject.collider )
  53.                 {
  54.                         Debug.LogWarning("DRAGGED ONTO NEW OBJECT: " + UICamera.currentTouch.current);
  55.                        
  56.                         if( hitCollider == activeGameObject.collider )
  57.                         {
  58.                                 UICamera.currentTouch.pressed = activeGameObject;
  59.                                 activeGameObject.SendMessage( "OnPress", true, SendMessageOptions.DontRequireReceiver );
  60.                                 Debug.Log("SENDING ONPRESS TO: " + activeGameObject.name);
  61.                         }
  62.                         else activeGameObject.SendMessage( "OnPress", false, SendMessageOptions.DontRequireReceiver );
  63.                 }
  64.                
  65.         }

Thanks in advance for any help you guys can provide!

Stephane

8
Cool, thx

9
Aren, I'm gonna bug you one more time if you don't mind.
Here's what I'm doing to cancel a touch on a button and activate another one, while dragging( without releasing the mouse button/screen):

  1. Collider hitCollider = UICamera.lastHit.collider;
  2. if( hitCollider != preloadBtn.collider )
  3. {
  4.         UICamera.currentTouch.pressed = null;
  5.         Debug.LogWarning("DRAGGED PAST TRESHOLD\n"+UICamera.currentTouch.current);
  6.        
  7.         if( hitCollider == accelBtn.collider )
  8.         {
  9.                 UICamera.currentTouch.pressed = accelBtn;
  10.                 accelBtn.SendMessage( "OnPress", true, SendMessageOptions.DontRequireReceiver );
  11.         }
  12.                        
  13. }
  14.  

  • First, is it the right way of doing it, or am I doing unnecessary stuff?
  • Second, in the last part of the code within "if( hitCollider == accelBtn.collider )", I have to set currentTouch.pressed = accelBtn manually because if I don't, when I drag onto the accelBtn and release the mouse button/touch, it doesn't send the "OnPress(false)" message, and my flag stays true. Am I doing this wrong, like maybe I'm not using a SendMessage() where/when I should?

Thanks for your time!
Stephane

10
Cool, thanks for the help guys!

11
PoN: Interesting approach, never thought of that before!

Aren: So no, there isn't a built-in way to do this, I have to write my own logic, eg; if( currentTouch.pos > myButton.pos + threshold ) SendMessage("OnPress", false); I just want to make sure I'm not missing something that's already implemented :)

12
Hi there, quick question:

Is there a built-in way to cancel a touch when the user drags his finger past a certain threshold, away from the button which was pressed? For example, in my HUD controls, I have 2 buttons next to each other, 1 for going left <-- and 1 for going right -->. Let's say I start the touch on the left arrow button, when I drag my finger onto the right arrow button, I want to cancel the left arrow button touch and activate the right arrow button touch, without having to lift my finger.

Before I started using NGUI, I was achieving that by doing:

  1. if( leftArrowRect.Contains( myTouch ) ) DoSomething();
  2. else if( rightArrowRect.Contains( myTouch ) DoSomethingElse();
  3.  

which would automatically cancel 1 button press for the other.

Thanks for your time!
Stephane

13
NGUI 3 Support / Re: Detect swipe velocity and start/end
« on: September 25, 2012, 01:05:57 PM »
UICamera.currentTouch.pos tells you the current position of the touch action inside an NGUI event callback such as OnDrag. UICamera.currentTouch.totalDelta tells you the delta since OnPress(true).

Got it, thanks!

14
NGUI 3 Support / Detect swipe velocity and start/end
« on: September 22, 2012, 01:45:28 AM »
Hi guys, i'm new here, and also a new user of NGUI, and I have a few questions...

I have a DetectInput() class which checks for thumb slides. I get the start Vector2 of the slide when calling 'TouchPhase.Began', and then check for the position of the slide in 'TouchPhase.Moved', and if 'slideEnd - slideStart > 200' I then do something.

Does NGUI have a built-in way to check for TouchPhases? I can get the position of the swipe by using 'OnDrag(Vector2 delta)', but how can I check for the delta position when the swipe starts, for example in 'OnPress(bool isPressed)' since it doesn't have a Vector2 parameter?

I don't want to start mixing my touch detection code with NGUI's, so if I can do everything the same with NGUI then I'd rather do that.

Thanks for your time!
Stephane

Pages: [1]