void SetRequButton(int i, PlacableData itemData) { requs[i].SetActive(true); PlacableButton image = requs[i].GetComponent <PlacableButton>(); image.SetPlacable(itemData); Button button = requs[i].GetComponent <Button>(); button.onClick.RemoveAllListeners(); button.onClick.AddListener(new UnityEngine.Events.UnityAction(() => { Book.ShowItem(itemData); })); }
protected override void OnEnable() { for (int i = 0; i < Content.childCount; i++) { Destroy(Content.GetChild(i).gameObject); } MaterialType[] materialTypes = System.Enum.GetValues(typeof(MaterialType)) as MaterialType[]; for (int i = 0; i < materialTypes.Length; i++) { int level = DataManager.Instance.GetTowerLevel(materialTypes[i]); PlacableData itemData = DataManager.Instance.GetTower(materialTypes[i], level == 0 ? 1 : level); GameObject obj = Instantiate(ButtonPrefab); obj.transform.SetParent(Content, false); (obj.transform as RectTransform).anchoredPosition = new Vector2(175 + (i % 3) * 250, -125 - (i / 3) * 250); PlacableButton image = obj.GetComponent <PlacableButton>(); image.SetPlacable(itemData); Button button = obj.GetComponent <Button>(); button.onClick.RemoveAllListeners(); button.onClick.AddListener(new UnityEngine.Events.UnityAction(() => { ShowItem(itemData); })); } Book.ShowPage(PlacableDataType); }
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); }