static void CreatePanel(Transform parent) { UIPrefarencesEditor uIPrefarencesEditor = GetUIPrefarences(); GameObject NatumPanel = new GameObject(); NatumPanel.transform.SetParent(parent); NatumPanel.gameObject.name = "Panel"; NatumPanel.AddComponent <AdvancePanel>(); RectTransform panelRect = NatumPanel.GetComponent <RectTransform>(); panelRect.SetAnchor(AnchorPresets.StretchAll); panelRect.anchoredPosition = Vector3.zero; panelRect.sizeDelta = Vector2.zero; panelRect.localScale = Vector3.one; }
static void CreateButton(Transform parent) { UIPrefarencesEditor uIPrefarencesEditor = GetUIPrefarences(); GameObject NatumButtonObject = new GameObject(); NatumButtonObject.gameObject.name = "Button"; NatumButtonObject.transform.SetParent(parent.transform); AdvanceButton nButton = NatumButtonObject.AddComponent <AdvanceButton>(); nButton.BackgroundImage = NatumButtonObject.GetComponent <Image>();; nButton.BackgroundSprite = uIPrefarencesEditor.ButtonBackgroundSprite; nButton.IconSprite = uIPrefarencesEditor.ButtonIconSprite; nButton.BackgroundImage.preserveAspect = true; nButton.transform.localScale = Vector3.one; nButton.BackgroundImage.hideFlags = HideFlags.HideInInspector; GameObject iconImageObject = new GameObject(); iconImageObject.gameObject.name = "Icon Image"; iconImageObject.transform.SetParent(NatumButtonObject.transform); Image iconImage = iconImageObject.AddComponent <Image>(); nButton.IconImage = iconImage; nButton.IconImage = iconImage; iconImage.raycastTarget = false; iconImage.preserveAspect = true; //iconImage.SetNativeSize(); //iconImageObject.hideFlags = HideFlags.HideInHierarchy; GameObject textMeshObject = new GameObject(); textMeshObject.transform.SetParent(NatumButtonObject.transform); textMeshObject.gameObject.name = "TextMeshProText"; TextMeshProUGUI textMesh = textMeshObject.AddComponent <TextMeshProUGUI>(); nButton.TextMesh = textMesh; textMesh.raycastTarget = false; textMesh.fontSize = 36; textMesh.alignment = TextAlignmentOptions.Center; textMesh.font = uIPrefarencesEditor.TextFont; //textMeshObject.hideFlags = HideFlags.HideInHierarchy; nButton.SetGraphic(); RectTransform textMeshRect = textMeshObject.GetComponent <RectTransform>(); textMeshRect.anchoredPosition = Vector2.zero; textMeshRect.sizeDelta = Vector2.zero; textMeshRect.transform.localScale = Vector3.one; textMeshRect.anchorMin = new Vector2(0, 0); textMeshRect.anchorMax = new Vector2(1, 1); textMeshRect.pivot = new Vector2(0.5f, 0.5f); RectTransform iconRect = iconImageObject.GetComponent <RectTransform>(); iconRect.anchoredPosition = Vector2.zero; iconRect.sizeDelta = Vector2.zero; iconRect.transform.localScale = Vector3.one; iconRect.anchorMin = new Vector2(0, 0); iconRect.anchorMax = new Vector2(1, 1); iconRect.pivot = new Vector2(0.5f, 0.5f); RectTransform buttonRect = NatumButtonObject.GetComponent <RectTransform>(); buttonRect.anchoredPosition = Vector2.zero; nButton.BackgroundImage.SetNativeSize(); Selection.activeObject = NatumButtonObject; }