public static void UpdateRecipe(PointerEventData o) { if (o.pointerEnter.GetComponent <Button>() != null) { scrBtnBuildRecipeData rec = o.pointerEnter.GetComponent <scrBtnBuildRecipeData>(); WorldController.Instance.UpdateRecipe(rec.ToString()); } }
void Start() { Button btnConcrete = MakeButton("btnBuild::Concrete", "Concrete", null); btnConcrete.onClick.AddListener(delegate { WorldController.Instance.SetBuildType_Tile("concrete"); }); Button btnRemove = MakeButton("btnBuild::Deconstruct", "Remove", null); btnRemove.onClick.AddListener(delegate { WorldController.Instance.SetBuildType_Deconstruct(); }); //add a button for building each type of installed item foreach (InstalledItem proto in InstalledItem.prototypes.Values. Where(e => e.build). OrderBy(e => e.niceName)) { Button btn = MakeButton(proto); AddButtonEvent(btn, data => { scrUIBuildMenu.UpdateRecipe((PointerEventData)data); } ); //EventTrigger trig = btn.GetComponent<EventTrigger>(); //EventTrigger.Entry entry = new EventTrigger.Entry(); //entry.eventID = EventTriggerType.PointerEnter; //entry.callback.AddListener(data => { scrUIBuildMenu.UpdateRecipe((PointerEventData)data); }); //trig.triggers.Add(entry); scrBtnBuildRecipeData recipeData = btn.GetComponent <scrBtnBuildRecipeData>(); if (recipeData != null) { recipeData.AddKeyValuePair("name", proto.niceName); recipeData.AddRecipe(proto.recipe); } if (proto.workRecipeName != null && proto.workRecipeName != "") { Recipe r = Recipe.GetRecipe(proto.workRecipeName); if (r != null && r.onDemand) { btn = Instantiate(btnBuildPrefab, Vector2.zero, Quaternion.identity); btn.transform.SetParent(this.transform); btn.GetComponentInChildren <Text>().text = r.btnText; btn.name = "btnBuild::" + r.name + "::ondemand"; btn.onClick.AddListener(delegate { World.current.InstalledItems_AssignOnDemandJobs(proto.type); }); btn.transform.localScale = Vector2.one; SetButtonSprite(btn, proto.spriteName + NYDISpriteManager.ICON_SUFFIX); AddButtonEvent(btn, data => { scrUIBuildMenu.UpdateRecipe((PointerEventData)data); } ); recipeData = btn.GetComponent <scrBtnBuildRecipeData>(); if (recipeData != null) { recipeData.AddKeyValuePair("name", r.btnText); recipeData.AddRecipe(r); } } } } //foreach (string recipeName in Recipe.GetRecipeNames()) { // Recipe recipe = Recipe.GetRecipe(recipeName); // if (recipe != null) { // if (recipe.onDemand) { // } // } //} }