добавил стейт менеджер оборудования, добавил индекс в префаб кнопки оборудования добавил логику отображения списка оборудования в списке
37 lines
1016 B
TypeScript
37 lines
1016 B
TypeScript
// ItemButton.ts
|
|
import { _decorator, Component, Label, Button } from 'cc';
|
|
import { apiSensors } from '../stores/apiSensors';
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('ItemButton')
|
|
export class ItemButton extends Component {
|
|
@property(Label)
|
|
public nameLabel: Label | null = null;
|
|
|
|
@property(Label)
|
|
public timeLabel: Label | null = null;
|
|
|
|
@property(Button)
|
|
public button: Button | null = null;
|
|
|
|
// Добавляем публичное свойство для хранения индекса элемента
|
|
public itemIndex: number = 0;
|
|
|
|
private itemData: apiSensors | null = null;
|
|
|
|
public initialize(data: apiSensors) {
|
|
this.itemData = data;
|
|
if (this.nameLabel) {
|
|
this.nameLabel.string = data.name;
|
|
}
|
|
if (this.timeLabel) {
|
|
this.timeLabel.string = data.connect_time;
|
|
}
|
|
}
|
|
|
|
public onClick() {
|
|
console.log('Нажата кнопка для элемента:', this.itemData);
|
|
}
|
|
}
|