Author Topic: UpdateManager  (Read 5103 times)

Matthias

  • Guest
UpdateManager
« on: April 19, 2012, 04:55:59 PM »
Hi,

any idea what would cause the UpdateManager not to call its registered coroutines? I can't find any docs on it. It seems like the UpdateManager object is created automatically, I can see it in the scene when I run the app. I can also see the list of registered functions in the the UpdateManager object in the debugger. However it doesn't call them.

Thanks for your help!
Matthias

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UpdateManager
« Reply #1 on: April 19, 2012, 05:00:35 PM »
Is the update manager's coroutine function running? It gets added in StartCoroutine(CoroutineFunction()), and it will stop if there are no more coroutines. I don't think I use that feature anywhere, so it's what you might call... untested. Any reason why you can't just start a coroutine yourself though?

Matthias

  • Guest
Re: UpdateManager
« Reply #2 on: April 19, 2012, 05:06:58 PM »
I don't know. I don't have the source for UpdateManager (should I?). I am still working with the trial version. Seems like the DragDrop classes aren't in that either.
I'm basically trying a similar setup like in the dragging window example in my app. I can set a breakpoint in LagPosition.cs and CoroutineUpdate is called once and then never again.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UpdateManager
« Reply #3 on: April 19, 2012, 05:18:36 PM »
The free version of NGUI is over 2 months old and comes as-is, meaning it's not supported anymore. Full version of NGUI has source code for everything including the update manager. LagPosition also has a checkbox 'useUpdateManager' which you can simply turn off to make it stop using the update manager.

Matthias

  • Guest
Re: UpdateManager
« Reply #4 on: April 19, 2012, 05:34:11 PM »
I see. Sounds like I need to pull the trigger on the purchase now. Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UpdateManager
« Reply #5 on: April 19, 2012, 05:43:52 PM »
Hehe wow, you didn't wait much after posting that, I see. :)

Matthias

  • Guest
Re: UpdateManager
« Reply #6 on: April 19, 2012, 07:00:11 PM »
Yeah, I was pretty certain since yesterday that I was going to purchase and I just wanted to see how far I can get with the demo version and if I run into anything that would disqualify NGUI. But your system appears to be the best out there right now for Unity, it's really inspired. Also I am soooo tired of spending days and days arranging UI controls in code.  ;)

I'd definitely recommend making the demo up to date, I'm sure I'm not the only one who makes their decision depending on their experience with the demo version.

Anyway, I debugged a while and I could not get it to work unless I turn off 'Ignore Time Scale' which is what's using the coroutine instead of LateUpdate. I didn't see a useUpdateManager checkbox in LagPosition of the full version. Looks identical to the demo version code.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UpdateManager
« Reply #7 on: April 20, 2012, 06:50:08 AM »
Aha, I was looking at Windward's LagPosition, my bad... that one has the checkbox. Here's Windward's script:

  1. using UnityEngine;
  2.  
  3. /// <summary>
  4. /// Attach to a game object to make its position always lag behind its parent as the parent moves.
  5. /// </summary>
  6.  
  7. [AddComponentMenu("NGUI/Examples/Lag Position")]
  8. public class LagPosition : MonoBehaviour
  9. {
  10.         public bool useUpdateManager = false;
  11.         public int updateOrder = 0;
  12.         public Vector3 speed = new Vector3(10f, 10f, 10f);
  13.         public bool ignoreTimeScale = false;
  14.        
  15.         Transform mTrans;
  16.         Vector3 mRelative;
  17.         Vector3 mAbsolute;
  18.  
  19.         void Start ()
  20.         {
  21.                 mTrans = transform;
  22.                 mRelative = mTrans.localPosition;
  23.  
  24.                 if (useUpdateManager)
  25.                 {
  26.                         if (ignoreTimeScale) UpdateManager.AddCoroutine(this, updateOrder, CoroutineUpdate);
  27.                         else UpdateManager.AddLateUpdate(this, updateOrder, CoroutineUpdate);
  28.                 }
  29.         }
  30.  
  31.         void OnEnable()
  32.         {
  33.                 mTrans = transform;
  34.                 mAbsolute = mTrans.position;
  35.         }
  36.  
  37.         void LateUpdate ()
  38.         {
  39.                 if (!useUpdateManager) CoroutineUpdate(Time.deltaTime);
  40.         }
  41.  
  42.         void CoroutineUpdate (float delta)
  43.         {
  44.                 Transform parent = mTrans.parent;
  45.                
  46.                 if (parent != null)
  47.                 {
  48.                         Vector3 target = parent.position + parent.rotation * mRelative;
  49.                         mAbsolute.x = Mathf.Lerp(mAbsolute.x, target.x, Mathf.Clamp01(delta * speed.x));
  50.                         mAbsolute.y = Mathf.Lerp(mAbsolute.y, target.y, Mathf.Clamp01(delta * speed.y));
  51.                         mAbsolute.z = Mathf.Lerp(mAbsolute.z, target.z, Mathf.Clamp01(delta * speed.z));
  52.                         mTrans.position = mAbsolute;
  53.                 }
  54.         }
  55. }

Matthias

  • Guest
Re: UpdateManager
« Reply #8 on: April 20, 2012, 11:33:24 AM »
Great, thanks!