示例#1
0
        public void RemoveListenerForInterval(float interval, System.Action OnUpdate)
        {
            CustomUpdateItem item = intervalItems.FindInList(interval);

            if (item != null)
            {
                item.OnUpdate -= OnUpdate;
                if (item.OnUpdate.GetInvocationList().Length == 0)
                {
                    intervalItems.Remove(item);
                    intervalItemsCount--;
                }
            }
        }
示例#2
0
        private void FixedUpdate()
        {
            for (int i = 0; i < intervalItemsCount; i++)
            {
                CustomUpdateItem update = intervalItems[i];

                update.TimeElapsedCounter += Time.fixedDeltaTime;
                if (update.TimeElapsedCounter > update.TimeInterval)
                {
                    update.TimeElapsedCounter = 0;
                    update.OnUpdate?.Invoke();
                }
            }
        }
示例#3
0
        public void AddListenerForInterval(float interval, System.Action OnUpdate)
        {
            CustomUpdateItem item = intervalItems.FindInList(interval);

            if (item == null)
            {
                item = new CustomUpdateItem()
                {
                    TimeInterval = interval
                };
                intervalItems.Add(item);
                intervalItemsCount++;
            }
            item.OnUpdate += OnUpdate;
        }