更新性能分析器及更改部分注释
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { Component } from '@esengine/ecs-framework';
|
||||
|
||||
/**
|
||||
* 生命值组件
|
||||
* 管理实体的生命值、最大生命值等
|
||||
*/
|
||||
export class Health extends Component {
|
||||
/** 当前生命值 */
|
||||
public currentHealth: number = 100;
|
||||
|
||||
/** 最大生命值 */
|
||||
public maxHealth: number = 100;
|
||||
|
||||
/** 是否死亡 */
|
||||
public isDead: boolean = false;
|
||||
|
||||
/** 生命值回复速度 (每秒) */
|
||||
public regenRate: number = 0;
|
||||
|
||||
constructor(maxHealth: number = 100) {
|
||||
super();
|
||||
this.maxHealth = maxHealth;
|
||||
this.currentHealth = maxHealth;
|
||||
}
|
||||
|
||||
/**
|
||||
* 受到伤害
|
||||
*/
|
||||
public takeDamage(damage: number): void {
|
||||
this.currentHealth = Math.max(0, this.currentHealth - damage);
|
||||
this.isDead = this.currentHealth <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 治疗
|
||||
*/
|
||||
public heal(amount: number): void {
|
||||
if (!this.isDead) {
|
||||
this.currentHealth = Math.min(this.maxHealth, this.currentHealth + amount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 复活
|
||||
*/
|
||||
public revive(healthPercent: number = 1.0): void {
|
||||
this.isDead = false;
|
||||
this.currentHealth = Math.floor(this.maxHealth * Math.max(0, Math.min(1, healthPercent)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取生命值百分比
|
||||
*/
|
||||
public getHealthPercent(): number {
|
||||
return this.maxHealth > 0 ? this.currentHealth / this.maxHealth : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置组件
|
||||
*/
|
||||
public reset(): void {
|
||||
this.currentHealth = this.maxHealth;
|
||||
this.isDead = false;
|
||||
this.regenRate = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "90369635-a6cb-4313-adf1-64117b50f2bc",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import { Component } from '@esengine/ecs-framework';
|
||||
import { Color } from 'cc';
|
||||
|
||||
/**
|
||||
* 渲染组件
|
||||
* 存储实体的渲染相关信息
|
||||
*/
|
||||
export class Renderer extends Component {
|
||||
/** 颜色 */
|
||||
public color: Color = new Color(255, 255, 255, 255);
|
||||
|
||||
/** 是否可见 */
|
||||
public visible: boolean = true;
|
||||
|
||||
/** 渲染层级 */
|
||||
public layer: number = 0;
|
||||
|
||||
/** 精灵名称或纹理路径 */
|
||||
public spriteName: string = '';
|
||||
|
||||
/** 大小 */
|
||||
public size: { width: number, height: number } = { width: 32, height: 32 };
|
||||
|
||||
/** 透明度 (0-1) */
|
||||
public alpha: number = 1.0;
|
||||
|
||||
constructor(spriteName: string = '', color?: Color) {
|
||||
super();
|
||||
this.spriteName = spriteName;
|
||||
if (color) {
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置颜色
|
||||
*/
|
||||
public setColor(r: number, g: number, b: number, a: number = 255): void {
|
||||
this.color.set(r, g, b, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置透明度
|
||||
*/
|
||||
public setAlpha(alpha: number): void {
|
||||
this.alpha = Math.max(0, Math.min(1, alpha));
|
||||
this.color.a = Math.floor(this.alpha * 255);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置大小
|
||||
*/
|
||||
public setSize(width: number, height: number): void {
|
||||
this.size.width = width;
|
||||
this.size.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示/隐藏
|
||||
*/
|
||||
public setVisible(visible: boolean): void {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置组件
|
||||
*/
|
||||
public reset(): void {
|
||||
this.color.set(255, 255, 255, 255);
|
||||
this.visible = true;
|
||||
this.layer = 0;
|
||||
this.spriteName = '';
|
||||
this.size = { width: 32, height: 32 };
|
||||
this.alpha = 1.0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "bf51f134-6ea5-4a26-8b15-0ed20fe1d605",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { Component } from '@esengine/ecs-framework';
|
||||
import { Vec3 } from 'cc';
|
||||
|
||||
/**
|
||||
* 变换组件
|
||||
* 存储实体的位置、旋转和缩放信息
|
||||
*/
|
||||
export class Transform extends Component {
|
||||
/** 位置 */
|
||||
public position: Vec3 = new Vec3(0, 0, 0);
|
||||
|
||||
/** 旋转 (度数) */
|
||||
public rotation: Vec3 = new Vec3(0, 0, 0);
|
||||
|
||||
/** 缩放 */
|
||||
public scale: Vec3 = new Vec3(1, 1, 1);
|
||||
|
||||
/** 移动速度 */
|
||||
public speed: number = 100;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置位置
|
||||
*/
|
||||
public setPosition(x: number, y: number, z: number = 0): void {
|
||||
this.position.set(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动
|
||||
*/
|
||||
public move(deltaX: number, deltaY: number, deltaZ: number = 0): void {
|
||||
this.position.x += deltaX;
|
||||
this.position.y += deltaY;
|
||||
this.position.z += deltaZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置组件
|
||||
*/
|
||||
public reset(): void {
|
||||
this.position.set(0, 0, 0);
|
||||
this.rotation.set(0, 0, 0);
|
||||
this.scale.set(1, 1, 1);
|
||||
this.speed = 100;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "09de6e5b-7bb7-4de8-8038-67be5ae955bc",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import { Component } from '@esengine/ecs-framework';
|
||||
import { Vec3 } from 'cc';
|
||||
|
||||
/**
|
||||
* 速度组件
|
||||
* 存储实体的移动速度和方向
|
||||
*/
|
||||
export class Velocity extends Component {
|
||||
/** 速度向量 */
|
||||
public velocity: Vec3 = new Vec3(0, 0, 0);
|
||||
|
||||
/** 最大速度 */
|
||||
public maxSpeed: number = 200;
|
||||
|
||||
/** 摩擦力 (0-1, 1表示无摩擦) */
|
||||
public friction: number = 0.98;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置速度
|
||||
*/
|
||||
public setVelocity(x: number, y: number, z: number = 0): void {
|
||||
this.velocity.set(x, y, z);
|
||||
this.clampToMaxSpeed();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加速度
|
||||
*/
|
||||
public addVelocity(x: number, y: number, z: number = 0): void {
|
||||
this.velocity.x += x;
|
||||
this.velocity.y += y;
|
||||
this.velocity.z += z;
|
||||
this.clampToMaxSpeed();
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用摩擦力
|
||||
*/
|
||||
public applyFriction(): void {
|
||||
this.velocity.multiplyScalar(this.friction);
|
||||
|
||||
// 当速度很小时直接设为0,避免无限减小
|
||||
if (this.velocity.length() < 0.1) {
|
||||
this.velocity.set(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 限制到最大速度
|
||||
*/
|
||||
private clampToMaxSpeed(): void {
|
||||
const currentSpeed = this.velocity.length();
|
||||
if (currentSpeed > this.maxSpeed) {
|
||||
this.velocity.normalize().multiplyScalar(this.maxSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前速度大小
|
||||
*/
|
||||
public getSpeed(): number {
|
||||
return this.velocity.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置组件
|
||||
*/
|
||||
public reset(): void {
|
||||
this.velocity.set(0, 0, 0);
|
||||
this.maxSpeed = 200;
|
||||
this.friction = 0.98;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "10c40371-267a-4016-a8b5-9f803e68e72b",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// 导出所有组件
|
||||
export { Transform } from './Transform';
|
||||
export { Health } from './Health';
|
||||
export { Velocity } from './Velocity';
|
||||
export { Renderer } from './Renderer';
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "dfc46d23-7ad6-4a21-914c-35d948185f93",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user