Ejemplo n.º 1
0
 private void CheckInput()
 {
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         if (currentAction != null)
         {
             currentAction.OnCancel();
             currentAction = null;
             actionQueue.Clear();
         }
         return;
     }
     for (int i = 0; i < inputActions.Count; i++)
     {
         KeyCode[] keys = inputActions[i].keys;
         for (int j = 0; j < keys.Length; j++)
         {
             //only hadles 1 key for now
             if (Input.GetKeyDown(keys[j]))
             {
                 string actionId = inputActions[i].actionId;
                 PlayerCharacterAction action = actionMap.Get(actionId);
                 if (action != null)
                 {
                     actionQueue.Enqueue(new QueuedAction(action));
                     return;
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        public void Update()
        {
            CheckInput();
            currentAction = currentAction ?? Dequeue();

            if (currentAction != null)
            {
                CharacterActionStatus actionStatus = currentAction.OnUpdate();

                switch (actionStatus)
                {
                case CharacterActionStatus.Running:
                    break;

                case CharacterActionStatus.Cancelled:
                    currentAction.OnCancel();
                    currentAction.OnCleanup();
                    currentAction = null;
                    break;

                case CharacterActionStatus.Completed:
                    currentAction.OnComplete();
                    currentAction.OnCleanup();
                    currentAction = null;
                    break;
                }
            }
        }