Skip to content

Instantly share code, notes, and snippets.

@IneonInoodle
Created September 11, 2018 08:39
Show Gist options
  • Save IneonInoodle/9ab6ae7d1144417e939d7755446e3db0 to your computer and use it in GitHub Desktop.
Save IneonInoodle/9ab6ae7d1144417e939d7755446e3db0 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Command
{
public static Queue<Command> CommandQueue = new Queue<Command>();
public static bool playingQueue = false;
public virtual void AddToQueue()
{
CommandQueue.Enqueue(this);
if (!playingQueue)
PlayFirstCommandFromQueue();
}
public virtual void StartCommandExecution()
{
// list of everything that we have to do with this command (move, delete, show a message, show a effect, etc...)
// there are 2 options of timing :
// 1) use tween sequences and call CommandExecutionComplete in OnComplete()
// 2) use coroutines (IEnumerator) and WaitFor... to introduce delays, call CommandExecutionComplete() in the end of coroutine
}
public static void CommandExecutionComplete()
{
if (CommandQueue.Count > 0)
PlayFirstCommandFromQueue();
else
playingQueue = false;
if (TurnManager.Instance.whoseTurn != null)
TurnManager.Instance.whoseTurn.HighlightPlayableCards();
}
public static void PlayFirstCommandFromQueue()
{
playingQueue = true;
CommandQueue.Dequeue().StartCommandExecution();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment