//Creating objects public static PortraitTagSelector CreateObject() { UICommon uICommon = Game.Instance.UI.Common; GameObject parentElement = uICommon?.transform.Find("CharacterBuild/Body/Content")?.gameObject; //TODO: remake to instantiate from Constitution instead GameObject preFab = uICommon?.transform.Find("CharacterBuild/Body/Content/RaceRightSide/Constitution")?.gameObject; TextMeshProUGUI labelPreFab = uICommon?.transform.Find("CharacterBuild/Body/Content/RaceRightSide/Constitution/LabelPlace/Label/LabelText").gameObject.GetComponent <TextMeshProUGUI>(); if (!parentElement || !preFab || !labelPreFab) { return(null); } GameObject portraitTagSelectorCanvas = Instantiate(preFab, parentElement.transform, false); portraitTagSelectorCanvas.AddComponent <CanvasGroup>(); portraitTagSelectorCanvas.transform.SetSiblingIndex(0); //Initialize transform Mod.Debug("Initialize transform"); portraitTagSelectorCanvas.name = "PortraitTagSelector"; RectTransform rectPortraitTagSelector = (RectTransform)portraitTagSelectorCanvas.transform; rectPortraitTagSelector.anchorMin = new Vector2(0.68f, 1.0f); rectPortraitTagSelector.anchorMax = new Vector2(0.68f, 1.0f); rectPortraitTagSelector.pivot = new Vector2(0.5f, 0.5f); // rectPortraitTagSelector.localPosition = preFabPos; rectPortraitTagSelector.localPosition -= rectPortraitTagSelector.forward; rectPortraitTagSelector.rotation = Quaternion.identity; //TODO Initialize children positions (copy from prefab?) TextMeshProUGUI _Label = portraitTagSelectorCanvas.transform.Find("LabelPlace/Label/LabelText").gameObject.GetComponent <TextMeshProUGUI>(); RectTransform rectLabel = (RectTransform)_Label.transform; rectLabel.anchoredPosition = rectLabel.parent.position; rectLabel.anchorMin = new Vector2(0.0F, 1.0F); rectLabel.anchorMax = new Vector2(0.0F, 1.0F); rectLabel.pivot = new Vector2(0.5F, 0.5F); rectLabel.localPosition += rectLabel.forward; UIHelpers.CopyTextMeshProUGUI(ref _Label, labelPreFab); CharBSequentialSelector charBSequentialSelector = portraitTagSelectorCanvas.transform.Find("SequentialSelector").gameObject.GetComponent <CharBSequentialSelector>(); //Buttons Button BackButton = portraitTagSelectorCanvas.transform.Find("SequentialSelector/SequentialSelector/ButtonPlaceBackSelector").gameObject.GetComponent <Button>(); charBSequentialSelector.m_BackButton = BackButton; Button NextButton = portraitTagSelectorCanvas.transform.Find("SequentialSelector/SequentialSelector/ButtonPlaceNextSelector").gameObject.GetComponent <Button>(); charBSequentialSelector.m_NextButton = NextButton; TextMeshProUGUI Counter = portraitTagSelectorCanvas.transform.Find("SequentialSelector/SequentialSelector/GameObject/Counter").gameObject.GetComponent <TextMeshProUGUI>(); charBSequentialSelector.m_Counter = Counter; charBSequentialSelector.m_Label = _Label; Mod.Debug("Initialized"); return(portraitTagSelectorCanvas.AddComponent <PortraitTagSelector>()); }