public void Initialize(FamilyTree.Person person) { siblingsData.anchoredPosition = new Vector3(0, -177.712f, 0); childrenData.anchoredPosition = new Vector3(0, -177.712f, 0); personName.text = person.name; if (person.hasSiblings) { foreach (string sibling in person.siblings) { GameObject text = Instantiate(textPrefab, siblingsData); text.GetComponent <TextMeshProUGUI>().text = sibling; } } else { GameObject text = Instantiate(textPrefab, siblingsData); text.GetComponent <TextMeshProUGUI>().text = "None"; } if (!person.hasParent1 && !person.hasParent2) { parentsData.text = "None"; } else if (person.hasParent1 && !person.hasParent2) { parentsData.text = "(1) " + person.parent1Name; } else if (person.hasParent1 && person.hasParent2) { parentsData.text = "(1) " + person.parent1Name + Environment.NewLine + "(2) " + person.parent2Name; } if (person.hasSpouse) { spouseData.text = person.spouseName; } else { spouseData.text = "None"; } if (person.hasChildren) { foreach (string child in person.children) { GameObject text = Instantiate(textPrefab, childrenData); text.GetComponent <TextMeshProUGUI>().text = child; } } else { GameObject text = Instantiate(textPrefab, childrenData); text.GetComponent <TextMeshProUGUI>().text = "None"; } }
public void UpdateData() { data = FamilyTree.tree[data.name]; if (data.hasParent1 && transform.parent.name != data.parent1Name) { transform.SetParent(Spawner.paths[data.parent1Name].transform, false); SpringJoint2D joint = transform.GetComponent <SpringJoint2D>(); if (joint == null) { joint = gameObject.AddComponent <SpringJoint2D>(); } joint.connectedBody = transform.parent.GetComponent <Rigidbody2D>(); joint.autoConfigureDistance = false; joint.distance = 3; } if (!data.hasParent1 && !data.hasParent2) { GetComponent <Rigidbody2D>().isKinematic = true; GetComponent <Rigidbody2D>().velocity = Vector2.zero; } else { GetComponent <Rigidbody2D>().isKinematic = false; if (data.hasParent1 && !parent1Linked) { parent1Linked = true; GameObject line = Instantiate(linePrefab, transform); line.name = "Parent1Link"; line.GetComponent <Line>().child = gameObject; line.GetComponent <Line>().parent = Spawner.paths[data.parent1Name]; line.GetComponent <Line>().Initialize(new Color(0.7f, 0.7f, 0.65f), Color.black); } if (data.hasParent2 && !parent2Linked) { parent2Linked = true; GameObject line = Instantiate(linePrefab, transform); line.name = "Parent2Link"; line.GetComponent <Line>().child = gameObject; line.GetComponent <Line>().parent = Spawner.paths[data.parent2Name]; line.GetComponent <Line>().Initialize(new Color(0.7f, 0.7f, 0.65f), Color.black); } } if (data.hasSpouse && !spouseLinked) { spouseLinked = true; GameObject line = Instantiate(linePrefab, transform); line.name = "SpouseLink"; line.GetComponent <Line>().child = gameObject; line.GetComponent <Line>().parent = Spawner.paths[data.spouseName]; line.GetComponent <Line>().Initialize(Color.red, Color.red); } }
public void Spawn(FamilyTree.Person person) { if (paths.ContainsKey(person.name)) { return; } GameObject personGameObject = Instantiate(personPrefab, transform); personGameObject.name = person.name; paths.Add(personGameObject.name, personGameObject); personGameObject.GetComponent <Person>().data = person; personGameObject.GetComponent <Person>().Initialize(); }