Projectiles

This commit is contained in:
Martin
2022-11-30 08:21:22 +01:00
parent da70723f2d
commit 7e20e41482
16 changed files with 140 additions and 31 deletions

View File

@@ -0,0 +1,27 @@
import { CircleCollider2D, Collider2D, Component, Contact2DType, _decorator } from "cc";
import { ISignal } from "../../Services/EventSystem/ISignal";
import { Signal } from "../../Services/EventSystem/Signal";
import { ProjectileCollision } from "./ProjectileCollision";
const { ccclass, property } = _decorator;
@ccclass("Projectile")
export class Projectile extends Component {
@property(CircleCollider2D) private collider: CircleCollider2D;
private contactBeginEvent: Signal<ProjectileCollision> = new Signal<ProjectileCollision>();
private isInit = false;
public tryInit(): void {
if (this.isInit) return;
this.isInit = true;
this.collider.on(Contact2DType.BEGIN_CONTACT, this.onColliderContactBegin, this);
}
public get ContactBeginEvent(): ISignal<ProjectileCollision> {
return this.contactBeginEvent;
}
private onColliderContactBegin(thisCollider: Collider2D, otherCollider: Collider2D): void {
this.contactBeginEvent.trigger({ otherCollider, projectile: this });
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "6a24e600-866b-4c0d-9a39-59bf222c2e50",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,7 @@
import { Collider2D } from "cc";
import { Projectile } from "./Projectile";
export class ProjectileCollision {
public otherCollider: Collider2D;
public projectile: Projectile;
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "0f4db0b8-c13a-41cd-8d53-b87b6b615ac6",
"files": [],
"subMetas": {},
"userData": {}
}