This commit is contained in:
dgflash
2022-03-05 12:12:57 +08:00
parent 5e67a7fd7f
commit 7cf30c2b3c
6 changed files with 38 additions and 9 deletions

View File

@@ -227,7 +227,7 @@
"_priority": 1073741824,
"_fov": 45,
"_fovAxis": 0,
"_orthoHeight": 419.7772828507795,
"_orthoHeight": 481.2709620476611,
"_near": 1,
"_far": 2000,
"_color": {

View File

@@ -0,0 +1,5 @@
/** 角色模块全局事件 */
export enum RoleEvent {
/** 修改职业事件 */
ChangeJob = "ChangeJob"
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "a2e7abd7-21aa-4dfc-ab5c-6dd0dfba2a7c",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -5,9 +5,11 @@
* @LastEditTime: 2022-01-29 11:46:38
*/
import { Message } from "../../../core/common/event/MessageManager";
import { ecs } from "../../../core/libs/ECS";
import { RoleJobModelComp } from "../model/RoleJobModelComp";
import { Role } from "../Role";
import { RoleEvent } from "../RoleEvent";
/**
* 角色转职
@@ -38,17 +40,12 @@ export class RoleChangeJobSystem extends ecs.ComblockSystem implements ecs.IEnti
entityEnter(entities: Role[]): void {
for (let e of entities) {
// console.log("【转职前】角色属性");
// e.RoleModel.toString();
// 数值更新
e.RoleJobModel.id = e.RoleChangeJob.jobId;
// console.log("【转职后】角色属性");
// e.RoleModel.toString();
// 转职事件
Message.dispatchEvent(RoleEvent.ChangeJob);
// 切换职业动画
e.RoleView.animator.changeJob();
e.remove(RoleChangeJobComp);
}
}

View File

@@ -64,7 +64,7 @@ export class RoleViewAnimator extends AnimatorSpine {
}
/** 当前动作换职业动画 */
changeJob() {
refresh() {
// 状态机状态值未变时,不会触发状态变化事件,所以这里直接触发状态变化事件来触发后续流程
this.onStateChange(this._ac.curState, this._ac.curState);
}

View File

@@ -13,6 +13,7 @@ import { config } from "../../common/config/Config";
import { CCComp } from "../../common/ecs/CCComp";
import { RoleModelComp } from "../model/RoleModelComp";
import { Role } from "../Role";
import { RoleEvent } from "../RoleEvent";
import { RoleViewAnimator } from "./RoleViewAnimator";
const { ccclass, property } = _decorator;
@@ -33,6 +34,23 @@ export class RoleViewComp extends CCComp {
this.node.active = false;
this.animator = this.spine!.getComponent(RoleViewAnimator)!;
this.animator.role = this.ent as Role;
this.on(RoleEvent.ChangeJob, this.onHandler, this);
}
/** 全局事件处理器 */
private onHandler(event: string, args: any) {
switch (event) {
case RoleEvent.ChangeJob:
this.changeJob();
break;
}
}
/** 演示业务层通过事件控制视图层逻辑,避免两层代码直接偶合 */
private changeJob() {
// 切换职业动画
this.animator.refresh();
}
load() {