fix convertToUINode (#6085)

This commit is contained in:
Yun Hsiao Wu
2020-01-12 15:09:32 +08:00
committed by pandamicro
parent 8c34bd968b
commit e75b394008
+11 -9
View File
@@ -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;
}