fix coordinate replace function (#6025)

save
This commit is contained in:
JoneLau
2020-01-04 11:22:14 +08:00
committed by pandamicro
parent 2fec62b5cf
commit ea700afb50
2 changed files with 25 additions and 5 deletions
@@ -431,6 +431,19 @@ export class CameraComponent extends Component {
return out;
}
/**
* @zh 3D 节点转 UI 本地节点坐标。
* 注意:千万不要设置负责做转换的 uiNode 和最终设置位置的 uiNode 是同一个 node,否则可能出现跳动现象。
* @param wpos 3D 节点事件坐标
* @param uiNode UI 节点
* @param out 返回在当前传入的 UI 节点下的偏移量
*
* @example
* ```typescript
* this.convertToUINode(target.worldPosition, uiNode.parent, out);
* uiNode.position = out;
* ```
*/
public convertToUINode(wpos: Vec3, uiNode: Node, out?: Vec3){
if (!out) {
out = new Vec3();
+12 -5
View File
@@ -7,6 +7,8 @@ import { Vec3 } from '../math';
import { Node } from '../scene-graph';
import { replaceProperty } from './deprecated';
const _vec3 = new Vec3();
/**
* @en
* Conversion of non-UI nodes to UI Node (Local) Space coordinate system.
@@ -60,12 +62,17 @@ const convertUtils = {
export { convertUtils };
cc.pipelineUtils = convertUtils;
replaceProperty(cc, 'cc', [
replaceProperty(cc.pipelineUtils, 'cc.pipelineUtils', [
{
name: 'pipelineUtils',
newName: 'CameraComponent.convertToUINode',
customGetter: () => {
return CameraComponent;
'name': 'WorldNode3DToLocalNodeUI',
'newName': 'convertToUINode',
'targetName': 'cc.CameraComponent.prototype',
'customFunction': function (...args: any[]) {
const camera = args[0] as CameraComponent;
const out = args[3] || _vec3;
camera.convertToUINode(args[1], args[2], out);
out.add(args[2].position);
return args[3] || out.clone();
},
},
]);