36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { _decorator, Component, Node, EventMouse, director, SceneAsset } from 'cc';
|
|
import { SceneTransitionManager } from '../stores/SceneTransitionManager';
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('SceneLoaderOnDoubleClick')
|
|
export class SceneLoaderOnDoubleClick extends Component {
|
|
@property({ type: SceneAsset, tooltip: 'Сцена для загрузки при двойном клике' })
|
|
public targetScene: SceneAsset | null = null;
|
|
|
|
private _lastClickTime: number = 0;
|
|
|
|
start() {
|
|
this.node.on(Node.EventType.MOUSE_DOWN, this.onMouseDown, this);
|
|
}
|
|
|
|
onMouseDown(event: EventMouse) {
|
|
if (event.getButton() === EventMouse.BUTTON_LEFT) {
|
|
const currentTime = Date.now();
|
|
if (currentTime - this._lastClickTime < 300) {
|
|
|
|
if (!SceneTransitionManager.allowTransition) {
|
|
console.log('Переходы отключены.');
|
|
return;
|
|
}
|
|
if (this.targetScene) {
|
|
director.loadScene(this.targetScene.name);
|
|
} else {
|
|
console.error('Сцена не указана!');
|
|
}
|
|
}
|
|
this._lastClickTime = currentTime;
|
|
}
|
|
}
|
|
}
|