예제 #1
0
        public override void Update()
        {
            List <InvokeRequest> removeRequests = new List <InvokeRequest>();

            for (int i = 0; i < requests.Count; i++)
            {
                InvokeRequest request = requests[i];

                request.DelayTime -= Time.DeltaTime;
                if (request.DelayTime > 0)
                {
                    continue;
                }
                removeRequests.Add(request); //准备移除
                if (request.Instance == null)
                {
                    continue;
                }
                //调用
                MethodInfo methodInfo = request.Instance.GetType().GetMethod(request.MethodName);
                methodInfo?.Invoke(request.Instance, null);
            }
            //移除
            foreach (InvokeRequest request in removeRequests)
            {
                requests.Remove(request);
            }

            List <DelayAction> removeActions = new List <DelayAction>();

            for (int i = 0; i < delayActions.Count; i++)
            {
                DelayAction delayAction = delayActions[i];

                delayAction.DelayTime -= Time.DeltaTime;
                if (delayAction.DelayTime > 0)
                {
                    continue;
                }
                removeActions.Add(delayAction); //准备移除
                if (delayAction.Action == null)
                {
                    continue;
                }
                delayAction.Action();           //调用
            }
            //移除
            foreach (DelayAction delayAction in removeActions)
            {
                delayActions.Remove(delayAction);
            }
        }