Beispiel #1
0
        private static void Schedule(float time, Callback func, ArgCallback argFunc, object args, Handle timerHandle, int iterations, float interval)
        {
            if (func == null && argFunc == null)
            {
                UnityEngine.Debug.LogError("Error: (TimerManager) Aborted event because function is null.");
                return;
            }

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

            mNewEvent = null;
            if (mPool.Count > 0)
            {
                mNewEvent = mPool [0];
                mPool.Remove(mNewEvent);
            }
            else
            {
                mNewEvent = new Event();
            }

            TimerManager.mEventCount++;
            mNewEvent.ID = TimerManager.mEventCount;

            if (func != null)
            {
                mNewEvent.Function = func;
            }
            else if (argFunc != null)
            {
                mNewEvent.ArgFunction = argFunc;
                mNewEvent.Arguments   = args;
            }
            mNewEvent.StartTime  = Time.time;
            mNewEvent.DueTime    = Time.time + time;
            mNewEvent.Iterations = iterations;
            mNewEvent.Interval   = interval;
            mNewEvent.LifeTime   = 0.0f;
            mNewEvent.Paused     = false;
            TimerManager.mActive.Add(mNewEvent);

            if (timerHandle != null)
            {
                if (timerHandle.Active)
                {
                    timerHandle.Cancel();
                }
                timerHandle.ID = mNewEvent.ID;
            }

                        #if (UNITY_EDITOR && DEBUG)
            mNewEvent.StoreCallingMethod();
            EditorRefresh();
                        #endif
        }
Beispiel #2
0
 ///////////////////////////////////////////////////////////
 // internal disabling of the vp_Timer
 ///////////////////////////////////////////////////////////
 private void CancelInstance()
 {
     if (this != null)
     {
         m_Function    = null;
         m_ArgFunction = null;
         m_Arguments   = null;
         enabled       = false;
         hideFlags     = HideFlags.HideInInspector;
     }
 }
Beispiel #3
0
    public static bool Cancel(ArgCallback fun)
    {
        if (fun == null)
        {
            return(false);
        }

        for (int t = vp_Timer.m_Active.Count - 1; t > -1; t--)
        {
            if (vp_Timer.m_Active[t].ArgFunction == fun)
            {
                vp_Timer.m_Active[t].Id = 0;
                return(true);
            }
        }

        return(false);
    }
Beispiel #4
0
    // internal schedule method
    private static vp_Timer In(float time, Callback func, ArgCallback argFunc, object args, int iterations, float interval)
    {
        if (m_GameObject == null)
        {
            m_GameObject = new GameObject("Timers");
            Object.DontDestroyOnLoad(m_GameObject);

            // by default gameobject will be invisible in the hierarchy.
            // disabling this may be useful for debugging
            m_GameObject.hideFlags = HideFlags.HideInHierarchy;
        }

        vp_Timer firstTimer = null;

        float currentTime = time;

        interval = (interval == 0.0f) ? time : interval;

        for (int i = 0; i < iterations; i++)
        {
            vp_Timer timer = m_GameObject.AddComponent <vp_Timer>();
            if (i == 0)
            {
                firstTimer = timer;
            }
            else
            {
                firstTimer.m_Iterations.Add(timer);
            }

            if (func != null)
            {
                timer.Schedule(currentTime, func);
            }
            else if (argFunc != null)
            {
                timer.Schedule(currentTime, argFunc, args);
            }

            currentTime += interval;
        }

        return(firstTimer);
    }
Beispiel #5
0
            private void Recycle()
            {
                ID        = 0;
                DueTime   = 0.0f;
                StartTime = 0.0f;

                Function    = null;
                ArgFunction = null;
                Arguments   = null;

                if (TimerManager.mActive.Remove(this))
                {
                    mPool.Add(this);
                }

#if (UNITY_EDITOR && DEBUG)
                EditorRefresh();
#endif
            }
        /// <summary>
        /// performs internal recycling of the vp_Timer
        /// </summary>
        public void Recycle()
        {
            Id        = 0;
            DueTime   = 0.0f;
            StartTime = 0.0f;

            Function    = null;
            ArgFunction = null;
            Arguments   = null;

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

#if (UNITY_EDITOR && DEBUG)
            EditorRefresh();
#endif
        }
Beispiel #7
0
        /// <summary>
        /// performs internal recycling of the vp_Timer
        /// </summary>
        private void Recycle()
        {
            Id           = 0;
            DueTime      = 0.0f;
            StartTime    = 0.0f;
            CancelOnLoad = true;

            Function    = null;
            ArgFunction = null;
            Arguments   = null;

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

#if (UNITY_EDITOR && DEBUG)
            EditorRefresh();
#endif
        }
Beispiel #8
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
        }
Beispiel #9
0
	/// <summary>
	/// schedules an event by time + callback + arguments + [timer handle]
	/// <summary>
	public static void In(float delay, ArgCallback callback, object arguments, Handle timerHandle = null)
	{ Schedule(delay, null, callback, arguments, timerHandle, 1, -1.0f); }
Beispiel #10
0
 // schedule a method with arguments
 public static vp_Timer In(float time, ArgCallback function, object args, int iterations = 1, float interval = 0.0f)
 {
     return In(time, null, function, args, iterations, interval);
 }
Beispiel #11
0
 // schedules a method with arguments
 private void Schedule(float time, ArgCallback function, object args)
 {
     m_ArgFunction = function;
     m_Arguments = args;
     Invoke("ArgExecute", time);
 }
