Exemple #1
0
    private void TransformTimeFormat(int time)
    {
        //DateTime.
        TimerUtil.RemoveTimeOutWithCallBack(timerID);
        TimerUtil.RemoveTimeOut(timerID);

        TimeSpan ts    = new TimeSpan(0, 0, time);
        TimeSpan timer = new TimeSpan(0, 0, 1);

        timerID = TimerUtil.SetTimeOut(1f, () => {
            if (isTimePause)
            {
                return;
            }
            ts = ts.Subtract(timer);
            ui_ShowText.text = ts.ToString(@"mm\:ss");
            //Debug.Log($"当前倒计时:{ts.ToString(@"mm\:ss")}");
            if (ts.TotalSeconds <= 0)
            {
                TimerUtil.RemoveTimeOutWithCallBack(timerID);
                TimerUtil.RemoveTimeOut(timerID);
                Debug.Log($"倒计时结束,游戏结束");
                GameCtrl._Ins.EC.OnGameOver(GameCtrl._Ins.CurrPattern, false);
            }
        }, -1);
    }
        private void OnGlobalHotkeyUp(object sender, GlobalKeyEventArgs e)
        {
            if (PendingGlobalCommand == null)
            {
                return;
            }

            var hotKey = e.HotKey;

            // Execute the pending command only if no modifier key is pressed or it will mess up the keystrokes
            // sent from the command
            if (InputUtil.IsSame(hotKey.Key, hotKey.Modifiers) || !InputUtil.IsModifierKey(hotKey.Key))
            {
                // If hotKey.Key is a modifier key, that modifier key state is still down at the time this event
                // is fired, which may interfere with the keystrokes sent from the automation command below, so we
                // will have to wait a bit more
                TimerUtil.SetTimeOut(() =>
                {
                    // The automation command will probably send some keystrokes (e.g. Ctrl-V to paste text or something)
                    // We dont want the global hook receives and processes those events, thus run this command again
                    _winService.GlobalKeyUp -= OnGlobalHotkeyUp;
                    PendingGlobalCommand.Execute(null);
                    PendingGlobalCommand     = null;
                    _winService.GlobalKeyUp += OnGlobalHotkeyUp;
                }, 1);
            }
        }
 public void StartBornConveyor()
 {
     //CreateConveyor();
     conveyorTimerID = TimerUtil.SetTimeOut(GameCtrl._Ins.CurrLevelData.Conveyorrate, () => {
         CreateConveyor();
     }, -1);
 }
 public void StartBornFood()
 {
     //CreateOneFood(GetOneFoodData());
     foodTimerID = TimerUtil.SetTimeOut(GameCtrl._Ins.CurrLevelData.Foodrate, () => {
         CreateOneFood(GetOneFoodData());
     }, -1);
 }
