unity 文件路径有空时的处理

博客给出了一个处理路径为空时的方法 GetUncode,该方法接收一个字符串参数,使用正则表达式匹配 Unicode 编码并将其转换为对应字符,最终返回处理后的字符串。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

///当路径有空的时候的处理方式   

    private string GetUncode(string src)

        {

            string outStr = "";

            Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");

            outStr = reg.Replace(src, delegate (Match match)

            {

                return ((char)Convert.ToInt32(match.Groups[1].Value, 16)).ToString();

            });

            return outStr;

        }

def execute(self,context): props = context.scene.example_props project_path = props.project_path choosename = props.armature_list # 创建导出目录 if props.case_anim_option: export_dir = os.path.join(project_path, f"{choosename}\Fbx\Animation") else: export_dir = os.path.join(project_path, f"{choosename}\Fbx") export_dir = bpy.path.abspath(export_dir) print(export_dir) # 确保目录存在 os.makedirs(export_dir, exist_ok=True) # 设置文件名和完整路径 filename = f"{choosename}.fbx" fbx_path = os.path.join(export_dir, filename) print(fbx_path) # 备份原始选择状态 original_selection = context.selected_objects original_active = context.active_object try: # 模式1:导出网格和骨架(无动画) if not props.case_anim_option: # 收集所有选中的网格和骨架 export_objects = [obj for obj in original_selection if obj.type in {'MESH', 'ARMATURE'}] if not export_objects: self.report({'ERROR'}, "未选中网格或骨架对象") return {'CANCELLED'} # 设置选中状态 bpy.ops.object.select_all(action='DESELECT') for obj in export_objects: obj.select_set(True) # 设置导出参数 export_kwargs = { 'filepath': fbx_path, 'use_space_transform':True, 'use_selection': True, 'bake_anim': False, 'path_mode': 'COPY', # 复制贴图文件 'embed_textures': False, 'mesh_smooth_type': 'FACE', 'add_leaf_bones': False, 'use_armature_deform_only': True, 'object_types': {'MESH', 'ARMATURE'}, 'apply_scale_options': 'FBX_SCALE_ALL' } # 模式2:仅导出骨架和动画 else: # 查找选中的骨架 armatures = [obj for obj in original_selection if obj.type == 'ARMATURE'] if not armatures: self.report({'ERROR'}, "未选中骨架对象") return {'CANCELLED'} # 设置选中状态(仅骨架) bpy.ops.object.select_all(action='DESELECT') for arm in armatures: arm.select_set(True) context.view_layer.objects.active = arm # 设置导出参数 export_kwargs = { 'filepath': fbx_path, 'use_selection': True, 'bake_anim': True, 'path_mode': 'COPY', # 复制贴图文件 'embed_textures': False, 'add_leaf_bones': False, 'use_armature_deform_only': True, 'object_types': {'ARMATURE'}, 'bake_anim_use_all_actions': False, 'bake_anim_use_nla_strips': False, 'bake_anim_use_all_bones': True, 'bake_anim_force_startend_keying': True } # 执行FBX导出 bpy.ops.export_scene.fbx(**export_kwargs) self.report({'INFO'}, f"成功导出到: {fbx_path}") return {'FINISHED'} except Exception as e: self.report({'ERROR'}, f"导出失败: {str(e)}") return {'CANCELLED'} 遇到一个问题,我的模型网格都存放在骨架对象的子层级中,所以在导出时如果不注意选中子层级的mesh,在导出骨架和网格这个分支时就不会正确导出我要的带网格的模型,现在我需要你对以上代码进行调整,以解决我提到的问题
最新发布
07-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值