yantar/assets/Scripts/ui/equipmentListSwitch.ts
Georgy Shive 302bce20c1 избавился от дублирующего и не нужного
добавил кнопку которая исчезает сразу после первого
нажатия
2025-04-03 16:37:00 +07:00

62 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { _decorator, Component, Node, tween, Vec3 } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('equipmentListSwitch')
export class equipmentListSwitch extends Component {
// Узел со списком оборудования
@property(Node)
public equipmentList: Node = null!;
// Смещение по оси X для закрытого состояния списка
@property
public offsetX: number = 250;
// Длительность анимации
@property
public animationDuration: number = 0.3;
// Позиции для анимации списка
private openPos: Vec3 = new Vec3();
private closedPos: Vec3 = new Vec3();
// Флаг, показывающий текущее состояние списка
private isOnToggle: boolean = false;
start() {
// Сохраняем позицию списка как открытое положение
this.openPos = this.equipmentList.getPosition().clone();
// Вычисляем закрытое положение (смещение по оси X)
this.closedPos = new Vec3(this.openPos.x - this.offsetX, this.openPos.y, this.openPos.z);
// Изначально скрываем список, устанавливая его в закрытое положение
this.equipmentList.setPosition(this.closedPos);
}
// Метод для остановки всех текущих анимаций
private stopTween() {
tween(this.equipmentList).stop();
}
// Метод переключения состояния списка
public equipmentSwitch() {
// Останавливаем текущие анимации, чтобы избежать их наложения
this.stopTween();
if (this.isOnToggle) {
// Если список открыт, закрываем его
this.isOnToggle = false;
tween(this.equipmentList)
.to(this.animationDuration, { position: this.closedPos })
.start();
} else {
// Если список закрыт, открываем его
this.isOnToggle = true;
tween(this.equipmentList)
.to(this.animationDuration, { position: this.openPos })
.start();
}
}
}