Exemple #5
0
 private void OnTweenScaleEnd()
 {
     if (isOpen)
     {
         TimerUtil.SetTimeOut(0.1f, new TimerUtil.Callback(OnNextFrame));
     }
     else
     {
         RealClose();
     }
 }
    public void TriggerAward(Action CallBack = null)
    {
        StopBornFood();
        StopBornConveyor();
        for (int i = 0; i < foodList.Count; i++)
        {
            if (foodList[i].isUsing)
            {
                foodList[i].splineMove.Pause();
            }
        }
        for (int i = 0; i < conveyorList.Count; i++)
        {
            conveyorList[i].splineMove.Pause();
        }
        List <FoodItem> awardList = new List <FoodItem>();

        for (int i = 0; i < foodList.Count; i++)
        {
            if (!foodList[i].isUsing)
            {
                continue;
            }
            if (GameCtrl._Ins.CheckIfInView(foodList[i].transform.position))
            {
                foodList[i].GetComponent <Image>().color = Color.red;
                awardList.Add(foodList[i]);
            }
        }
        if (awardList.Count == 0)
        {
            Debug.Log($"punishList.Count = 0,直接return了");
            CallBack?.Invoke();
            return;
        }
        Vector2 pos1   = Vector2.zero;
        Vector2 screen = GameCtrl._Ins.UIcamera.WorldToScreenPoint(Player._Ins.transform.position);

        RectTransformUtility.ScreenPointToLocalPointInRectangle(transform as RectTransform, screen,
                                                                GameCtrl._Ins.UIcamera, out pos1);
        for (int i = 0; i < awardList.Count; i++)
        {
            awardList[i].boxcollider.enabled = false;
        }

        TimerUtil.SetTimeOut(0.5f, () => {
            for (int i = 0; i < awardList.Count; i++)
            {
                var item = awardList[i];

                int index = i;
                TimerUtil.SetTimeOut(i * 0.2f, () => {
                    if (index != awardList.Count - 1)
                    {
                        item.transform.DOLocalMove(pos1, 0.5f).OnComplete(() => {
                            item.ResetItem();
                            item.GetComponent <Image>().color = Color.white;
                            GameCtrl._Ins.EC.OnCheckCaptureFood?.Invoke(item);
                        });
                    }
                    else
                    {
                        // 最后一个加上回调
                        item.transform.DOLocalMove(pos1, 0.5f).OnComplete(() => {
                            item.ResetItem();
                            item.GetComponent <Image>().color = Color.white;
                            GameCtrl._Ins.EC.OnCheckCaptureFood?.Invoke(item);
                            CallBack?.Invoke();
                        });
                    }
                });
            }
        });
    }
    public void TriggerPunishment(Action CallBack = null)
    {
        StopBornFood();
        StopBornConveyor();
        for (int i = 0; i < foodList.Count; i++)
        {
            if (foodList[i].isUsing)
            {
                foodList[i].splineMove.Pause();
            }
        }
        for (int i = 0; i < conveyorList.Count; i++)
        {
            conveyorList[i].splineMove.Pause();
        }
        // 开始效果
        List <FoodItem> punishList = new List <FoodItem>();

        for (int i = 0; i < foodList.Count; i++)
        {
            if (!foodList[i].isUsing)
            {
                continue;
            }
            if (GameCtrl._Ins.CheckIfInView(foodList[i].transform.position))
            {
                foodList[i].GetComponent <Image>().color = Color.red;
                punishList.Add(foodList[i]);
            }
        }
        if (punishList.Count == 0)
        {
            Debug.Log($"punishList.Count = 0,直接return了");
            CallBack?.Invoke();
            return;
        }

        Vector2 pos1, pos2;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(transform as RectTransform, new Vector2(Screen.width / 2, Screen.height / 2),
                                                                GameCtrl._Ins.UIcamera, out pos1);
        RectTransformUtility.ScreenPointToLocalPointInRectangle(transform as RectTransform, new Vector2(Screen.width, Screen.height),
                                                                GameCtrl._Ins.UIcamera, out pos2);
        for (int i = 0; i < punishList.Count; i++)
        {
            punishList[i].boxcollider.enabled = false;
            //punishList[i].transform.DOLocalMove(pos1, 0.5f);
        }
        TimerUtil.SetTimeOut(0.5f, () => {
            for (int i = 0; i < punishList.Count; i++)
            {
                var item = punishList[i];

                int index = i;
                TimerUtil.SetTimeOut(i * 0.2f, () => {
                    if (index != punishList.Count - 1)
                    {
                        item.transform.DOLocalMove(pos2, 0.5f).OnComplete(() => {
                            item.ResetItem();
                            item.GetComponent <Image>().color = Color.white;
                            Debug.Log($"惩罚废除了dishArriveNum++,惩罚销毁数量:{punishList.Count}");
                            GameCtrl._Ins.DishArriveNum++;
                            GameCtrl._Ins.EC.OnRefreshCurrDishNum?.Invoke(GameCtrl._Ins.DishArriveNum);
                        });
                    }
                    else
                    {
                        // 最后一个加上回调
                        item.transform.DOLocalMove(pos2, 0.5f).OnComplete(() => {
                            item.ResetItem();
                            item.GetComponent <Image>().color = Color.white;
                            Debug.Log($"惩罚废除了dishArriveNum++,惩罚销毁数量:{punishList.Count}");
                            GameCtrl._Ins.DishArriveNum++;
                            GameCtrl._Ins.EC.OnRefreshCurrDishNum?.Invoke(GameCtrl._Ins.DishArriveNum);
                            CallBack?.Invoke();
                        });
                    }
                });
            }
        });
    }