private void InstantiateAttachmentButton(ToyAttachment attachment, Transform content) { var buttonPrefab = Instantiate(AttachmentButtonPrefab); buttonPrefab.GetComponent <Button>().onClick.AddListener(() => { m_GameTracker.AddToyAttachment(attachment); }); buttonPrefab.GetComponentInChildren <Image>().sprite = attachment.mySprite; buttonPrefab.GetComponentInChildren <Text>().text = attachment.friendlyName; buttonPrefab.transform.SetParent(content); }
public void AddToyAttachment(ToyAttachment toyAttachment) { if (m_BaseToyObject == null) { return; } var attachmentObject = Instantiate(toyAttachment.ItemPrefab); attachmentObject.transform.SetParent(ToyCreationRoot); var attachmentAttachPoint = attachmentObject.GetComponentInChildren <AttachmentData>(); var slotType = attachmentAttachPoint.Slot; var slot = m_BaseToyObject.GetComponentsInChildren <AttachmentData>() .FirstOrDefault(a => a.Slot == slotType); if (slot == null) { Debug.Log("That don't go there son!"); return; } for (var i = 0; i < ToyCreationRoot.childCount; i++) { var child = ToyCreationRoot.GetChild(i); if (child.gameObject == m_BaseToyObject) { continue; } if (child.GetComponentInChildren <AttachmentData>()?.Slot == slotType && attachmentObject != child.gameObject) { Destroy(child.gameObject); } } AttachTheThingToTheOtherThing(slot, attachmentAttachPoint); ToyAttachments.Add(toyAttachment); }
public void RemoveToyAttachment(ToyAttachment attachment) { ToyAttachments.Remove(attachment); }