首页 > 其他分享 >UE代码重构方法

UE代码重构方法

时间:2022-11-10 12:56:08浏览次数:63  
标签:重构 String NewName 代码 CoreRedirects OldName UE Class op

代码重构

开发过程中,需要对class、function、enum、variable改名,此处介绍如何处理。

一、可以明确对象被少量引用

  • 父类修改:直接打开蓝图,然后在 Class Settings > Class Options > Parent Class,修改成新的类名
  • 其它的函数、变量、枚举修改:找使用的地方直接改

Class Settings

二、对象被大量引用

主要流程如下:

A=>start: 打开文件:DefaultEngine.ini
op_a=>operation: 添加:[CoreRedirects]
op_b=>operation: 配置好+ClassRedirects=
op_c=>operation: 重启UnrealEditor
op_d=>operation: 观察,可以看到引用已修改
e=>end: 完结

A->op_a->op_b->op_c->op_d->e

支持重定向class, struct, enum, function, member

1. 重定向类的方法

修改DefaultEngine.ini文件

[CoreRedirects]
+ClassRedirects=(OldName="Pawn",NewName="MyPawn",InstanceOnly=true)
+ClassRedirects=(OldName="/Script/MyModule.MyOldClass",NewName="/Script/MyModule.MyNewClass")
+ClassRedirects=(OldName="PointLightComponent",NewName="PointLightComponent",ValueChanges=(("PointLightComponent0","LightComponent0")))
+ClassRedirects=(OldName="AnimNotify_PlayParticleEffect_C",NewName="/Script/Engine.AnimNotify_PlayParticleEffect",OverrideClassName="/Script/CoreUObject.Class")

字段含义如下:

字段名 类型 功能
OldName String 类的旧名字
NewName String 类的新名字
MatchSubstring Bool (可选)任意名字匹配到,都替换
OverrideClassName String (可选)指定要对UCLASS的底层类进行的更改。此字段通常用于将蓝图类更改为原生类(/Script/CoreUObject.Class)。
InstanceOnly Bool (可选)只对实例生成
ValueChanges List of String pairs (可选)重命名OldName对应的实例,每一对pair的第一个是实例名字,第二个是新名字

获得类名的方法:
Copy Class Name

配置文件写好后,保存,并重启UnrealEditor,顺序的话,可以看到实例化对象的Parent Class都变成新的class了。

2.重定向Enum、Struct,与重定向类差不多

Enum的字段与Class类似,见类字段

[CoreRedirects]
+EnumRedirects=(OldName="ENumbers",NewName="ELetters",ValueChanges=(("NumberTwo","LetterB"),("NumberThree","LetterC")))

3.重定向Function

[CoreRedirects]
+FunctionRedirects=(OldName="MyOldActor.OldFunction",NewName="MyNewActor.NewFunction")
+FunctionRedirects=(OldName="MyActor.OldFunction",NewName="NewFunction")
Field Type Purpose
OldName String 函数的旧名字
NewName String 函数的新名字
MatchSubstring Bool (可选)任意名字匹配到,都替换

4. 重定向Package

[CoreRedirects]
+PackageRedirects=(OldName="OldPlugin",NewName="/NewPlugin/",MatchSubstring=true)
+PackageRedirects=(OldName="/Game/DeletedContentPackage",Removed=true)
Field Type Purpose
OldName String Specifies the name of the obsolete or deleted package.
NewName String (Optional) If remapping is desired, this specifies the name of the package that replaces the obsolete or deleted package. If this is not present, Removed should be present and set to true.
MatchSubstring Bool (Optional) If present and set to true, this Core Redirect will apply to any package containing the value of OldName, rather than requiring an exact match.
Removed Bool (Optional) If present and set to true, the named package has been removed. References to any of the removed content will be set to null without generating warnings or errors. The NewName argument should not be present if this is the case.

5. 重定向属性

[CoreRedirects]
+PropertyRedirects=(OldName="MyOldActor.OldIntProperty",NewName="MyNewActor.NewIntProperty") 
+PropertyRedirects=(OldName="MyActor.OldFloatProperty",NewName="NewFloatProperty")
Field Type Purpose
OldName String 旧属性名,示例:"类名.属性名", MyActor.MyStruct.MyProperty.
NewName String 新属性名,示例:"类名.属性名", MyActor.MyStruct.MyProperty.
MatchSubstring Bool (可选)任意名字匹配到,都替换

参考资料:

UE5 Core Redirects

友情链接:

blog: https://www.cgsgood.tech/ue_code_refactor
语雀: https://www.yuque.com/cgsgood/dshx0b/qhqlmldu7s28o9bd
博客园: https://www.cnblogs.com/cgsgood/p/16876703.html

标签:重构,String,NewName,代码,CoreRedirects,OldName,UE,Class,op
From: https://www.cnblogs.com/cgsgood/p/16876703.html

相关文章

  • Java使用lamda表达式简化代码
    代码,自然写的越简洁越好啦,写的人舒服,看的人也舒服,一切为了高效。要把有限的时间花到其它有意思的事情上去。目的学习简化代码的思路,使用jdk8新特性lamada表达式。推理......
  • ORA-00600 内部错误代码:
    发现对某个表进行操作时突然报改错(后面在其他生产环境也发现过其他表出现同样的报错),网上说是oracle11g本身的问题,不想动生产环境解决办法:导出数据,重新建表导入数据错误消......
  • ant design vue table报错h is not defined
    报错原因使用table时由于columns数据太多,所以将columns中的数据拆分到一个单独的常量js文件中,又因为需要使用customRender,里面有<a-tag>之类的标签,需要使用jsx进行渲染,因......
  • VUE WEB怎么实现大文件上传
    ​ javaweb上传文件上传文件的jsp中的部分上传文件同样可以使用form表单向后端发请求,也可以使用ajax向后端发请求    1.通过form表单向后端发送请求     ......
  • vuecli之todo练习1静态资源html
    首先建立静态资源htmlApp。vue<template><divid="app"><divclass="todo-container"><divclass="todo-wrap"><MyHeader>......
  • Vue实战必会的几个技巧
    键盘事件在js中我们通常通过绑定一个事件,去获取按键的编码,再通过event中的keyCode属性去获得编码如果我们需要实现固定的键才能触发事件时就需要不断的判断,其实很......
  • vue3中使用vue3-seamless-scroll(最新版本滚动插件)
    npm安装npminstallvue3-seamless-scroll--saveyarn安装yarnaddvue3-seamless-scrollbrowser安装<scriptsrc="https://unpkg.com/browse/vue3-seamless-scr......
  • vue中配置接口返回不带域名的图片地址显示问题
    前端上传图片,通过接口传给后端,需要前端渲染时,接口返回的图片路径如下图其中的path就是图片地址,而我们想渲染图片到前端页面,正常的思路是需要在前面加上服务器的域名1.......
  • Vue组件是怎样挂载的
    我们先来关注一下$mount是实现什么功能的吧:我们打开源码路径core/instance/init.js:exportfunctioninitMixin(Vue:Class<Component>){......initLifec......
  • Vue模板是怎样编译的
    这一章我们开始讲模板解析编译:总结来说就是通过compile函数把tamplate解析成renderFunction形式的字符串compiler/index.jsimport{parse}from'./parser/index'imp......