mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user