Beispiel #12
0
 ///////////////////////////////////////////////////////////
 // internal disabling of the vp_Timer
 ///////////////////////////////////////////////////////////
 private void CancelInstance()
 {
     if (this != null)
     {
         m_Function = null;
         m_ArgFunction = null;
         m_Arguments = null;
         enabled = false;
         hideFlags = HideFlags.HideInInspector;
     }
 }
Beispiel #13
0
    // internal schedule method
    private static vp_Timer In(float time, Callback func, ArgCallback argFunc, object args, int iterations, float interval)
    {
        if (m_GameObject == null)
        {

            m_GameObject = new GameObject("Timers");
            Object.DontDestroyOnLoad(m_GameObject);

            // by default gameobject will be invisible in the hierarchy.
            // disabling this may be useful for debugging
            m_GameObject.hideFlags = HideFlags.HideInHierarchy;

        }

        vp_Timer firstTimer = null;

        float currentTime = time;

        interval = (interval == 0.0f) ? time : interval;

        for (int i = 0; i < iterations; i++)
        {
            vp_Timer timer = m_GameObject.AddComponent<vp_Timer>();
            if (i == 0)
                firstTimer = timer;
            else
                firstTimer.m_Iterations.Add(timer);

            if(func != null)
                timer.Schedule(currentTime, func);
            else if (argFunc != null)
                timer.Schedule(currentTime, argFunc, args);

            currentTime += interval;
        }

        return firstTimer;
    }
    /// <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, Handle timerHandle, int iterations, float interval)
    {
        //  Debug.LogError("interval" + interval + " time" + time + " iterations" + iterations);

        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("[vp_Timer_UnScaleTime]");
            m_MainObject.AddComponent <vp_Timer_UnScaleTime>();
            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_UnScaleTime.m_EventCount++;
        m_NewEvent.Id = vp_Timer_UnScaleTime.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;
        }
        m_NewEvent.StartTime  = Time.unscaledTime;
        m_NewEvent.DueTime    = Time.unscaledTime + time;
        m_NewEvent.Iterations = iterations;
        m_NewEvent.Interval   = interval;
        m_NewEvent.LifeTime   = 0.0f;
        m_NewEvent.Paused     = false;

        // add event to the Active list
        vp_Timer_UnScaleTime.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)
            {
                //  Debug.LogError("你妹子啊 ,你知道错了吗》?????????");
                timerHandle.Cancel();
            }

            // setting the 'Id' property associates this handle with
            // the currently active event with the corresponding id
            timerHandle.Id = m_NewEvent.Id;
            //  Debug.LogError("timerHandle.Id" + timerHandle.Id);
        }

#if (UNITY_EDITOR && DEBUG)
        m_NewEvent.StoreCallingMethod();
        EditorRefresh();
#endif
    }
 // time + callback + arguments + [timer handle]
 public static void In(float delay, ArgCallback callback, object arguments, Handle timerHandle = null)
 {
     Schedule(delay, null, callback, arguments, timerHandle, 1, -1.0f);
 }
Beispiel #16
0
 // schedules a method with arguments
 private void Schedule(float time, ArgCallback function, object args)
 {
     m_ArgFunction = function;
     m_Arguments   = args;
     Invoke("ArgExecute", time);
 }
Beispiel #17
0
 // schedule a method with arguments
 public static vp_Timer In(float time, ArgCallback function, object args, int iterations = 1, float interval = 0.0f)
 {
     return(In(time, null, function, args, iterations, interval));
 }
Beispiel #18
0
 public static void AddTimer(float delay, ArgCallback callback, object arguments, int iterations, Handle timerHandle = null)
 {
     Schedule(delay, null, callback, arguments, timerHandle, iterations, -1.0f);
 }
Beispiel #19
0
	/// <summary>
	/// schedules an event by time + callback + arguments + iterations + interval + [timer handle]
	/// <summary>
	public static void In(float delay, ArgCallback callback, object arguments, int iterations, float interval, Handle timerHandle = null)
	{ Schedule(delay, null, callback, arguments, timerHandle, iterations, interval); }
 // time + callback + arguments + iterations + interval + [timer handle]
 public static void In(float delay, ArgCallback callback, object arguments, int iterations, float interval, Handle timerHandle = null)
 {
     Schedule(delay, null, callback, arguments, timerHandle, iterations, interval);
 }
Beispiel #21
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, Handle timerHandle, int iterations, float interval)
	{

		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;
		}
		m_NewEvent.StartTime = Time.time;
		m_NewEvent.DueTime = Time.time + time;
		m_NewEvent.Iterations = iterations;
		m_NewEvent.Interval = interval;
		m_NewEvent.LifeTime = 0.0f;
		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

	}
Beispiel #22
0
		/// <summary>
		/// performs internal recycling of the vp_Timer
		/// </summary>
		private void Recycle()
		{

			Id = 0;
			DueTime = 0.0f;
			StartTime = 0.0f;
			CancelOnLoad = true;

			Function = null;
			ArgFunction = null;
			Arguments = null;

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

#if (UNITY_EDITOR && DEBUG)
			EditorRefresh();
#endif

		}
Beispiel #23
0
    // internal schedule method
    private static vp_Timer At(float time, Callback func, ArgCallback argFunc, object args, int iterations, float interval)
    {
        vp_Timer firstTimer = null;

        float currentTime = time;

        interval = (interval == 0.0f) ? time : interval;

        for (int i = 0; i < iterations; i++)
        {
            vp_Timer timer = m_GameObject.AddComponent<vp_Timer>();
            if (i == 0)
                firstTimer = timer;
            else
                firstTimer.m_Iterations.Add(timer);

            if(func != null)
                timer.Schedule(currentTime, func);
            else if (argFunc != null)
                timer.Schedule(currentTime, argFunc, args);

            currentTime += interval;
        }

        return firstTimer;
    }