public static void startPreviewLayoutAnchor() { if (Selection.activeGameObject == null) { Debug.Log("需要选中场景结构面板中的节点"); return; } Vector2 gameViewSize = UnityUtility.getGameViewSize(); string info = "是否要预览" + Selection.activeGameObject.name + "在" + gameViewSize.x + "x" + gameViewSize.y + "下的显示?"; if (!EditorUtility.DisplayDialog("预览", info, "确定", "取消")) { return; } // 设置摄像机的Z坐标为视图高的一半,设置画布根节点为屏幕大小 GameObject uguiRootObj = UnityUtility.getGameObject(FrameDefine.UGUI_ROOT); RectTransform transform = uguiRootObj.GetComponent <RectTransform>(); transform.offsetMin = new Vector2(-gameViewSize.x * 0.5f, -gameViewSize.y * 0.5f); transform.offsetMax = new Vector2(gameViewSize.x * 0.5f, gameViewSize.y * 0.5f); transform.anchorMax = Vector2.zero; transform.anchorMin = Vector2.zero; GameObject camera = UnityUtility.getGameObject(FrameDefine.UI_CAMERA, uguiRootObj, true); camera.transform.localPosition = new Vector3(0.0f, 0.0f, -gameViewSize.y * 0.5f); UnityUtility.applyAnchor(Selection.activeGameObject, true); }
public static void applyAnchor(GameObject go, bool force, GameLayout layout = null) { #if MAKE_CS_DLL callStatic(UTILITY_UNITY, "applyAnchor", new object[] { go, force, layout }); #else UnityUtility.applyAnchor(go, force, layout); #endif }