public void Setup() { #if UNITY_EDITOR Action codeToExecute = delegate() { UnityEditor.EditorApplication.ExecuteMenuItem("GameObject/UI/Button"); }; CreateSceneUtility.CreateScene(k_SceneName, codeToExecute); #endif }
public void Setup() { #if UNITY_EDITOR Action codeToExecute = delegate() { var canvasGO = new GameObject("CanvasToAddImage", typeof(Canvas)); var imageGO = new GameObject("ImageOnCanvas", typeof(UnityEngine.UI.Image)); imageGO.transform.localPosition = Vector3.one; imageGO.transform.SetParent(canvasGO.transform); imageGO.AddComponent <CanvasSizeCorrectInAwakeAndStartScript>(); canvasGO.GetComponent <Canvas>().renderMode = RenderMode.ScreenSpaceOverlay; imageGO.SetActive(false); }; CreateSceneUtility.CreateScene(k_SceneName, codeToExecute); #endif }
public void Setup() { #if UNITY_EDITOR Action codeToExecute = delegate() { var canvasGameObject = new GameObject(kGameObjectName, typeof(Canvas)); canvasGameObject.SetActive(false); canvasGameObject.GetComponent <Canvas>().renderMode = RenderMode.ScreenSpaceOverlay; canvasGameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(0, 0); canvasGameObject.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0); CanvasScaler canvasScaler = canvasGameObject.AddComponent <CanvasScaler>(); canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; canvasScaler.referenceResolution = new Vector2(1024, 768); }; CreateSceneUtility.CreateScene(kSceneName, codeToExecute); #endif }
public void Setup() { #if UNITY_EDITOR Action aspectRatioFitterSceneCreation = delegate() { var canvasGO = new GameObject("Canvas", typeof(Canvas), typeof(CanvasScaler)); var panelGO = new GameObject("Panel", typeof(UnityEngine.UI.Image), typeof(AspectRatioFitter)); var imageGO = new GameObject("Image", typeof(UnityEngine.UI.RawImage), typeof(AspectRatioFitter)); panelGO.transform.SetParent(canvasGO.transform); imageGO.transform.SetParent(panelGO.transform); var panelARF = panelGO.GetComponent <AspectRatioFitter>(); panelARF.aspectMode = AspectRatioFitter.AspectMode.EnvelopeParent; panelARF.aspectRatio = 1.98f; var iamgeARF = imageGO.GetComponent <AspectRatioFitter>(); iamgeARF.aspectMode = AspectRatioFitter.AspectMode.None; iamgeARF.aspectRatio = 1f; new GameObject("GameObject", typeof(SceneWithNestedLayoutElementsLoadScript)); }; CreateSceneUtility.CreateScene("AspectRatioFitter", aspectRatioFitterSceneCreation); Action contentSizeFitterSceneCreation = delegate() { var canvasGO = new GameObject("Canvas", typeof(Canvas), typeof(CanvasScaler)); var panelGO = new GameObject("Panel", typeof(UnityEngine.UI.Image), typeof(ContentSizeFitter), typeof(LayoutElement)); var imageGO = new GameObject("Image", typeof(UnityEngine.UI.RawImage), typeof(ContentSizeFitter), typeof(LayoutElement)); panelGO.transform.SetParent(canvasGO.transform); imageGO.transform.SetParent(panelGO.transform); var panelCSF = panelGO.GetComponent <ContentSizeFitter>(); panelCSF.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; panelCSF.verticalFit = ContentSizeFitter.FitMode.PreferredSize; var panelLE = panelGO.GetComponent <LayoutElement>(); panelLE.preferredWidth = 200f; panelLE.preferredHeight = 200f; var imageCSF = imageGO.GetComponent <ContentSizeFitter>(); imageCSF.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; imageCSF.verticalFit = ContentSizeFitter.FitMode.PreferredSize; var imageLE = imageGO.GetComponent <LayoutElement>(); imageLE.preferredWidth = 100f; imageLE.preferredHeight = 100f; new GameObject("GameObject", typeof(SceneWithNestedLayoutElementsLoadScript)); }; CreateSceneUtility.CreateScene("ContentSizeFitter", contentSizeFitterSceneCreation); Action layoutGroupSceneCreation = delegate() { var canvasGO = new GameObject("Canvas", typeof(Canvas), typeof(CanvasScaler), typeof(GridLayoutGroup)); var panelGO = new GameObject("Panel (0)", typeof(UnityEngine.UI.Image), typeof(GridLayoutGroup), typeof(LayoutElement)); var imageGOOne = new GameObject("Image", typeof(UnityEngine.UI.RawImage), typeof(LayoutElement)); var imageGOTwo = new GameObject("Image", typeof(UnityEngine.UI.RawImage), typeof(LayoutElement)); panelGO.transform.SetParent(canvasGO.transform); imageGOOne.transform.SetParent(panelGO.transform); imageGOTwo.transform.SetParent(panelGO.transform); var panelLE = panelGO.GetComponent <LayoutElement>(); panelLE.preferredWidth = 100f; panelLE.preferredHeight = 100f; var imageOneLE = imageGOOne.GetComponent <LayoutElement>(); imageOneLE.preferredWidth = 100f; imageOneLE.preferredHeight = 100f; var imageTwoLE = imageGOOne.GetComponent <LayoutElement>(); imageTwoLE.preferredWidth = 100f; imageTwoLE.preferredHeight = 100f; // Duplicate the first panel we created. GameObject.Instantiate(panelGO, canvasGO.transform); new GameObject("GameObject", typeof(SceneWithNestedLayoutElementsLoadScript)); }; CreateSceneUtility.CreateScene("LayoutGroup", layoutGroupSceneCreation); #endif }