Ejemplo n.º 1
0
    static public void ExportLayout()
    {
        string prefab      = EditorTool.GetCurrentSelectedAssetPath();
        string layout_file = LayoutTool.GetLayoutFullPath(prefab);

        if (string.IsNullOrEmpty(layout_file))
        {
            return;
        }
        if (File.Exists(layout_file))
        {
            if (!EditorUtility.DisplayDialog("", "\"" + layout_file + "\"已经存在,是否覆盖?", "确定", "取消"))
            {
                return;
            }
        }

        Object     objSelected = EditorTool.GetCurrentSelectedAssetObj();
        GameObject inst        = Object.Instantiate(objSelected) as GameObject;

        inst.name = objSelected.name;
        if (LayoutTool.HasUI(inst))
        {
            if (!LayoutTool.HasAnchorUI(inst))
            {
                if (!LayoutTool.HasUIRootOrPanel(inst))
                {
                    GameObject objRoot = new GameObject("UIRootTempPanel");
                    UIPanel    uPanel  = objRoot.AddComponent <UIPanel>();
                    if (uPanel != null)
                    {
                        uPanel.depth          = 1;
                        inst.transform.parent = objRoot.transform;
                        inst.name             = objSelected.name;
                        inst = objRoot;
                    }
                    else
                    {
                        Debug.Log("Add UIPanel Component Failed");
                    }
                }

                Camera camera         = LayoutTool.CreateCamera();
                int    max_try        = 5;
                int    try_count      = 0;
                bool   need_reset_pos = LayoutTool.NeedResetPos(inst);
                if (need_reset_pos)
                {
                    inst.transform.localPosition = Vector3.zero;
                }
                inst.transform.localEulerAngles = Vector3.zero;
                inst.transform.localScale       = Vector3.one;
                LayoutTool.SetCamera(inst, camera);
                while (try_count < max_try && LayoutTool.RemoveNoUINode(inst))
                {
                    ++try_count;
                }

                if (LayoutTool.ProcessBeforeExport(inst))
                {
                    if (LayoutTool.ProcessSubPrefabBeforeExport(inst))
                    {
                        if (LayoutTool.ProcessBeforeExport(inst))
                        {
                            LayoutTool.SaveLayout(layout_file, inst);
                            EditorUtility.DisplayDialog("", "导出成功", "确定");
                        }
                    }
                }
                LayoutTool.ReleaseCamera(camera);
            }
            else
            {
                EditorUtility.DisplayDialog("", "有含有Anchor的UI节点,无法导出", "确定");
            }
        }
        else
        {
            EditorUtility.DisplayDialog("", "没有可调整的UI,无需导出", "确定");
        }
        Object.DestroyImmediate(inst);
    }