Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Capyvara on June 28, 2014, 08:07:13 PM

Title: RealTime problem
Post by: Capyvara on June 28, 2014, 08:07:13 PM
Hi,

Yesterday I faced one Unity bug while trying to play a UITweener on the OnEnable() of one of my scripts, for some reason it delayed a several seconds before starting, I found out it was related to this:

http://forum.unity3d.com/threads/realtimesincestartup-is-not-0-in-first-awake-call.205773/

Basically the Time.realtimeSinceStartup isn't updated yet in the Awake() / OnEnable() calls when the scene is entering play mode in editor.

In order to prevent this I've made some workarounds in RealTime class, not sure if it's the best option (also not well tested):

  1.         static void Spawn ()
  2.         {
  3.                 GameObject go = new GameObject("_RealTime");
  4.                 DontDestroyOnLoad(go);
  5.                 mInst = go.AddComponent<RealTime>();
  6.                 mInst.mRealTime = Time.realtimeSinceStartup;
  7.                 mInst.mInitialRealTime = mInst.mRealTime;
  8.         }
  9.  
  10.         void Update ()
  11.         {
  12.                 float rt = Time.realtimeSinceStartup;
  13.  
  14.                 if (rt < mRealTime) rt += mInitialRealTime;
  15.  
  16.                 mRealDelta = Mathf.Clamp01(rt - mRealTime);
  17.                 mRealTime = rt;
  18.         }
  19.  
Title: Re: RealTime problem
Post by: Nicki on June 29, 2014, 04:11:55 PM
Arguably it should just use http://docs.unity3d.com/ScriptReference/Time-unscaledTime.html now.
Title: Re: RealTime problem
Post by: Capyvara on June 29, 2014, 06:58:44 PM
Arguably it should just use http://docs.unity3d.com/ScriptReference/Time-unscaledTime.html now.

The problem is that it's Unity 4.5 only, and NGUI supports 4.3+
Title: Re: RealTime problem
Post by: ArenMook on June 29, 2014, 10:45:45 PM
Ah, I didn't know it was finally added. I remember mentioning that it was needed back in 2012 when I was in Unity. Good news. I've adjusted the RealTime class accordingly.