コード例 #1
0
ファイル: CCScheduler.cs プロジェクト: lonag/cocos-u3d
        /** The scheduled method will be called every 'interval' seconds.
         *   If paused is YES, then it won't be called until it is resumed.
         *   If 'interval' is 0, it will be called every frame, but if so, it recommened to use 'scheduleUpdateForTarget:' instead.
         *   If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
         *
         *   @since v0.99.3
         */
        public void scheduleSelector(SEL_SCHEDULE selector, SelectorProtocol target, float fInterval, bool bPaused)
        {
            if (selector == null)
            {
                throw (new ArgumentNullException("selector", "Schedule selector can not be null"));
            }
            if (target == null)
            {
                throw (new ArgumentNullException("target", "Schedule target must be set."));
            }

            tHashSelectorEntry element = null;

            if (!m_pHashForSelectors.ContainsKey(target))
            {
                element        = new tHashSelectorEntry();
                element.target = target;
                m_pHashForSelectors[target] = element;

                // Is this the 1st element ? Then set the pause level to all the selectors of this target
                element.paused = bPaused;
            }
            else
            {
                element = m_pHashForSelectors[target];

                Debug.Assert(element.paused == bPaused);
            }

            if (element.timers == null)
            {
                element.timers = new List <CCTimer>();
            }
            else
            {
                foreach (CCTimer timer in element.timers)
                {
                    if (selector == timer.m_pfnSelector)
                    {
                        CCLog.Log("CCSheduler#scheduleSelector. Selector already scheduled.");
                        timer.m_fInterval = fInterval;
                        return;
                    }
                }
            }

            CCTimer timer2 = new CCTimer();

            timer2.initWithTarget(target, selector, fInterval);
            element.timers.Add(timer2);
        }
コード例 #2
0
ファイル: CCScheduler.cs プロジェクト: lonag/cocos-u3d
        /** Unschedule a selector for a given target.
         *   If you want to unschedule the "update", use unscheudleUpdateForTarget.
         *   @since v0.99.3
         */
        public void unscheduleSelector(SEL_SCHEDULE selector, SelectorProtocol target)
        {
            // explicity handle nil arguments when removing an object
            if (selector == null || target == null)
            {
                return;
            }

            if (m_pHashForSelectors.ContainsKey(target))
            {
                tHashSelectorEntry element = m_pHashForSelectors[target];

                for (int i = 0; i < element.timers.Count; i++)
                {
                    CCTimer timer = element.timers[i];

                    if (selector == timer.m_pfnSelector)
                    {
                        if (timer == element.currentTimer && (!element.currentTimerSalvaged))
                        {
                            element.currentTimerSalvaged = true;
                        }

                        element.timers.RemoveAt(i);

                        // update timerIndex in case we are in tick:, looping over the actions
                        if (element.timerIndex >= i)
                        {
                            element.timerIndex--;
                        }

                        if (element.timers.Count == 0)
                        {
                            if (m_pCurrentTarget == element)
                            {
                                m_bCurrentTargetSalvaged = true;
                            }
                            else
                            {
                                removeHashElement(element);
                            }
                        }

                        return;
                    }
                }
            }
        }