private void CompleteCraft() { // tell the observers it is complete, start the next if there is one if (OnCraftingComplete != null) { OnCraftingComplete(_currentlyCrafting.Recipe); } if (OnCraftingCompleteUI != null) { OnCraftingCompleteUI(_currentlyCrafting.Recipe, _currentlyCrafting.ID); } _currentlyCrafting = null; CheckForBeginCrafting(); }
// This, CancelCrafting() and the Recipe callbacks are the typical in-game usage public int QueueCrafting(Recipe recipe) { _lastId++; var queued = new QueuedRecipe { ID = _lastId, Recipe = recipe }; _recipeQueue.Add(queued); if (OnCraftingQueued != null) { OnCraftingQueued(queued.Recipe, queued.ID); } CheckForBeginCrafting(); return(queued.ID); }
private void BeginCrafting(QueuedRecipe queuedRecipe) { var recipe = queuedRecipe.Recipe; // will most likely not make it here in the first place, but jic if (recipe.Container.Name != Info.Name) { throw new UnityException(string.Format("{0} was given a recipe for {1}", Info.Name, recipe.Container.Name)); } // may replace with WorldTime when it is a more flexible type var seconds = WorldClock.Instance.GetSeconds(recipe.TimeLength); StopWatch.AddNode(STOPWATCH_NAME, seconds, true).OnTick = CompleteCraft; _currentlyCrafting = queuedRecipe; if (OnCraftingBegin != null) { OnCraftingBegin(queuedRecipe.Recipe, queuedRecipe.ID); } }
private void CancelCurrentCraft() { _currentlyCrafting = null; StopWatch[STOPWATCH_NAME].Reset(0); StopWatch[STOPWATCH_NAME].Pause(); }