* feat(fairygui): FairyGUI ECS 集成核心架构 实现 FairyGUI 的 ECS 原生集成,完全替代旧 UI 系统: 核心类: - GObject: UI 对象基类,支持变换、可见性、关联、齿轮 - GComponent: 容器组件,管理子对象和控制器 - GRoot: 根容器,管理焦点、弹窗、输入分发 - GGroup: 组容器,支持水平/垂直布局 抽象层: - DisplayObject: 显示对象基类 - EventDispatcher: 事件分发 - Timer: 计时器 - Stage: 舞台,管理输入和缩放 布局系统: - Relations: 约束关联管理 - RelationItem: 24 种关联类型 基础设施: - Controller: 状态控制器 - Transition: 过渡动画 - ScrollPane: 滚动面板 - UIPackage: 包管理 - ByteBuffer: 二进制解析 * refactor(ui): 删除旧 UI 系统,使用 FairyGUI 替代 * feat(fairygui): 实现 UI 控件 - 添加显示类:Image、TextField、Graph - 添加基础控件:GImage、GTextField、GGraph - 添加交互控件:GButton、GProgressBar、GSlider - 更新 IRenderCollector 支持 Graph 渲染 - 扩展 Controller 添加 selectedPageId - 添加 STATE_CHANGED 事件类型 * feat(fairygui): 现代化架构重构 - 增强 EventDispatcher 支持类型安全、优先级和传播控制 - 添加 PropertyBinding 响应式属性绑定系统 - 添加 ServiceContainer 依赖注入容器 - 添加 UIConfig 全局配置系统 - 添加 UIObjectFactory 对象工厂 - 实现 RenderBridge 渲染桥接层 - 实现 Canvas2DBackend 作为默认渲染后端 - 扩展 IRenderCollector 支持更多图元类型 * feat(fairygui): 九宫格渲染和资源加载修复 - 修复 FGUIUpdateSystem 支持路径和 GUID 两种加载方式 - 修复 GTextInput 同时设置 _displayObject 和 _textField - 实现九宫格渲染展开为 9 个子图元 - 添加 sourceWidth/sourceHeight 用于九宫格计算 - 添加 DOMTextRenderer 文本渲染层(临时方案) * fix(fairygui): 修复 GGraph 颜色读取 * feat(fairygui): 虚拟节点 Inspector 和文本渲染支持 * fix(fairygui): 编辑器状态刷新和遗留引用修复 - 修复切换 FGUI 包后组件列表未刷新问题 - 修复切换组件后 viewport 未清理旧内容问题 - 修复虚拟节点在包加载后未刷新问题 - 重构为事件驱动架构,移除轮询机制 - 修复 @esengine/ui 遗留引用,统一使用 @esengine/fairygui * fix: 移除 tsconfig 中的 @esengine/ui 引用
127 lines
4.0 KiB
TypeScript
127 lines
4.0 KiB
TypeScript
/**
|
|
* 检查器面板组件
|
|
* Inspector panel component
|
|
*
|
|
* 使用 InspectorStore 管理状态,减少 useEffect 数量
|
|
* Uses InspectorStore for state management to reduce useEffect count
|
|
*/
|
|
|
|
import { useEffect, useRef } from 'react';
|
|
import { useInspectorStore } from '../../stores';
|
|
import { InspectorProps } from './types';
|
|
import { getProfilerService } from './utils';
|
|
import {
|
|
EmptyInspector,
|
|
ExtensionInspector,
|
|
AssetFileInspector,
|
|
RemoteEntityInspector,
|
|
PrefabInspector,
|
|
VirtualNodeInspector
|
|
} from './views';
|
|
import { EntityInspectorPanel } from '../inspector';
|
|
|
|
export function Inspector({ entityStore: _entityStore, messageHub, inspectorRegistry, projectPath, commandManager }: InspectorProps) {
|
|
// ===== 从 InspectorStore 获取状态 | Get state from InspectorStore =====
|
|
const {
|
|
target,
|
|
componentVersion,
|
|
autoRefresh,
|
|
setAutoRefresh,
|
|
isLocked,
|
|
setIsLocked,
|
|
decimalPlaces,
|
|
} = useInspectorStore();
|
|
|
|
// Ref 用于 profiler 回调访问最新状态 | Ref for profiler callback to access latest state
|
|
const targetRef = useRef(target);
|
|
targetRef.current = target;
|
|
|
|
// 自动刷新远程实体详情 | Auto-refresh remote entity details
|
|
useEffect(() => {
|
|
if (!autoRefresh || target?.type !== 'remote-entity') {
|
|
return;
|
|
}
|
|
|
|
const profilerService = getProfilerService();
|
|
if (!profilerService) {
|
|
return;
|
|
}
|
|
|
|
const handleProfilerData = () => {
|
|
const currentTarget = targetRef.current;
|
|
if (currentTarget?.type === 'remote-entity' && currentTarget.data?.id !== undefined) {
|
|
profilerService.requestEntityDetails(currentTarget.data.id);
|
|
}
|
|
};
|
|
|
|
const unsubscribe = profilerService.subscribe(handleProfilerData);
|
|
|
|
return () => {
|
|
unsubscribe();
|
|
};
|
|
}, [autoRefresh, target?.type]);
|
|
|
|
// ===== 渲染 | Render =====
|
|
if (!target) {
|
|
return <EmptyInspector />;
|
|
}
|
|
|
|
if (target.type === 'extension') {
|
|
return <ExtensionInspector data={target.data} inspectorRegistry={inspectorRegistry} projectPath={projectPath} />;
|
|
}
|
|
|
|
if (target.type === 'asset-file') {
|
|
// 预制体文件使用专用检查器 | Prefab files use dedicated inspector
|
|
if (target.data.extension?.toLowerCase() === 'prefab') {
|
|
return <PrefabInspector fileInfo={target.data} messageHub={messageHub} commandManager={commandManager} />;
|
|
}
|
|
|
|
// 检查插件是否提供自定义检查器 | Check if a plugin provides a custom inspector
|
|
const customInspector = inspectorRegistry.render(target, { target, projectPath });
|
|
if (customInspector) {
|
|
return customInspector;
|
|
}
|
|
// 回退到默认资产文件检查器 | Fall back to default asset file inspector
|
|
return <AssetFileInspector fileInfo={target.data} content={target.content} isImage={target.isImage} />;
|
|
}
|
|
|
|
if (target.type === 'remote-entity') {
|
|
const entity = target.data;
|
|
const details = target.details;
|
|
|
|
return (
|
|
<RemoteEntityInspector
|
|
entity={entity}
|
|
details={details}
|
|
autoRefresh={autoRefresh}
|
|
onAutoRefreshChange={setAutoRefresh}
|
|
decimalPlaces={decimalPlaces}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (target.type === 'entity') {
|
|
return (
|
|
<EntityInspectorPanel
|
|
entity={target.data}
|
|
messageHub={messageHub}
|
|
commandManager={commandManager}
|
|
componentVersion={componentVersion}
|
|
isLocked={isLocked}
|
|
onLockChange={setIsLocked}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (target.type === 'virtual-node') {
|
|
return (
|
|
<VirtualNodeInspector
|
|
parentEntityId={target.data.parentEntityId}
|
|
virtualNode={target.data.virtualNode}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return null;
|
|
}
|