添加2个游戏层,敌方精灵随机出现在3个层内
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { _decorator,Contact2DType,Collider2D ,IPhysics2DContact} from "cc";
|
||||
import { _decorator,Contact2DType,Collider2D ,IPhysics2DContact,v3, v2} from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
import { BoxSet } from "../common/config/BoxSet";
|
||||
@@ -9,41 +9,46 @@ const { ccclass, property } = _decorator;
|
||||
@ccclass('BoxRangComp')
|
||||
@ecs.register('BoxRang', false)
|
||||
export class BoxRangComp extends CCComp {
|
||||
@property(MonsterViewComp)
|
||||
Hero_node:MonsterViewComp = null!;
|
||||
|
||||
Hero_node: any=null!;
|
||||
MonsterViewComp:MonsterViewComp = null!;
|
||||
box_group:number = BoxSet.DEFAULT;
|
||||
box_tag:number = BoxSet.ATK_RANGE;
|
||||
offset_x:number = 0;
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
start() {
|
||||
let collider = this.getComponent(Collider2D);
|
||||
collider.group = this.box_group;
|
||||
collider.tag = this.box_tag;
|
||||
// console.log(collider,this.Hero_node);
|
||||
collider.offset = v2(this.offset_x,45);
|
||||
this.Hero_node = this.node.parent;
|
||||
this.MonsterViewComp=this.Hero_node.getComponent(MonsterViewComp);
|
||||
// console.log("range box",this.MonsterViewComp);
|
||||
if (collider) {
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
|
||||
collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
|
||||
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
|
||||
// collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
|
||||
// collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
|
||||
// collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
|
||||
}
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
}
|
||||
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
}
|
||||
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
if(selfCollider.group != otherCollider.group&&otherCollider.tag != BoxSet.ATK_RANGE){
|
||||
this.Hero_node.is_atking = true;
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
if(selfCollider.group != otherCollider.group&&otherCollider.tag != BoxSet.ATK_RANGE&&otherCollider.tag != BoxSet.SKILL_TAG){
|
||||
// console.log("range box group: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag);
|
||||
this.MonsterViewComp.is_atking = true;
|
||||
}
|
||||
}
|
||||
// onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
// // console.log("range box group: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| range box tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag);
|
||||
|
||||
}
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
// }
|
||||
// onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
|
||||
// }
|
||||
// onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
|
||||
|
||||
}
|
||||
// }
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
|
||||
Reference in New Issue
Block a user