mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-12-08 21:59:26 +00:00
Item refactoring
This commit is contained in:
30
assets/Scripts/Game/Items/Item.ts
Normal file
30
assets/Scripts/Game/Items/Item.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { _decorator, Component, Node, Vec3, ccenum, Enum } from "cc";
|
||||
import { ISignal } from "../../Services/EventSystem/ISignal";
|
||||
import { Signal } from "../../Services/EventSystem/Signal";
|
||||
import { ItemType } from "./ItemType";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("Item")
|
||||
export class Item extends Component {
|
||||
@property({ type: Enum(ItemType) }) private itemType: ItemType;
|
||||
|
||||
private pickUpEvent = new Signal<Item>();
|
||||
|
||||
public get ItemType(): ItemType {
|
||||
return <ItemType>this.itemType;
|
||||
}
|
||||
|
||||
public setup(position: Vec3): void {
|
||||
this.node.setWorldPosition(position);
|
||||
this.node.active = true;
|
||||
}
|
||||
|
||||
public get PickupEvent(): ISignal<Item> {
|
||||
return this.pickUpEvent;
|
||||
}
|
||||
|
||||
public pickup(): void {
|
||||
this.pickUpEvent.trigger(this);
|
||||
this.node.active = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user