import { _decorator, Component, Node, CameraComponent, PhysicsSystem, geometry, Vec3, EventMouse, input, Input } from 'cc'; import { PulsatingHighlighter } from './PulsatingHighlighter'; import { CameraMover } from './CameraMover'; const { ccclass, property } = _decorator; @ccclass('ModelSelector') export class ModelSelector extends Component { @property({ type: CameraComponent }) public camera: CameraComponent | null = null; @property({ type: CameraMover }) public cameraMover: CameraMover | null = null; // πŸ”₯ ДобавляСм CameraMover private _ray = new geometry.Ray(); private _clickCount = 0; private _doubleClickThreshold = 0.3; // 300 мс ΠΌΠ΅ΠΆΠ΄Ρƒ ΠΊΠ»ΠΈΠΊΠ°ΠΌΠΈ onLoad() { input.on(Input.EventType.MOUSE_UP, this._onMouseUp, this); } onDestroy() { input.off(Input.EventType.MOUSE_UP, this._onMouseUp, this); } private _onMouseUp(event: EventMouse) { if (event.getButton() !== 2) return; // Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌ ΠΏΡ€Π°Π²ΡƒΡŽ ΠΊΠ½ΠΎΠΏΠΊΡƒ ΠΌΡ‹ΡˆΠΈ console.log('πŸ–± ΠŸΡ€Π°Π²Ρ‹ΠΉ ΠΊΠ»ΠΈΠΊ зафиксирован!'); this.unschedule(this._resetClickCount); this._clickCount++; if (this._clickCount === 2) { console.log('βœ… Π”Π²ΠΎΠΉΠ½ΠΎΠΉ ΠΊΠ»ΠΈΠΊ зафиксирован!'); this._performRaycast(event); this._clickCount = 0; } else { this.scheduleOnce(this._resetClickCount, this._doubleClickThreshold); } } private _resetClickCount() { this._clickCount = 0; console.log('⏳ Бброс Π΄Π²ΠΎΠΉΠ½ΠΎΠ³ΠΎ ΠΊΠ»ΠΈΠΊΠ° ΠΈΠ·-Π·Π° Ρ‚Π°ΠΉΠΌΠ°ΡƒΡ‚Π°.'); } private _performRaycast(event: EventMouse) { if (!this.camera) { console.warn('🚨 ΠšΠ°ΠΌΠ΅Ρ€Π° Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½Π°!'); return; } const screenPos = new Vec3(event.getLocationX(), event.getLocationY(), 0); this.camera.screenPointToRay(screenPos.x, screenPos.y, this._ray); console.log('πŸ” ЗапускаСм raycast...'); if (PhysicsSystem.instance.raycast(this._ray)) { const results = PhysicsSystem.instance.raycastResults; if (results.length > 0) { const hitNode = results[0].collider.node; console.log(`🎯 ПопаданиС ΠΏΠΎ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Ρƒ: ${hitNode.name}`); this._highlightModel(hitNode , "red"); this._moveCamera(hitNode); // πŸ”₯ Π’Ρ‹Π·Ρ‹Π²Π°Π΅ΠΌ ΠΊΠ°ΠΌΠ΅Ρ€Ρƒ! } else { console.log('❌ Raycast Π½ΠΈΡ‡Π΅Π³ΠΎ Π½Π΅ нашСл.'); } } else { console.log('⚠️ Raycast Π½Π΅ сработал.'); } } private _highlightModel(model: Node, color: string) { const switcher = model.getComponent(PulsatingHighlighter); if (switcher) { switcher.switchToColor(color); } } private _moveCamera(model: Node ) { if (this.cameraMover) { this.cameraMover.moveToTarget(model); } else { console.warn('🚨 CameraMover Π½Π΅ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½!'); } } }