private static void CreateSamplePosImage() { GameObject canvasObject = ExpansionToolUI.CreateEmptyUIObject("SamplePosImageCanvas"); var canvas = canvasObject.AddComponent <Canvas>(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; canvas.sortingOrder = 100; var canvasScaler = canvasObject.AddComponent <CanvasScaler>(); canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; canvasScaler.referenceResolution = new Vector2(ExpansionToolUI.CanvasSizeX, ExpansionToolUI.CanvasSizeY); canvasScaler.screenMatchMode = CanvasScaler.ScreenMatchMode.Expand; canvasObject.AddComponent <GraphicRaycaster>(); GameObject imageObject = ExpansionToolUI.CreateEmptyUIObject("SamplePosImage"); var childObjectImage = imageObject.AddComponent <Image>(); imageObject.transform.SetParent(canvasObject.transform, false); imageObject.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); imageObject.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1); imageObject.GetComponent <RectTransform>().sizeDelta = Vector2.zero; childObjectImage.color = new Color(1.0f, 1.0f, 1.0f, 0.7f); if (GameObject.Find("EventSystem") == null) { var eventSystemObject = new GameObject("EventSystem"); eventSystemObject.AddComponent <EventSystem>(); eventSystemObject.AddComponent <StandaloneInputModule>(); } }
/// <summary> /// 選択中オブジェクトの子に空のオブジェクトを作成する。未選択の場合は一番親階層 /// </summary> private static GameObject CreateEmptyUIObjectInSelectObject(string objectName) { GameObject emptyObject = ExpansionToolUI.CreateEmptyUIObject(objectName); var selectObject = Selection.GetTransforms(SelectionMode.DeepAssets); foreach (Transform t in selectObject) { emptyObject.transform.SetParent(t.transform); emptyObject.layer = t.gameObject.layer; } emptyObject.transform.localPosition = Vector3.zero; emptyObject.transform.localScale = Vector3.one; return(emptyObject); }