Ejemplo n.º 1
0
 /// <summary>
 /// 往UI操作队列中加入新的操作
 /// </summary>
 /// <param name="ActionName">操作名(记录在日志里)</param>
 /// <param name="UIAction">操作内容</param>
 /// <param name="AnimationID">当前播放动画的ID</param>
 /// <param name="AnimationEnding">动画播放是否结束</param>
 public static void AddNewUIAction(string ActionName, Action UIAction, int AnimationID = 0, bool AnimationEnding = false)
 {
     lock (ActionWaitingList) {
         if (!ActionName.Equals(string.Empty))
         {
             // PLogger.Log("创建操作 " + ActionName + " #" + ActionIDCount.ToString());
         }
         ActionWaitingList.Enqueue(new NamedAction()
         {
             Name        = ActionName,
             ID          = ActionIDCount++,
             AnimationID = AnimationID,
             Action      = () => {
                 if (AnimationID > 0)
                 {
                     CurrentAnimationID = AnimationID;
                 }
                 UIAction();
                 if (AnimationID == CurrentAnimationID && AnimationEnding)
                 {
                     //PLogger.Log("结束动画(真) " + ActionName + " #" + AnimationID);
                     //PLogger.Log("Waiting List:");
                     //WaitingAnimation.ForEach((int x) => PLogger.Log(x.ToString()));
                     CurrentAnimationID++;
                 }
             }
         });
     }
 }
Ejemplo n.º 2
0
 void Update()
 {
     lock (ActionWaitingList) {
         Queue <NamedAction> TempQueue = new Queue <NamedAction>();
         while (ActionWaitingList.Count > 0)
         {
             NamedAction CurrentAction = ActionWaitingList.Dequeue();
             try {
                 if (CurrentAction != null)
                 {
                     if (CurrentAction.AnimationID > 0)
                     {
                         if (CurrentAnimationID > 0 && CurrentAnimationID != CurrentAction.AnimationID)
                         {
                             TempQueue.Enqueue(CurrentAction);
                             continue;
                         }
                         //} else {
                         //    if (CurrentAnimationID == 0) {
                         //        WaitingAnimation.Remove(CurrentAction.AnimationID);
                         //    }
                         //    CurrentAnimationID = CurrentAction.AnimationID;
                         //}
                     }
                     if (!CurrentAction.Name.Equals(string.Empty))
                     {
                         // PLogger.Log("执行操作 " + CurrentAction.ToString());
                     }
                     bool ActionCompleted = false;
                     PThread.Async(() => {
                         PThread.Delay(0.5f);
                         if (!ActionCompleted)
                         {
                             PLogger.Log("操作异常:" + CurrentAction.ToString());
                             throw new TimeoutException("UI操作超时");
                         }
                     });
                     CurrentAction.Action();
                     ActionCompleted = true;
                 }
             } catch (Exception e) {
                 PLogger.Log("操作 " + CurrentAction.ToString() + " 发生错误");
                 PLogger.Log(e.ToString());
             }
         }
         while (TempQueue.Count > 0)
         {
             ActionWaitingList.Enqueue(TempQueue.Dequeue());
         }
     }
 }