组件属性编辑器

This commit is contained in:
YHH
2025-10-15 00:15:12 +08:00
parent 3224bb9696
commit 4550a6146a
7 changed files with 452 additions and 22 deletions

View File

@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react';
import { Core, Scene } from '@esengine/ecs-framework';
import { EditorPluginManager, UIRegistry, MessageHub, SerializerRegistry, EntityStoreService, ComponentRegistry, LocaleService } from '@esengine/editor-core';
import { EditorPluginManager, UIRegistry, MessageHub, SerializerRegistry, EntityStoreService, ComponentRegistry, LocaleService, PropertyMetadataService } from '@esengine/editor-core';
import { SceneInspectorPlugin } from './plugins/SceneInspectorPlugin';
import { SceneHierarchy } from './components/SceneHierarchy';
import { EntityInspector } from './components/EntityInspector';
@@ -13,13 +13,43 @@ import { en, zh } from './locales';
import './styles/App.css';
// 在 App 组件外部初始化 Core 和基础服务
Core.create({ debug: true });
const coreInstance = Core.create({ debug: true });
const localeService = new LocaleService();
localeService.registerTranslations('en', en);
localeService.registerTranslations('zh', zh);
Core.services.registerInstance(LocaleService, localeService);
const propertyMetadata = new PropertyMetadataService();
Core.services.registerInstance(PropertyMetadataService, propertyMetadata);
propertyMetadata.register(TransformComponent, {
properties: {
x: { type: 'number', label: 'X Position' },
y: { type: 'number', label: 'Y Position' },
rotation: { type: 'number', label: 'Rotation', min: 0, max: 360 },
scaleX: { type: 'number', label: 'Scale X', min: 0, step: 0.1 },
scaleY: { type: 'number', label: 'Scale Y', min: 0, step: 0.1 }
}
});
propertyMetadata.register(SpriteComponent, {
properties: {
texturePath: { type: 'string', label: 'Texture Path' },
color: { type: 'color', label: 'Tint Color' },
visible: { type: 'boolean', label: 'Visible' }
}
});
propertyMetadata.register(RigidBodyComponent, {
properties: {
mass: { type: 'number', label: 'Mass', min: 0, step: 0.1 },
friction: { type: 'number', label: 'Friction', min: 0, max: 1, step: 0.01 },
restitution: { type: 'number', label: 'Restitution', min: 0, max: 1, step: 0.01 },
isDynamic: { type: 'boolean', label: 'Dynamic' }
}
});
function App() {
const [initialized, setInitialized] = useState(false);
const [pluginManager, setPluginManager] = useState<EditorPluginManager | null>(null);
@@ -68,7 +98,7 @@ function App() {
Core.services.registerInstance(ComponentRegistry, componentRegistry);
const pluginMgr = new EditorPluginManager();
pluginMgr.initialize(Core, Core.services);
pluginMgr.initialize(coreInstance, Core.services);
await pluginMgr.installEditor(new SceneInspectorPlugin());