public void Load(Tune loadData) { AssembledData = loadData; //Materials for (int i = 0; i < MaterialSlots.Count; i++) { Destroy(MaterialSlots[i].gameObject); } MaterialSlots.Clear(); for (int i = 0; i < AssembledData.CraftMaterials.Count; i++) { CraftMaterialSlot craftMaterialSlot = Instantiate(MaterialSlotTemplate, MaterialTemplate.transform); craftMaterialSlot.gameObject.SetActive(true); craftMaterialSlot.NameInputField.SetTextWithoutNotify(AssembledData.CraftMaterials[i].Name); craftMaterialSlot.AmountInputField.SetTextWithoutNotify(AssembledData.CraftMaterials[i].Amount.ToString()); craftMaterialSlot.GetComponent <RectTransform>().anchoredPosition = new Vector2(MaterialOffset.x, MaterialOffset.y * MaterialSlots.Count); MaterialSlots.Add(craftMaterialSlot); } MaterialAddButton.anchoredPosition = new Vector2(MaterialOffset.x, MaterialOffset.y * MaterialSlots.Count); RecalculateContent(); //Event callback OnRedraw?.Invoke(AssembledData); }
public void UpdateMaterialName(CraftMaterialSlot craftMaterialSlot, string text) { if (IgnoreEvents) { return; } int index = MaterialSlots.IndexOf(craftMaterialSlot); AssembledData.CraftMaterials[index].Name = text; }
public void UpdateMaterialAmount(CraftMaterialSlot craftMaterialSlot, string text) { if (IgnoreEvents) { return; } int index = MaterialSlots.IndexOf(craftMaterialSlot); int.TryParse(text, out int amount); AssembledData.CraftMaterials[index].Amount = amount; }
public void AddMaterialSlot() { CraftMaterialSlot craftMaterialSlot = Instantiate(MaterialSlotTemplate, MaterialTemplate.transform); craftMaterialSlot.gameObject.SetActive(true); craftMaterialSlot.GetComponent <RectTransform>().anchoredPosition = new Vector2(MaterialOffset.x, MaterialOffset.y * MaterialSlots.Count); MaterialSlots.Add(craftMaterialSlot); AssembledData.CraftMaterials.Add(new Tune.CraftMaterial()); MaterialAddButton.anchoredPosition = new Vector2(MaterialOffset.x, MaterialOffset.y * MaterialSlots.Count); RecalculateContent(); }
public void RemoveMaterialSlot(CraftMaterialSlot craftMaterialSlot) { int index = MaterialSlots.IndexOf(craftMaterialSlot); MaterialSlots.RemoveAt(index); AssembledData.CraftMaterials.RemoveAt(index); Destroy(craftMaterialSlot.gameObject); for (int i = index; i < MaterialSlots.Count; i++) { RectTransform slotTransform = MaterialSlots[i].GetComponent <RectTransform>(); slotTransform.anchoredPosition = new Vector2(slotTransform.anchoredPosition.x, slotTransform.anchoredPosition.y - MaterialOffset.y); } MaterialAddButton.anchoredPosition = new Vector2(MaterialOffset.x, MaterialOffset.y * MaterialSlots.Count); RecalculateContent(); }