mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
fix convertToUINode (#6085)
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
*/
|
||||
|
||||
import { RenderTexture } from '../../assets/render-texture';
|
||||
import { UITransformComponent } from '../../components';
|
||||
import { Component } from '../../components/component';
|
||||
import { ccclass, executeInEditMode, menu, property } from '../../data/class-decorator';
|
||||
import { ray } from '../../geom-utils';
|
||||
@@ -38,9 +39,8 @@ import { CameraDefaultMask } from '../../pipeline/define';
|
||||
import { Camera } from '../../renderer';
|
||||
import { SKYBOX_FLAG } from '../../renderer/scene/camera';
|
||||
import { Root } from '../../root';
|
||||
import { Layers, Scene, Node } from '../../scene-graph';
|
||||
import { Layers, Node, Scene } from '../../scene-graph';
|
||||
import { Enum } from '../../value-types';
|
||||
import { UITransformComponent } from '../../components';
|
||||
|
||||
const _temp_vec3_1 = new Vec3();
|
||||
|
||||
@@ -444,22 +444,24 @@ export class CameraComponent extends Component {
|
||||
* uiNode.position = out;
|
||||
* ```
|
||||
*/
|
||||
public convertToUINode(wpos: Vec3, uiNode: Node, out?: Vec3){
|
||||
public convertToUINode (wpos: Vec3, uiNode: Node, out?: Vec3){
|
||||
if (!out) {
|
||||
out = new Vec3();
|
||||
}
|
||||
if (!this._camera) { return out; }
|
||||
|
||||
this.worldToScreen(wpos, _temp_vec3_1);
|
||||
_temp_vec3_1.x = _temp_vec3_1.x / cc.view.getScaleX();
|
||||
_temp_vec3_1.y = _temp_vec3_1.y / cc.view.getScaleY();
|
||||
const cmp = uiNode.getComponent('cc.UITransformComponent') as UITransformComponent;
|
||||
const designSize = cc.view._designResolutionSize;
|
||||
const xoffset = _temp_vec3_1.x - this._camera!.width * 0.5;
|
||||
const yoffset = _temp_vec3_1.y - this._camera!.height * 0.5;
|
||||
_temp_vec3_1.x = xoffset / cc.view.getScaleX() + designSize.width * 0.5;
|
||||
_temp_vec3_1.y = yoffset / cc.view.getScaleY() + designSize.height * 0.5;
|
||||
|
||||
if (!cmp) {
|
||||
return out;
|
||||
if (cmp) {
|
||||
cmp.convertToNodeSpaceAR(_temp_vec3_1, out);
|
||||
}
|
||||
|
||||
cmp.convertToNodeSpaceAR(_temp_vec3_1, out);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user