Exemplo n.º 1
0
        /// <summary>
        /// performs internal recycling of the vp_Timer
        /// </summary>
        private void Recycle()
        {
            Id           = 0;
            DueTime      = -1f;
            StartTime    = 0.0f;
            LifeTime     = 0;
            WillLifeTime = 0;
            Function     = null;
            ArgFunction  = null;
            Arguments    = null;

            FinalFunction = null;

            if (vp_Timer.m_Active.Remove(this))
            {
                m_Pool.Add(this);
            }

#if (UNITY_EDITOR && DEBUG)
            EditorRefresh();
#endif
        }
Exemplo n.º 2
0
 public static extern int sqlite3_create_function(IntPtr db, byte[] functionNameBytes, int argsNumber, int encodingType, IntPtr userDataFunc, FuncCallback func, StepCallback step, FinalCallback final);
Exemplo n.º 3
0
    /// <summary>
    /// the 'Schedule' method sets everything in order for the
    /// timer event to be fired. it also creates a hidden
    /// gameobject upon the first time called (for purposes of
    /// running the Update loop and drawing editor debug info)
    /// </summary>
    private static void Schedule(float time, Callback func, ArgCallback argFunc, object args, FinalCallback finalFunc, Handle timerHandle, int iterations, float interval, float lifeTime)
    {
        if (func == null && argFunc == null)
        {
            UnityEngine.Debug.LogError("Error: (vp_Timer) Aborted event because function is null.");
            return;
        }

        // setup main gameobject
        if (m_MainObject == null)
        {
            m_MainObject = new GameObject("Timers");
            m_MainObject.AddComponent <vp_Timer>();
            UnityEngine.Object.DontDestroyOnLoad(m_MainObject);

#if (UNITY_EDITOR && !DEBUG)
            m_MainObject.gameObject.hideFlags = HideFlags.HideInHierarchy;
#endif
        }

        // force healthy time values
        time       = Mathf.Max(0.0f, time);
        iterations = Mathf.Max(0, iterations);
        interval   = (interval == -1.0f) ? time : Mathf.Max(0.0f, interval);

        // recycle an event - or create a new one if the pool is empty
        m_NewEvent = null;
        if (m_Pool.Count > 0)
        {
            m_NewEvent = m_Pool[0];
            m_Pool.Remove(m_NewEvent);
        }
        else
        {
            m_NewEvent = new Event();
        }

        // iterate the event counter and store the id for this event
        vp_Timer.m_EventCount++;
        m_NewEvent.Id = vp_Timer.m_EventCount;

        // set up the event with its function, arguments and times
        if (func != null)
        {
            m_NewEvent.Function = func;
        }
        else if (argFunc != null)
        {
            m_NewEvent.ArgFunction = argFunc;
            m_NewEvent.Arguments   = args;
        }

        if (finalFunc != null)
        {
            m_NewEvent.FinalFunction = finalFunc;
        }

        m_NewEvent.StartTime    = Time.time;
        m_NewEvent.DueTime      = Time.time + time;
        m_NewEvent.Iterations   = iterations;
        m_NewEvent.Interval     = interval;
        m_NewEvent.LifeTime     = 0;
        m_NewEvent.WillLifeTime = lifeTime;
        m_NewEvent.Paused       = false;

        // add event to the Active list
        vp_Timer.m_Active.Add(m_NewEvent);

        // if a timer handle was provided, associate it to this event,
        // but first cancel any already active event using the same
        // handle: there can be only one ...
        if (timerHandle != null)
        {
            if (timerHandle.Active)
            {
                timerHandle.Cancel();
            }
            // setting the 'Id' property associates this handle with
            // the currently active event with the corresponding id
            timerHandle.Id = m_NewEvent.Id;
        }

#if (UNITY_EDITOR && DEBUG)
        m_NewEvent.StoreCallingMethod();
        EditorRefresh();
#endif
    }
Exemplo n.º 4
0
 public static void In(float delay, Callback callback, FinalCallback finalcallback, float lifeTime, float interval, Handle timerHandle = null)
 {
     Schedule(delay, callback, null, null, finalcallback, timerHandle, -1, interval, lifeTime);
 }