/// <summary> /// Deletes all the UI fields and rebuilds them based on _contact. /// Any unsaved changes on the fields will be lost. Call UpdateContactFromFields() /// before calling Refresh() if changes needed to be saved. /// </summary> private void Refresh() { DestroyListItems(); _nameField.Text = _contact.Name; _nameField.enabled = IsEditing; float yOffset = 0.01f; const float xOffset = -0.25f; const float yOffsetInc = -0.03f; for (int i = 0; i < _contact.PhoneNumberList.Count; ++i) { MLContactsTaggedAttribute phoneNumber = _contact.PhoneNumberList.Items[i]; GameObject itemGO = Instantiate(_attributeItem.gameObject, transform); itemGO.transform.localPosition = new Vector3(xOffset, yOffset, 0); yOffset += yOffsetInc; ContactAttributeItem item = itemGO.GetComponent <ContactAttributeItem>(); item.ContactPage = this; item.Attribute = phoneNumber; item.ListIndex = i; item.DeleteCommand = RemovePhoneNumber; _phoneNumberGOList.Add(itemGO); } _addPhoneButton.gameObject.SetActive(IsEditing); _addPhoneButton.transform.localPosition = new Vector3(xOffset, yOffset, 0); if (IsEditing) { yOffset += 2 * yOffsetInc; } else if (_contact.PhoneNumberList.Count > 0) { yOffset += yOffsetInc; } for (int i = 0; i < _contact.EmailAddressList.Count; ++i) { MLContactsTaggedAttribute emailAddress = _contact.EmailAddressList.Items[i]; GameObject itemGO = Instantiate(_attributeItem.gameObject, transform); itemGO.transform.localPosition = new Vector3(xOffset, yOffset, 0); yOffset += yOffsetInc; ContactAttributeItem item = itemGO.GetComponent <ContactAttributeItem>(); item.ContactPage = this; item.Attribute = emailAddress; item.ListIndex = i; item.DeleteCommand = RemoveEmailAddress; item.enabled = IsEditing; _emailAddressGOList.Add(itemGO); } _addEmailButton.gameObject.SetActive(IsEditing); _addEmailButton.transform.localPosition = new Vector3(xOffset, yOffset, 0); }
/// <summary> /// Update _contact from the UI. /// </summary> private void UpdateContactFromFields() { _contact.Name = _nameField.Text; _contact.PhoneNumberList.Items.Clear(); foreach (GameObject item in _phoneNumberGOList) { ContactAttributeItem attributeItem = item.GetComponent <ContactAttributeItem>(); _contact.PhoneNumberList.Items.Add(attributeItem.Attribute); } _contact.EmailAddressList.Items.Clear(); foreach (GameObject item in _emailAddressGOList) { ContactAttributeItem attributeItem = item.GetComponent <ContactAttributeItem>(); _contact.EmailAddressList.Items.Add(attributeItem.Attribute); } }