This commit is contained in:
pan@work
2024-07-29 11:05:17 +08:00
parent f131de6489
commit 5fa8794c09
18 changed files with 304 additions and 44 deletions

View File

@@ -0,0 +1,41 @@
/*
* @Author: dgflash
* @Date: 2021-11-18 15:56:01
* @LastEditors: dgflash
* @LastEditTime: 2022-08-17 13:43:25
*/
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { Monster } from "./Monster";
/**
* 角色属性数据
*/
@ecs.register('BaseMonsterModel')
export class BaseMonsterModel extends ecs.Comp {
/** 角色编号 */
hp: number = 100;
/** 角色名 */
name: string = "base monster";
/** */
reset() {
this.hp = 100;
this.name = "";
}
}
@ecs.register('Monster')
export class MonsterUpgradeSystem extends ecs.ComblockSystem implements ecs.IEntityEnterSystem {
filter(): ecs.IMatcher {
return ecs.allOf(BaseMonsterModel);
}
entityEnter(e: Monster): void {
let MonsterModel = e.MonsterModel;
MonsterModel.name = "base monster"
console.log("MonsterUpgradeSystem", e);
e.remove(BaseMonsterModel);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "52aacfb8-cb73-4ce1-be54-3c2a83e83408",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -15,13 +15,11 @@ import { MonsterModelComp } from "./MonsterModelComp";
import { MonsterSpine } from "./MonsterSpine";
import { MonsterViewComp } from "./MonsterViewComp";
import { MoveToComp } from "../common/MoveTo";
import { GameCollision } from "../../../../extensions/oops-plugin-framework/assets/module/common/GameCollision";
/** 角色实体 */
@ecs.register(`Monster`)
export class Monster extends ecs.Entity {
// 数据层
MonsterModel!: MonsterModelComp;
GameCollision: GameCollision =new GameCollision();
// 视图层
MonsterView!: MonsterViewComp;
RoleMoveTo!: MoveToComp; // 移动
@@ -49,7 +47,7 @@ export class Monster extends ecs.Entity {
var mv = node.getComponent(MonsterViewComp)!;
mv.speed = speed;
console.log("speed:"+mv.speed)
// console.log("speed:"+mv.speed)
mv.Tpos = v3(0,0,0);
this.add(mv);
// node.setScale(-1, 1, 1);

View File

@@ -17,13 +17,13 @@ export class MonsterModelComp extends ecs.Comp {
/** 角色名 */
name: string = "monster";
/** speed */
speed: number = 0;
// speed: number = 0;
/** 动画名资源 */
anim: string = "monster";
reset() {
this.id = -1;
this.speed = 0;
// this.speed = 0;
this.name = "";
}
}

View File

@@ -36,7 +36,7 @@ export class MonsterSpine extends Component {
/** 初始化动画 */
protected initAnimator() {
this.spine = this.animator.getComponent(sp.Skeleton)!;
console.log("MonsterSpine initAnimator", this.spine);
// console.log("MonsterSpine initAnimator", this.spine);
}

View File

@@ -11,6 +11,7 @@ import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/modu
import { MonsterSpine } from "./MonsterSpine";
import { Monster } from "./Monster";
import { MonsterModelComp } from "./MonsterModelComp";
import { BoxSet } from "../common/config/BoxSet";
const { ccclass, property } = _decorator;
@@ -25,39 +26,33 @@ export class MonsterViewComp extends CCComp {
/** 视图层逻辑代码分离演示 */
start () {
// 注册单个碰撞体的回调函数
console.log('MonsterViewComp start');
// console.log('MonsterViewComp start');
let collider = this.getComponent(Collider2D);
// console.log('Monster collider',collider);
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);
}
// 注册全局碰撞回调函数
if (PhysicsSystem2D.instance) {
console.log('PhysicsSystem2D.instance');
// console.log('PhysicsSystem2D.instance');
PhysicsSystem2D.instance.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
PhysicsSystem2D.instance.on(Contact2DType.END_CONTACT, this.onEndContact, this);
PhysicsSystem2D.instance.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
PhysicsSystem2D.instance.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
}
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// 只在两个碰撞体开始接触时被调用一次
console.log('onBeginContact');
}
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// 只在两个碰撞体结束接触时被调用一次
console.log('onEndContact');
}
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// 每次将要处理碰撞体接触逻辑时被调用
console.log('onPreSolve');
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// 每次处理完碰撞体接触逻辑时被调用
console.log('onPostSolve');
// console.log('monster Contact,selfCollider',selfCollider);
switch (otherCollider.group) {
case BoxSet.HERO:
console.log('monster coolider hero');
break;
case BoxSet.HERO_SKILL:
console.log('monster coolider hero skill');
break;
default:
break;
}
}
onLoad() {