protected virtual void OnEnable() { for (int i = 0; i < buttons.Count; i++) { buttons[i].gameObject.SetActive(false); } PlacableData[] allData = DataManager.Instance.GetAllData(PlacableDataType); Button button; for (int i = 0; i < allData.Length; i++) { PlacableData itemData = allData[i]; if (i < buttons.Count) { button = buttons[i]; button.gameObject.SetActive(true); } else { GameObject obj = Instantiate(ButtonPrefab); obj.transform.SetParent(Content, false); (obj.transform as RectTransform).anchoredPosition = new Vector2(175 + (i % 3) * 250, -125 - (i / 3) * 250); button = obj.GetComponent <Button>(); buttons.Add(button); } PlacableButton image = button.GetComponent <PlacableButton>(); image.SetPlacable(itemData); button.onClick.RemoveAllListeners(); button.onClick.AddListener(new UnityEngine.Events.UnityAction(() => { ShowItem(itemData); })); } if ((HelpManager.Instance.CurrentStep == TutorialStep.CraftToy || HelpManager.Instance.CurrentStep == TutorialStep.PlaceToy) && PlacableDataType != PlacableDataType.Toy) { if (buttonFlash == null) { Destroy(buttonFlash); } for (int i = 0; i < buttons.Count; i++) { buttons[i].interactable = false; } Book.FlashTab(PlacableDataType.Toy); } else if (HelpManager.Instance.CurrentStep == TutorialStep.PlaceTreat || HelpManager.Instance.CurrentStep == TutorialStep.CraftToy || HelpManager.Instance.CurrentStep == TutorialStep.PlaceToy) { if (buttonFlash == null) { buttonFlash = Instantiate(uiManager.flashPrefab); } buttonFlash.GetComponent <FlashUI>().SetTarget(buttons[0].targetGraphic as Image); buttons[0].interactable = true; for (int i = 1; i < buttons.Count; i++) { buttons[i].interactable = false; } Book.SetInteractable(false); } else { if (buttonFlash != null) { Destroy(buttonFlash); } for (int i = 0; i < buttons.Count; i++) { buttons[i].interactable = true; } Book.SetInteractable(true); } Book.ShowPage(PlacableDataType); }
void UpdateRecipe(BuildableData[] buildables) { if (current < 0) { current = buildables.Length - 1; } else if (current >= buildables.Length) { current = 0; } bool hasRecipe = PlayerManager.Instance.HasRecipe(buildables[current]); NameLabel.text = buildables[current].Name; ItemImage.sprite = buildables[current].Icon; ItemImage.color = (hasRecipe || buildables[current].Unlimited) ? Color.white : Color.black; PageLabel.text = (current + 1) + " / " + buildables.Length; int count = PlayerManager.Instance.GetInventoryCount(buildables[current]); int areaCount = 0; CountLabel.text = buildables[current].Unlimited ? "\u221E" : count.ToString(); if (buildables[current].Attached) { if (PlacementManager.Instance.CurrentAttached != null && PlacementManager.Instance.CurrentAttached.Data == buildables[current]) { SetUseButton("Return"); UseButton.interactable = true; areaCount = 1; } else { SetUseButton("Use"); UseButton.interactable = count > 0 || buildables[current].Unlimited; } } else { if (PlacementManager.Instance.GetPlayArea().GetInArea(buildables[current]).Count > 0) { SetUseButton("Return"); UseButton.interactable = true; areaCount = 1; } else { SetUseButton("Place"); UseButton.interactable = count > 0 || buildables[current].Unlimited; } } if (buildables[current].Unlimited) { HealthImage.fillAmount = 0f; } else if (count + areaCount > 0) { HealthImage.fillAmount = 1f - (PlayerManager.Instance.GetItemHealth(buildables[current]) - (count + areaCount - 1)); } else { HealthImage.fillAmount = 1f; } if (buildables[current].Unlimited) { for (int i = 0; i < requs.Count; i++) { requs[i].SetActive(false); } CraftButton.gameObject.SetActive(false); } else { if (hasRecipe) { UnknownLabel.gameObject.SetActive(false); for (int i = 0; i < requs.Count; i++) { requs[i].SetActive(false); } Dictionary <PlacableData, int> requCounts = new Dictionary <PlacableData, int>(); for (int i = 0; i < buildables[current].BuildRequirements.Length; i++) { if (requCounts.ContainsKey(buildables[current].BuildRequirements[i])) { requCounts[buildables[current].BuildRequirements[i]]++; } else { requCounts.Add(buildables[current].BuildRequirements[i], 1); } } int requIndex = 0; bool requMissing = false; foreach (KeyValuePair <PlacableData, int> pair in requCounts) { GameObject requObj = null; if (requIndex < requs.Count) { requObj = requs[requIndex]; requObj.SetActive(true); } else { requObj = Instantiate(RequPrefab); requObj.transform.SetParent(Content, false); (requObj.transform as RectTransform).anchoredPosition = new Vector2(125, -210 - 200 * requIndex); requs.Add(requObj); } int invCount = PlayerManager.Instance.GetInventoryCount(pair.Key); requObj.GetComponentInChildren <Image>().sprite = pair.Key.Icon; requObj.GetComponentInChildren <Image>().color = Color.white; requObj.GetComponentInChildren <Text>().text = invCount + " / " + pair.Value; requIndex++; if (invCount < pair.Value) { requMissing = true; } } CraftButton.gameObject.SetActive(true); //CraftButtonText.text = "Craft"; CraftButton.interactable = !requMissing; } else { for (int i = 0; i < requs.Count; i++) { requs[i].SetActive(true); requs[i].GetComponentInChildren <Image>().sprite = null; requs[i].GetComponentInChildren <Image>().color = Color.gray; requs[i].GetComponentInChildren <Text>().text = "? / ?"; } UnknownLabel.gameObject.SetActive(false); //UnknownLabel.text = "????"; CraftButton.gameObject.SetActive(false); CraftButton.interactable = false; } } if ((HelpManager.Instance.CurrentStep == TutorialStep.CraftToy || HelpManager.Instance.CurrentStep == TutorialStep.PlaceToy) && buildables[current].name != "FeltMouse") { if (buttonFlash == null) { Destroy(buttonFlash); } UseButton.interactable = false; CraftButton.interactable = false; prevButton.interactable = false; nextButton.interactable = false; Book.FlashTab(PlacableDataType.Toy); } else if (HelpManager.Instance.CurrentStep == TutorialStep.PlaceTreat || HelpManager.Instance.CurrentStep == TutorialStep.PlaceToy) { if (buttonFlash == null) { buttonFlash = Instantiate(Book.uiManager.flashPrefab); } buttonFlash.GetComponent <FlashUI>().SetTarget(UseButton.targetGraphic as Image); UseButton.interactable = true; CraftButton.interactable = false; prevButton.interactable = false; nextButton.interactable = false; Book.SetInteractable(false); } else if (HelpManager.Instance.CurrentStep == TutorialStep.CraftToy) { if (buttonFlash == null) { buttonFlash = Instantiate(Book.uiManager.flashPrefab); } buttonFlash.GetComponent <FlashUI>().SetTarget(CraftButton.targetGraphic as Image); UseButton.interactable = false; CraftButton.interactable = true; prevButton.interactable = false; nextButton.interactable = false; Book.SetInteractable(false); } else { if (buttonFlash != null) { Destroy(buttonFlash); } prevButton.interactable = true; nextButton.interactable = true; Book.SetInteractable(true); } }