|
@@ -4,8 +4,8 @@ import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDis
|
|
|
import { GameEvent } from '../Enum/GameEvent';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
/** 截图组件脚本*/
|
|
|
-@ccclass('ScreenShot')
|
|
|
-export class ScreenShot extends Component {
|
|
|
+@ccclass('ScreenShotComponent')
|
|
|
+export class ScreenShotComponent extends Component {
|
|
|
|
|
|
@property(Sprite)
|
|
|
public sprite: Sprite = null!;
|
|
@@ -13,6 +13,8 @@ export class ScreenShot extends Component {
|
|
|
_renderTex: RenderTexture | null = null;
|
|
|
|
|
|
private _originalTargetTexture: RenderTexture | null = null;
|
|
|
+ private _originalCameraPosition: Vec3 = new Vec3();
|
|
|
+ private _originalCameraRotation: Vec3 = new Vec3();
|
|
|
|
|
|
async start() {
|
|
|
this.registerEvent();
|
|
@@ -59,7 +61,7 @@ export class ScreenShot extends Component {
|
|
|
if (targetNode) {
|
|
|
// 设置渲染纹理
|
|
|
sp.texture = renderTex;
|
|
|
- // 关键修改:通过设置flipUV来翻转图像
|
|
|
+ // 设置flipUV来翻转图像
|
|
|
sp.flipUVY = true;
|
|
|
this.sprite.spriteFrame = sp;
|
|
|
|
|
@@ -72,6 +74,8 @@ export class ScreenShot extends Component {
|
|
|
this.scheduleOnce(() => {
|
|
|
// 恢复相机状态
|
|
|
camera.targetTexture = this._originalTargetTexture;
|
|
|
+ camera.node.setWorldPosition(this._originalCameraPosition);
|
|
|
+ camera.node.setRotationFromEuler(this._originalCameraRotation);
|
|
|
// 强制更新材质
|
|
|
this.sprite.markForUpdateRenderData();
|
|
|
}, 0.1); // 稍微延长等待时间确保渲染完成
|
|
@@ -98,6 +102,12 @@ export class ScreenShot extends Component {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ //更新相机最新的位置和旋转角度
|
|
|
+ public saveCameraState(pos:Vec3,rotation:Vec3){
|
|
|
+ this._originalCameraPosition = pos;
|
|
|
+ this._originalCameraRotation = rotation;
|
|
|
+ }
|
|
|
+
|
|
|
protected onDestroy(): void {
|
|
|
this.unregisterEvent();
|
|
|
}
|