private static void CreateImage() { GameObject imageObject = ExpansionToolUI.CreateEmptyUIObjectInSelectObject("Image"); var imageComponent = imageObject.AddComponent <Image>(); imageComponent.raycastTarget = false; Selection.activeGameObject = imageObject; }
private static void CreateToggle() { GameObject toggleObject = ExpansionToolUI.CreateEmptyUIObjectInSelectObject("Toggle"); var imageComponent = toggleObject.AddComponent <Image>(); var toggleComponent = toggleObject.AddComponent <Toggle>(); toggleComponent.transition = Selectable.Transition.None; toggleComponent.graphic = imageComponent; toggleComponent.isOn = true; Selection.activeGameObject = toggleObject; }
private static void CreateVerticalScrollView() { // 初期化 GameObject scrollView = ExpansionToolUI.CreateEmptyUIObjectInSelectObject("ScrollView"); var scrollRectComponent = scrollView.AddComponent <ScrollRect>(); GameObject viewport = ExpansionToolUI.CreateEmptyUIObjectInSelectObject("Viewport"); viewport.transform.SetParent(scrollView.transform, false); GameObject content = ExpansionToolUI.CreateEmptyUIObjectInSelectObject("Content"); content.transform.SetParent(viewport.transform, false); // 必要内容の追加 scrollView.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0); scrollView.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 1); scrollView.GetComponent <RectTransform>().sizeDelta = new Vector2(300f, 0f); scrollRectComponent.horizontal = false; viewport.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); viewport.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1); viewport.GetComponent <RectTransform>().sizeDelta = new Vector2(0, 0); viewport.AddComponent <RectMask2D>(); var scrollViewImageComponet = scrollView.AddComponent <Image>(); scrollViewImageComponet.color = new Color(1.0f, 1.0f, 1.0f, 0.7f); scrollRectComponent.content = content.GetComponent <RectTransform>(); scrollRectComponent.viewport = viewport.GetComponent <RectTransform>(); var viewportImageComponet = viewport.AddComponent <Image>(); viewportImageComponet.color = new Color(1.0f, 1.0f, 1.0f, 0f); content.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 1); content.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 1); content.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 1); content.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0); var verticalLayoutGroup = content.AddComponent <VerticalLayoutGroup>(); verticalLayoutGroup.spacing = 50; var contentSizeFitter = content.AddComponent <ContentSizeFitter>(); contentSizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; Selection.activeGameObject = content; }