コード例 #1
0
 private static void Schedule(float time, vp_Timer.Callback func, vp_Timer.ArgCallback argFunc, object args, vp_Timer.Handle timerHandle, int iterations, float interval)
 {
     if (func == null && argFunc == null)
     {
         Debug.LogError("Error: (vp_Timer) Aborted event because function is null.");
         return;
     }
     if (vp_Timer.m_MainObject == null)
     {
         vp_Timer.m_MainObject = new GameObject("Timers");
         vp_Timer.m_MainObject.AddComponent <vp_Timer>();
         UnityEngine.Object.DontDestroyOnLoad(vp_Timer.m_MainObject);
     }
     time                = Mathf.Max(0f, time);
     iterations          = Mathf.Max(0, iterations);
     interval            = ((interval != -1f) ? Mathf.Max(0f, interval) : time);
     vp_Timer.m_NewEvent = null;
     if (vp_Timer.m_Pool.Count > 0)
     {
         vp_Timer.m_NewEvent = vp_Timer.m_Pool[0];
         vp_Timer.m_Pool.Remove(vp_Timer.m_NewEvent);
     }
     else
     {
         vp_Timer.m_NewEvent = new vp_Timer.Event();
     }
     vp_Timer.m_EventCount++;
     vp_Timer.m_NewEvent.Id = vp_Timer.m_EventCount;
     if (func != null)
     {
         vp_Timer.m_NewEvent.Function = func;
     }
     else if (argFunc != null)
     {
         vp_Timer.m_NewEvent.ArgFunction = argFunc;
         vp_Timer.m_NewEvent.Arguments   = args;
     }
     vp_Timer.m_NewEvent.StartTime  = Time.time;
     vp_Timer.m_NewEvent.DueTime    = Time.time + time;
     vp_Timer.m_NewEvent.Iterations = iterations;
     vp_Timer.m_NewEvent.Interval   = interval;
     vp_Timer.m_NewEvent.LifeTime   = 0f;
     vp_Timer.m_NewEvent.Paused     = false;
     vp_Timer.m_Active.Add(vp_Timer.m_NewEvent);
     if (timerHandle != null)
     {
         if (timerHandle.Active)
         {
             timerHandle.Cancel();
         }
         timerHandle.Id = vp_Timer.m_NewEvent.Id;
     }
 }
コード例 #2
0
 private void Recycle()
 {
     this.Id          = 0;
     this.DueTime     = 0f;
     this.StartTime   = 0f;
     this.Function    = null;
     this.ArgFunction = null;
     this.Arguments   = null;
     if (vp_Timer.m_Active.Remove(this))
     {
         vp_Timer.m_Pool.Add(this);
     }
 }
コード例 #3
0
 public static void In(float delay, vp_Timer.ArgCallback callback, object arguments, int iterations, float interval, vp_Timer.Handle timerHandle = null)
 {
     vp_Timer.Schedule(delay, null, callback, arguments, timerHandle, iterations, interval);
 }
コード例 #4
0
 public static void In(float delay, vp_Timer.ArgCallback callback, object arguments, vp_Timer.Handle timerHandle = null)
 {
     vp_Timer.Schedule(delay, null, callback, arguments, timerHandle, 1, -1f);
 }