环境
Cocos Creator 3.6.2
步骤
将下面的脚本放入项目中
//EditorCamerHelper.ts
import { _decorator, Component, Camera, log, Node } from 'cc';
import { EDITOR } from 'cc/env';
const { ccclass, property, executeInEditMode } = _decorator;
declare const cce: any;
@ccclass('EditorCamerHelper')
@executeInEditMode
export class EditorCamerHelper extends Component {
_targetCamera: Camera = null!
get targetCamera() {
return this._targetCamera
}
@property(Camera)
set targetCamera(v) {
this._targetCamera = v;
this.node.worldPosition = this.targetCamera.node.worldPosition
this.node.worldRotation = this.targetCamera.node.worldRotation
}
_refresh: boolean = false;
get refresh() {
return this._refresh
}
@property
set refresh(v) {
this._refresh = v;