mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 08:36:14 +00:00
Menu button
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
import { _decorator, Component, Node } from "cc";
|
||||
import { _decorator, Component, Node, Button } from "cc";
|
||||
import { UIButton } from "../Services/UI/Button/UIButton";
|
||||
|
||||
import { GameRunner } from "./GameRunner";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("Menu")
|
||||
export class Menu extends Component {
|
||||
@property(UIButton) private playBtn: UIButton;
|
||||
|
||||
public async start(): Promise<void> {
|
||||
GameRunner.Instance.playGame();
|
||||
this.playBtn.InteractedEvent.on(() => GameRunner.Instance.playGame(), this);
|
||||
}
|
||||
}
|
||||
|
12
assets/Scripts/Services/UI/Button.meta
Normal file
12
assets/Scripts/Services/UI/Button.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "75b52184-72e7-4686-9688-e6baa2cb1d70",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
22
assets/Scripts/Services/UI/Button/UIButton.ts
Normal file
22
assets/Scripts/Services/UI/Button/UIButton.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { _decorator, Component, Node, NodeEventType } from "cc";
|
||||
import { ISignal } from "../../EventSystem/ISignal";
|
||||
import { Signal } from "../../EventSystem/Signal";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("UIButton")
|
||||
export class UIButton extends Component {
|
||||
private interactedEvent = new Signal<UIButton>();
|
||||
|
||||
public start(): void {
|
||||
this.node.on(Node.EventType.TOUCH_START, this.interact, this);
|
||||
}
|
||||
|
||||
public get InteractedEvent(): ISignal<UIButton> {
|
||||
return this.interactedEvent;
|
||||
}
|
||||
|
||||
private interact(): void {
|
||||
console.log("interact");
|
||||
this.interactedEvent.trigger(this);
|
||||
}
|
||||
}
|
9
assets/Scripts/Services/UI/Button/UIButton.ts.meta
Normal file
9
assets/Scripts/Services/UI/Button/UIButton.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "55e5fe67-43c7-4788-be5f-3d68e07576c7",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user