了解 move 用法

This commit is contained in:
2024-08-30 17:09:48 +08:00
parent 4c16b6cb51
commit ea67f9434f
12 changed files with 360 additions and 237 deletions

View File

@@ -16,11 +16,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 534,
"trimY": 1,
"trimX": 253,
"trimY": 57,
"width": 60,
"height": 62,
"rawWidth": 60,
@@ -62,11 +62,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 587,
"trimY": 129,
"trimX": 381,
"trimY": 1,
"width": 54,
"height": 62,
"rawWidth": 54,
@@ -111,8 +111,8 @@
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 468,
"trimY": 136,
"trimX": 449,
"trimY": 58,
"width": 61,
"height": 64,
"rawWidth": 61,
@@ -154,11 +154,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 1,
"trimY": 1,
"trimY": 247,
"width": 102,
"height": 106,
"rawWidth": 102,
@@ -200,11 +200,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 1,
"trimY": 109,
"trimX": 109,
"trimY": 248,
"width": 102,
"height": 106,
"rawWidth": 102,
@@ -246,11 +246,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 105,
"trimY": 1,
"trimX": 217,
"trimY": 255,
"width": 102,
"height": 106,
"rawWidth": 102,
@@ -292,11 +292,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 105,
"trimY": 109,
"trimX": 325,
"trimY": 268,
"width": 102,
"height": 106,
"rawWidth": 102,
@@ -338,11 +338,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 475,
"trimY": 68,
"trimX": 384,
"trimY": 58,
"width": 61,
"height": 63,
"rawWidth": 61,
@@ -384,11 +384,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": true,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 341,
"trimY": 151,
"trimX": 232,
"trimY": 119,
"width": 70,
"height": 63,
"rawWidth": 70,
@@ -430,11 +430,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 343,
"trimY": 1,
"trimX": 304,
"trimY": 119,
"width": 63,
"height": 68,
"rawWidth": 63,
@@ -476,11 +476,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 408,
"trimY": 1,
"trimX": 89,
"trimY": 117,
"width": 62,
"height": 66,
"rawWidth": 62,
@@ -522,11 +522,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 406,
"trimY": 146,
"trimX": 185,
"trimY": 56,
"width": 60,
"height": 66,
"rawWidth": 60,
@@ -568,11 +568,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 278,
"trimY": 76,
"trimX": 157,
"trimY": 118,
"width": 62,
"height": 73,
"rawWidth": 62,
@@ -614,11 +614,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 277,
"trimY": 1,
"trimX": 1,
"trimY": 177,
"width": 64,
"height": 73,
"rawWidth": 64,
@@ -660,11 +660,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 209,
"trimY": 155,
"trimX": 76,
"trimY": 181,
"width": 64,
"height": 73,
"rawWidth": 64,
@@ -706,11 +706,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 275,
"trimY": 155,
"trimX": 151,
"trimY": 182,
"width": 64,
"height": 73,
"rawWidth": 64,
@@ -752,57 +752,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 531,
"trimY": 133,
"width": 54,
"height": 62,
"rawWidth": 54,
"rawHeight": 62,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [],
"indexes": [],
"uv": [],
"nuv": [],
"minPos": [],
"maxPos": []
},
"isUuid": true,
"imageUuidOrDatabaseUri": "d359dffc-1087-4d3b-bce7-f80eaaeacb1a@6c48a",
"atlasUuid": "56fae78e-4db4-4ef1-be24-d030fc909ed1"
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"e19f9": {
"importer": "sprite-frame",
"uuid": "56fae78e-4db4-4ef1-be24-d030fc909ed1@e19f9",
"displayName": "",
"id": "e19f9",
"name": "6201",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 531,
"trimY": 133,
"trimX": 253,
"trimY": 1,
"width": 54,
"height": 62,
"rawWidth": 54,
@@ -844,103 +798,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 538,
"trimY": 65,
"width": 54,
"height": 62,
"rawWidth": 54,
"rawHeight": 62,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [],
"indexes": [],
"uv": [],
"nuv": [],
"minPos": [],
"maxPos": []
},
"isUuid": true,
"imageUuidOrDatabaseUri": "d359dffc-1087-4d3b-bce7-f80eaaeacb1a@6c48a",
"atlasUuid": "56fae78e-4db4-4ef1-be24-d030fc909ed1"
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"38a73": {
"importer": "sprite-frame",
"uuid": "56fae78e-4db4-4ef1-be24-d030fc909ed1@38a73",
"displayName": "",
"id": "38a73",
"name": "6202",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 538,
"trimY": 65,
"width": 54,
"height": 62,
"rawWidth": 54,
"rawHeight": 62,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [],
"indexes": [],
"uv": [],
"nuv": [],
"minPos": [],
"maxPos": []
},
"isUuid": true,
"imageUuidOrDatabaseUri": "d359dffc-1087-4d3b-bce7-f80eaaeacb1a@6c48a",
"atlasUuid": "56fae78e-4db4-4ef1-be24-d030fc909ed1"
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"de798": {
"importer": "sprite-frame",
"uuid": "56fae78e-4db4-4ef1-be24-d030fc909ed1@de798",
"displayName": "",
"id": "de798",
"name": "6203",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 587,
"trimY": 129,
"trimX": 317,
"trimY": 1,
"width": 54,
"height": 62,
"rawWidth": 54,
@@ -985,8 +847,8 @@
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 468,
"trimY": 202,
"trimX": 64,
"trimY": 1,
"width": 53,
"height": 61,
"rawWidth": 53,
@@ -1028,11 +890,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 594,
"trimY": 65,
"trimX": 127,
"trimY": 1,
"width": 53,
"height": 61,
"rawWidth": 53,
@@ -1074,10 +936,10 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 596,
"trimX": 190,
"trimY": 1,
"width": 53,
"height": 61,
@@ -1120,11 +982,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 643,
"trimY": 128,
"trimX": 445,
"trimY": 1,
"width": 55,
"height": 59,
"rawWidth": 55,
@@ -1166,11 +1028,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 649,
"trimY": 64,
"trimX": 1,
"trimY": 50,
"width": 55,
"height": 59,
"rawWidth": 55,
@@ -1215,8 +1077,8 @@
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 531,
"trimY": 197,
"trimX": 62,
"trimY": 56,
"width": 56,
"height": 59,
"rawWidth": 56,
@@ -1258,15 +1120,61 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 651,
"trimY": 1,
"width": 55,
"height": 59,
"rawWidth": 55,
"rawHeight": 59,
"trimX": 1,
"trimY": 114,
"width": 61,
"height": 86,
"rawWidth": 61,
"rawHeight": 86,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [],
"indexes": [],
"uv": [],
"nuv": [],
"minPos": [],
"maxPos": []
},
"isUuid": true,
"imageUuidOrDatabaseUri": "d359dffc-1087-4d3b-bce7-f80eaaeacb1a@6c48a",
"atlasUuid": "56fae78e-4db4-4ef1-be24-d030fc909ed1"
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"0283d": {
"importer": "sprite-frame",
"uuid": "56fae78e-4db4-4ef1-be24-d030fc909ed1@0283d",
"displayName": "",
"id": "0283d",
"name": "6211",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 380,
"trimY": 192,
"width": 74,
"height": 83,
"rawWidth": 74,
"rawHeight": 83,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
@@ -1304,11 +1212,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 342,
"trimY": 76,
"trimX": 441,
"trimY": 124,
"width": 66,
"height": 68,
"rawWidth": 66,
@@ -1350,11 +1258,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 209,
"trimY": 79,
"trimX": 304,
"trimY": 186,
"width": 67,
"height": 74,
"rawWidth": 67,
@@ -1396,11 +1304,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 592,
"trimY": 193,
"trimX": 1,
"trimY": 1,
"width": 47,
"height": 61,
"rawWidth": 47,
@@ -1442,11 +1350,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 410,
"trimY": 69,
"trimX": 374,
"trimY": 121,
"width": 63,
"height": 65,
"rawWidth": 63,
@@ -1488,11 +1396,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": true,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 472,
"trimY": 1,
"trimX": 317,
"trimY": 57,
"width": 65,
"height": 60,
"rawWidth": 65,
@@ -1534,11 +1442,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 209,
"trimY": 1,
"trimX": 226,
"trimY": 184,
"width": 66,
"height": 76,
"rawWidth": 66,
@@ -1580,11 +1488,11 @@
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"rotated": true,
"offsetX": 0,
"offsetY": 0,
"trimX": 641,
"trimY": 193,
"trimX": 123,
"trimY": 56,
"width": 59,
"height": 60,
"rawWidth": 59,

View File

@@ -12,6 +12,7 @@ import { ecs } from '../../extensions/oops-plugin-framework/assets/libs/ecs/ECS'
import { UIConfigData } from './game/common/config/GameUIConfig';
import { smc } from './game/common/SingletonModuleComp';
import { Initialize } from './game/initialize/Initialize';
import { EcsPositionSystem } from './game/common/ecs/position/EcsPositionSystem';
const { ccclass, property } = _decorator;
@@ -34,7 +35,10 @@ export class Main extends Root {
oops.gui.init(UIConfigData);
}
protected initEcsSystem() {
protected async initEcsSystem() {
oops.ecs.add(new EcsPositionSystem())
// oops.ecs.add(new EcsAccountSystem());
// oops.ecs.add(new EcsRoleSystem());
// oops.ecs.add(new EcsInitializeSystem());
}
}

View File

@@ -15,11 +15,14 @@ import { RoleModelComp } from "./RoleModelComp";
import { RoleSpine } from "./RoleSpine";
import { RoleViewComp } from "./RoleViewComp";
import { RoleSet } from "../common/config/RoleSet";
import { MoveToComp } from "../common/ecs/position/MoveTo";
/** 角色实体 */
@ecs.register(`Role`)
export class Role extends ecs.Entity {
// 数据层
RoleModel!: RoleModelComp;
RoleMoveTo!: MoveToComp; // 移动
// 视图层
RoleView!: RoleViewComp;
@@ -57,7 +60,12 @@ export class Role extends ecs.Entity {
this.hero_init(uuid,node)
}
move(target: Vec3) {
var move = this.get(MoveToComp) || this.add(MoveToComp);
move.target = target;
move.node = this.RoleView.node;
move.speed = 100;
}
hero_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
}

View File

@@ -17,6 +17,7 @@ import { SkillSet } from "../common/config/SkillSet";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { MoveToComp } from "../common/ecs/position/MoveTo";
const { ccclass, property } = _decorator;
/** 角色显示组件 */
@@ -82,6 +83,7 @@ export class RoleViewComp extends CCComp {
}
add_hp(hp:number){
console.log("role add hp",hp);
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "635cbba2-f16e-4c87-b7c5-d9d2bc107de0",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "c1147d9a-3dcd-4fd0-ad87-f4d964ee62a8",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "d2d775f5-1dc0-455e-89d7-4a17f43170e0",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,15 @@
/*
* @Author: dgflash
* @Date: 2021-08-11 16:41:12
* @LastEditors: dgflash
* @LastEditTime: 2022-07-25 17:05:02
*/
import { ecs } from "../../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { MoveToSystem } from "./MoveTo";
export class EcsPositionSystem extends ecs.System {
constructor() {
super();
this.add(new MoveToSystem());
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "b44c446b-ce5f-4079-ac42-269837dbf580",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,136 @@
/*
* @Author: dgflash
* @Date: 2021-08-11 16:41:12
* @LastEditors: dgflash
* @LastEditTime: 2023-01-19 15:27:24
*/
import { Node, Vec3 } from "cc";
import { Timer } from "../../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { Vec3Util } from "../../../../../../extensions/oops-plugin-framework/assets/core/utils/Vec3Util";
import { ecs } from "../../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
/** 向目标移动,移动过程中目标位置变化会自动修正移动目标点,直到未修正前移动到目标点停止 */
@ecs.register('MoveTo')
export class MoveToComp extends ecs.Comp {
/** 移动节点 */
node: Node = null!;
/** 移动方向 */
velocity: Vec3 = Vec3Util.zero;
/** 移动速度(每秒移动的像素距离) */
speed: number = 0;
/** 目标实体ECS编号、目标位置 */
target: Vec3 | Node | null = null;
/** 坐标标(默认本地坐标) */
ns: number = Node.NodeSpace.LOCAL;
/** 偏移距离 */
offset: number = 0;
/** 偏移向量 */
offsetVector: Vec3 | null = null;
/** 移动完成回调 */
onComplete: Function | null = null;
/** 距离变化时 */
onChange: Function | null = null;
reset() {
this.ns = Node.NodeSpace.LOCAL;
this.offset = 0;
this.target = null;
this.offsetVector = null;
this.onComplete = null;
this.onChange = null;
}
}
@ecs.register('VariableMoveTo')
class VariableMoveToComponent extends ecs.Comp {
/** 延时触发器 */
timer: Timer = new Timer();
/** 终点备份 */
end: Vec3 | null = null;
/** 目标位置 */
target!: Vec3;
reset() {
this.end = null;
this.timer.reset();
}
}
/** 跟踪移动到目标位置 */
export class MoveToSystem extends ecs.ComblockSystem<ecs.Entity> implements ecs.IEntityEnterSystem, ecs.IEntityRemoveSystem, ecs.ISystemUpdate {
filter(): ecs.IMatcher {
return ecs.allOf(MoveToComp);
}
entityEnter(e: ecs.Entity): void {
e.add(VariableMoveToComponent);
}
entityRemove(e: ecs.Entity): void {
e.remove(VariableMoveToComponent);
}
update(e: ecs.Entity) {
let move = e.get(MoveToComp);
let mtv = e.get(VariableMoveToComponent);
let end: Vec3;
console.assert(move.speed > 0, "移动速度必须要大于零");
if (move.target instanceof Node) {
end = move.ns == Node.NodeSpace.WORLD ? move.target.worldPosition : move.target.position;
}
else {
end = move.target as Vec3;
}
// 目标移动后,重计算移动方向与移动到目标点的速度
if (mtv.end == null || !mtv.end.strictEquals(end)) {
let target = end.clone();
if (move.offsetVector) {
target = target.add(move.offsetVector); // 这里的问题
}
// 移动方向与移动数度
let start = move.ns == Node.NodeSpace.WORLD ? move.node.worldPosition : move.node.position;
move.velocity = Vec3Util.sub(target, start).normalize();
// 移动时间与目标偏位置计算
let distance = Vec3.distance(start, target) - move.offset;
move.onChange?.call(this);
if (distance - move.offset <= 0) {
this.exit(e);
}
else {
mtv.timer.step = distance / move.speed;
mtv.end = end.clone();
mtv.target = move.velocity.clone().multiplyScalar(distance).add(start);
}
}
if (move.speed > 0) {
let trans = Vec3Util.mul(move.velocity, move.speed * this.dt);
move.node.translate(trans, Node.NodeSpace.LOCAL);
}
// 移动完成事件
if (mtv.timer.update(this.dt)) {
if (move.ns == Node.NodeSpace.WORLD)
move.node.worldPosition = mtv.target;
else
move.node.position = mtv.target;
this.exit(e);
}
}
private exit(e: ecs.Entity) {
let move = e.get(MoveToComp);
move.onComplete?.call(this);
e.remove(VariableMoveToComponent);
e.remove(MoveToComp);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "eb55eb50-dace-4e75-8965-3475c0b11835",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -32,7 +32,8 @@ export class MapViewComp extends CCComp {
this.addHero(args.uuid)
}
reset(): void {
//撤销监听
// oops.message.off("do_add_hero", this.on_do_add_hero, this);
}
start() {
@@ -45,6 +46,7 @@ export class MapViewComp extends CCComp {
let pos = v3(BoxSet.HERO_START-50,BoxSet.GAME_LINE)
role.load(pos,108,"Character07")
smc.Role=role
}
load_data(){
// let heros = oops.res.get("config/game/heros")