mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 00:26:04 +00:00
Item manager
This commit is contained in:
24
assets/Scripts/Game/Items/Gold/Gold.ts
Normal file
24
assets/Scripts/Game/Items/Gold/Gold.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Component, Vec3, _decorator } from "cc";
|
||||
import { ISignal } from "../../../Services/EventSystem/ISignal";
|
||||
import { Signal } from "../../../Services/EventSystem/Signal";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("Gold")
|
||||
export class Gold extends Component {
|
||||
private pickUpEvent: Signal<Gold> = new Signal<Gold>();
|
||||
|
||||
public setup(position: Vec3): void {
|
||||
this.node.setWorldPosition(position);
|
||||
this.node.active = true;
|
||||
}
|
||||
|
||||
public get PickupEvent(): ISignal<Gold> {
|
||||
return this.pickUpEvent;
|
||||
}
|
||||
|
||||
public pickup(): void {
|
||||
this.pickUpEvent.trigger(this);
|
||||
this.node.active = false;
|
||||
}
|
||||
}
|
9
assets/Scripts/Game/Items/Gold/Gold.ts.meta
Normal file
9
assets/Scripts/Game/Items/Gold/Gold.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "41f6700e-1184-4c4c-b5f0-35fec21bd88e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
26
assets/Scripts/Game/Items/Gold/GoldSpawner.ts
Normal file
26
assets/Scripts/Game/Items/Gold/GoldSpawner.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Component, Prefab, Vec3, _decorator } from "cc";
|
||||
import { ObjectPool } from "../../../Services/ObjectPool";
|
||||
import { Gold } from "./Gold";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("GoldSpawner")
|
||||
export class GoldSpawner extends Component {
|
||||
@property(Prefab) public goldPrefab: Prefab;
|
||||
|
||||
private goldPool: ObjectPool<Gold>;
|
||||
public init(): void {
|
||||
this.goldPool = new ObjectPool<Gold>(this.goldPrefab, this.node, 5, "Gold");
|
||||
}
|
||||
|
||||
public spawn(position: Vec3): void {
|
||||
const gold: Gold = this.goldPool.borrow();
|
||||
gold.setup(position);
|
||||
gold.PickupEvent.on(this.return, this);
|
||||
}
|
||||
|
||||
private return(gold: Gold): void {
|
||||
gold.PickupEvent.off(this.return);
|
||||
this.goldPool.return(gold);
|
||||
}
|
||||
}
|
9
assets/Scripts/Game/Items/Gold/GoldSpawner.ts.meta
Normal file
9
assets/Scripts/Game/Items/Gold/GoldSpawner.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "abf1ff90-c9a3-4d65-8bb9-1ac9ebeb7d51",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user