예제 #1
0
        public void ExcuteTimeEvent(Dictionary <int, TimeEvent> eventDic, List <int> rmList)
        {
            if (rmList != null && rmList.Count > 0)
            {
                foreach (int item in rmList)
                {
                    if (eventDic.ContainsKey(item))
                    {
                        eventDic.Remove(item);
                    }
                }
                rmList.Clear();
            }

            if (eventDic != null && eventDic.Count > 0)
            {
                foreach (var itemKey in eventDic.Keys)
                {
                    TimeEvent item = eventDic[itemKey];
                    //如果是立即执行
                    if (item.now)
                    {
                        if (item.overDe != null)
                        {
                            item.overDe();
                        }
                        item.now   = false;
                        item.count = item.count > 0 ? --item.count : item.count;
                        if (item.count == 0)
                        {
                            RemoveTimeEvent(itemKey);
                        }
                    }

                    //已经到达时间
                    if (item.deltaTime >= item.waitTime)
                    {
                        //执行方法,并移除model
                        try
                        {
                            item.overDe?.Invoke();
                        }
                        catch (System.Exception ex)
                        {
                            RemoveTimeEvent(itemKey);
                            Debug.Log(ex.ToString());
                            return;
                        }

                        item.deltaTime = 0;
                        item.count     = item.count > 0 ? --item.count : item.count;
                        if (item.count == 0)
                        {
                            RemoveTimeEvent(itemKey);
                        }
                    }
                    else
                    {
                        float deltaTime = item.ignoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime;
                        item.deltaTime += deltaTime;

                        if (item.updateDe != null)
                        {
                            float leaveTime = item.waitTime - item.deltaTime;

                            leaveTime = (int)(leaveTime * 100) / 100f;

                            float percent = (item.deltaTime) / item.waitTime;

                            percent = (int)(percent * 100) / 100f;//0.1~1

                            try
                            {
                                item.updateDe(Mathf.Max(0, leaveTime), Mathf.Min(1, percent));
                            }
                            catch (System.Exception ex)
                            {
                                Debug.Log(ex.ToString());
                                RemoveTimeEvent(itemKey);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        private void LateUpdate()
        {
            if (rmTEvents_late != null && rmTEvents_late.Count > 0)
            {
                foreach (TimeEvent item in rmTEvents_late)
                {
                    if (rmTEvents_late.Contains(item))
                    {
                        rmTEvents_late.Remove(item);
                    }
                }
                rmTEvents_late.Clear();
            }

            if (rmTEvents_late != null && rmTEvents_late.Count > 0)
            {
                for (int i = 0; i < rmTEvents_late.Count; i++)
                {
                    TimeEvent item = rmTEvents_late[i];

                    //如果是立即执行
                    if (item.now)
                    {
                        if (item.overDe != null)
                        {
                            item.overDe();
                        }
                        item.now   = false;
                        item.count = item.count > 0 ? --item.count : item.count;
                        if (tEvents_up[i].count == 0)
                        {
                            RemoveTimeEvent(item);
                        }
                    }

                    //已经到达时间
                    if (item.deltaTime >= item.waitTime)
                    {
                        //执行方法,并移除model
                        try {
                            item.overDe?.Invoke();
                        }
                        catch (System.Exception ex) {
                            RemoveTimeEvent(item);
                            Debug.Log(ex.ToString());
                            return;
                        }

                        item.deltaTime = 0;
                        item.count     = item.count > 0 ? --item.count : item.count;
                        if (item.count == 0)
                        {
                            RemoveTimeEvent(item);
                        }
                    }
                    else
                    {
                        float deltaTime = item.ignoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime;
                        item.deltaTime += deltaTime;

                        if (item.updateDe != null)
                        {
                            float leaveTime = item.waitTime - item.deltaTime;

                            leaveTime = (int)(leaveTime * 100) / 100f;

                            float percent = (item.deltaTime) / item.waitTime;

                            percent = (int)(percent * 100) / 100f;//0.1~1

                            try {
                                item.updateDe(Mathf.Max(0, leaveTime), Mathf.Min(1, percent));
                            }
                            catch (System.Exception ex) {
                                Debug.Log(ex.ToString());
                                RemoveTimeEvent(item);
                            }
                        }
                    }
                }
            }
        }