public void SelectRecipe(RecipeScriptableObject recipe) { if (LastSpawnedObject) { //the last spawned object didnt get bought if (LastSpawnedObject.followUI) { Destroy(LastSpawnedObject.gameObject); } } displayedRecipes[recipe].GetComponent <RecipeButton>().buttonImage.color = displayedRecipes[recipe].GetComponent <RecipeButton>().defaultColor; Vector3 spawnPos = Camera.main.ScreenToWorldPoint(nodeSpawnPos.position); spawnPos.z = -.5f; GameObject go = Instantiate(nodePrefab, spawnPos, Quaternion.identity); go.GetComponent <Node> ().generateNode(recipe); go.GetComponent <Node> ().IsPreviewNode = true; LastSpawnedObject = go.GetComponent <UIDraggable>(); LastSpawnedObject.followUI = true; LastSpawnedObject.uiAnchor = nodeSpawnPos; if (GameManager.GetCurrentMoney() >= recipe.getPrice()) { PullArrow.enabled = true; } else { PullArrow.enabled = false; } }
/// <summary> /// returns true if the item was found in its dependancies /// </summary> public bool SearchFor(RecipeScriptableObject item) { if (item == this) { return(true); } foreach (var ingredient in ingredients) { if (ingredient && ingredient.SearchFor(item)) { return(true); } } return(false); }
public void UnlockRecipe(RecipeScriptableObject recipe) { //check if tier allows for recipe to be unlocked if (recipe.tier <= currentTier + tiersAboveCurrentAllowed) { if (!unlockedRecipes.Contains(recipe)) { //unlock this recipe unlockedRecipes.Add(recipe); //unlock all children foreach (var childRecipe in recipe.ingredients) { UnlockRecipe(childRecipe); } } } }
/// <summary> /// call this when production finally works on a recipe /// </summary> public void BuiltRecipe(RecipeScriptableObject recipe) { if (!builtRecipes.Contains(recipe)) { builtRecipes.Add(recipe); UnlockRecipe(recipe); foreach (var usedinRecipe in recipe.usedIn) { UnlockRecipe(usedinRecipe); } if (recipe.tier > currentTier) { currentTier = recipe.tier; OnTierIncreased(); } UpdateDisplayedRecipes(); } }
public void LoadAllRecipes() { #if UNITY_EDITOR allRecipes.Clear(); string path = Application.dataPath + "/Recipes"; string[] filePaths = Directory.GetFiles(path, searchPattern: "*", searchOption: SearchOption.AllDirectories); foreach (string s in filePaths) { string assetPath = s.Substring(Application.dataPath.Length - 6); RecipeScriptableObject recipe = AssetDatabase.LoadAssetAtPath <RecipeScriptableObject>(assetPath); if (recipe) { allRecipes.Add(recipe); } } EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); #endif }
public void generateNode(RecipeScriptableObject pRecipe) { foreach (UIConnectorIn i in InConnections) { Destroy(i); } InConnections.Clear(); int ingredients_count = Mathf.Max(pRecipe.ingredients.Count - 1, 0); Background.size = new Vector2(Background.size.x, background_base_height + (ingredients_count * 0.5f)); BoxCollider2D col = GetComponent <BoxCollider2D> (); col.size = new Vector2(col.size.x, col_base_height + (ingredients_count * 0.5f)); col.offset = new Vector2(0, -(ingredients_count * 0.25f)); for (int i = 0; i < pRecipe.ingredients.Count; i++) { RecipeScriptableObject ingredient = pRecipe.ingredients[i]; GameObject go = Instantiate(InPrefab, (inPivot.position + new Vector3(0, -0.5f * i, -0.1f)), Quaternion.identity); InConnections.Add(go.GetComponent <UIConnectorIn> ()); go.transform.SetParent(inPivot, true); go.GetComponent <UIConnectorIn> ().Text.text = ingredient.name; go.GetComponent <UIConnectorIn>().inputRecipe = pRecipe.ingredients[i]; } TitleText.text = pRecipe.GetFullName(); if (pRecipe.IsFinalNode) { Destroy(OutConnection.gameObject); } else { OutConnection.Text.text = pRecipe.name; OutConnection.outputRecipe = pRecipe; } this.gameObject.name = pRecipe.GetFullName() + "_" + (Time.frameCount % 9999999); Recipe = pRecipe; }