добавил сокрытие стен при движение, и их отображение

при возвращение на стартовое положение
This commit is contained in:
Georgy Shive 2025-04-09 20:54:42 +07:00
parent d66733510a
commit 7e227cd2b6
3 changed files with 54 additions and 28 deletions

View File

@ -1173,7 +1173,7 @@
},
"_enabled": true,
"__prefab": null,
"Walls": {
"walls": {
"__id__": 11
},
"_id": "03+eMGqihAhbXb7K37p5lM"
@ -13085,8 +13085,8 @@
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": -442.59,
"y": -340,
"x": -615,
"y": -335,
"z": 0
},
"_lrot": {
@ -13315,7 +13315,7 @@
},
"component": "",
"_componentId": "710e0lYsxlDaazRa54bbTix",
"handler": "hideButton",
"handler": "onReturnButtonClick",
"customEventData": ""
},
{
@ -13392,12 +13392,12 @@
},
"_enabled": true,
"__prefab": null,
"_alignFlags": 4,
"_alignFlags": 12,
"_target": null,
"_left": 0,
"_left": 5,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_bottom": 5,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,
@ -13408,9 +13408,9 @@
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_alignMode": 1,
"_alignMode": 2,
"_lockFlags": 0,
"_id": "63oWQ1iPNE1YFPZynBBsdf"
"_id": "74U5JoNaxDmrWl1bmGSLM0"
},
{
"__type__": "cc.Node",
@ -13452,8 +13452,8 @@
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": -596.781,
"y": -347,
"x": -321.687,
"y": 321.5830000000001,
"z": 0
},
"_lrot": {
@ -13488,7 +13488,7 @@
"__id__": 381
},
"_children": [],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 383
@ -13597,7 +13597,7 @@
"__id__": 381
},
"_children": [],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 386
@ -13798,7 +13798,7 @@
"__id__": 381
},
"_children": [],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 393
@ -13997,7 +13997,7 @@
"r": 114,
"g": 255,
"b": 109,
"a": 255
"a": 0
},
"_spriteFrame": {
"__uuid__": "f12a23c4-b924-4322-a260-3d982428f1e8@f9941",
@ -14082,7 +14082,7 @@
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_bottom": 668.5830000000001,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,

View File

@ -1,4 +1,5 @@
import { _decorator, Component, Node, tween, Vec3 } from 'cc';
import { switchWalls } from '../ux/switchWalls';
const { ccclass, property } = _decorator;
@ccclass('ReturnCameraButtonController')
@ -32,6 +33,8 @@ export class ReturnCameraButtonController extends Component {
// Исходная позиция кнопки
private originalButtonPos: Vec3 = new Vec3();
private wallSwtich: switchWalls = null!;
start() {
// Сохраняем исходную позицию кнопки, как её позицию при отображении (например, в инспекторе)
this.originalButtonPos = this.returnCameraButton.getPosition().clone();
@ -43,15 +46,17 @@ export class ReturnCameraButtonController extends Component {
// Подписываемся на событие "moved", эмитируемое персонажем при его движении
this.character.on('moved', this.onCharacterMoved, this);
this.wallSwtich = switchWalls.getInstance();
}
// Обработчик события движения персонажа
private onCharacterMoved() {
const currentPos = this.character.getPosition();
const distance = currentPos.clone().subtract(this.originalCharacterPos).length();
if (distance >= this.moveThreshold) {
// Если персонаж сместился достаточно, запускаем анимацию показа кнопки
// Скрываем стены явно (до этого они были видимы)
this.wallSwtich.hideWalls();
// Запускаем анимацию показа кнопки
this.resetPosition();
}
}
@ -74,4 +79,11 @@ export class ReturnCameraButtonController extends Component {
})
.start();
}
// Метод, назначаемый через UI click event на кнопке.
// При повторном клике отображаются стены, а кнопка скрывается.
public onReturnButtonClick() {
this.wallSwtich.showWalls();
this.hideButton();
}
}

View File

@ -3,14 +3,28 @@ const { ccclass, property } = _decorator;
@ccclass('switchWalls')
export class switchWalls extends Component {
@property(Node) Walls : Node = null!;
isOnToggle: boolean = true;
private static _instance: switchWalls = null!;
wallSwitch() {
if (this.isOnToggle) {
this.Walls.active = !this.Walls.active ;
}
}
}
// Ссылка на ноду стен
@property(Node)
public walls: Node = null!;
onLoad() {
// Записываем текущий экземпляр (не создавайте через new!)
switchWalls._instance = this;
}
public static getInstance(): switchWalls {
return switchWalls._instance;
}
// Метод для скрытия стен
public hideWalls(): void {
this.walls.active = false;
}
// Метод для отображения стен
public showWalls(): void {
this.walls.active = true;
}
}