diff --git a/extensions/cocos/cocos-ecs/extensions/cocos-ecs-extension/source/panels/behavior-tree/composables/useBehaviorTreeEditor.ts b/extensions/cocos/cocos-ecs/extensions/cocos-ecs-extension/source/panels/behavior-tree/composables/useBehaviorTreeEditor.ts index 2180b741..1375011f 100644 --- a/extensions/cocos/cocos-ecs/extensions/cocos-ecs-extension/source/panels/behavior-tree/composables/useBehaviorTreeEditor.ts +++ b/extensions/cocos/cocos-ecs/extensions/cocos-ecs-extension/source/panels/behavior-tree/composables/useBehaviorTreeEditor.ts @@ -559,26 +559,19 @@ export function useBehaviorTreeEditor() { // 全局拖拽结束处理 const handleGlobalDragEnd = (event: DragEvent) => { - console.log('🔚 全局拖拽结束,是否正在拖拽条件:', conditionAttachment.dragState.isDraggingCondition); if (conditionAttachment.dragState.isDraggingCondition) { setTimeout(() => { - console.log('⏰ 延迟重置拖拽状态'); conditionAttachment.resetDragState(); - }, 100); // 延迟重置,确保drop事件先执行 + }, 100); } }; - // 全局拖拽监听器用于调试 const handleGlobalDragOver = (event: DragEvent) => { - if (conditionAttachment.dragState.isDraggingCondition) { - console.log('🌐 全局dragover,鼠标位置:', event.clientX, event.clientY, '目标:', event.target); - } + // 静默处理拖拽悬停 }; const handleGlobalDrop = (event: DragEvent) => { - if (conditionAttachment.dragState.isDraggingCondition) { - console.log('🌐 全局drop事件,目标:', event.target, '位置:', event.clientX, event.clientY); - } + // 静默处理拖拽放置 }; document.addEventListener('load-behavior-tree-file', handleLoadBehaviorTreeFile as EventListener); @@ -631,30 +624,21 @@ export function useBehaviorTreeEditor() { clearAllConnections, copyToClipboard, saveToFile, - // 节点选择相关 selectNode: (nodeId: string) => { - // 选中普通节点时,取消条件节点的选中 appState.selectedNodeId.value = nodeId; appState.selectedConditionNodeId.value = null; - console.log('🎯 选中节点:', nodeId); }, selectConditionNode: (decoratorNode: any) => { - // 选中条件节点时,取消装饰器节点的选中 appState.selectedNodeId.value = null; appState.selectedConditionNodeId.value = decoratorNode.id; - console.log('📝 选中条件节点进行编辑:', decoratorNode.attachedCondition?.name); }, - // 统一的属性更新方法(支持普通节点和条件节点) updateNodeProperty: (path: string, value: any) => { - // 如果选中的是条件节点,更新装饰器节点的属性 if (appState.selectedConditionNodeId.value) { const decoratorNode = appState.getNodeByIdLocal(appState.selectedConditionNodeId.value); if (decoratorNode) { - // 使用通用方法更新属性 const keys = path.split('.'); let current: any = decoratorNode; - // 导航到目标属性的父对象 for (let i = 0; i < keys.length - 1; i++) { const key = keys[i]; if (!(key in current) || typeof current[key] !== 'object' || current[key] === null) { @@ -663,18 +647,13 @@ export function useBehaviorTreeEditor() { current = current[key]; } - // 设置最终值 const finalKey = keys[keys.length - 1]; current[finalKey] = value; - - console.log('📝 更新条件属性:', path, '=', value); } } else { - // 普通节点属性更新 nodeOps.updateNodeProperty(path, value); } }, - // 条件吸附功能 conditionDragState: conditionAttachment.dragState, startConditionDrag: conditionAttachment.startConditionDrag, handleDecoratorDragOver: conditionAttachment.handleDecoratorDragOver, @@ -684,48 +663,43 @@ export function useBehaviorTreeEditor() { removeConditionFromDecorator: conditionAttachment.removeConditionFromDecorator, canAcceptCondition: conditionAttachment.canAcceptCondition, resetDragState: conditionAttachment.resetDragState, - // 合并的画布拖拽处理 + handleCanvasDrop: (event: DragEvent) => { - // 先尝试条件拖拽处理 if (conditionAttachment.handleCanvasDrop(event)) { - return; // 如果是条件拖拽,直接返回 + return; } - // 否则使用正常的节点拖拽处理 nodeOps.onCanvasDrop(event); }, - // 条件节点拖拽处理 + handleConditionNodeDragStart: (event: DragEvent, template: any) => { - console.log('🎯 条件节点拖拽事件:', template.name, template.isDraggableCondition); if (template.isDraggableCondition) { conditionAttachment.startConditionDrag(event, template); } else { nodeOps.onNodeDragStart(event, template); } }, - // 节点拖拽事件处理 + handleNodeDrop: (event: DragEvent, node: any) => { - console.log('📦 节点拖拽放置:', node.name, node.type, 'isDraggingCondition:', conditionAttachment.dragState.isDraggingCondition); if (node.type === 'conditional-decorator') { event.preventDefault(); event.stopPropagation(); return conditionAttachment.attachConditionToDecorator(event, node); } }, + handleNodeDragOver: (event: DragEvent, node: any) => { - console.log('🔄 节点拖拽悬停:', node.name, node.type, 'isDraggingCondition:', conditionAttachment.dragState.isDraggingCondition); if (node.type === 'conditional-decorator') { event.preventDefault(); event.stopPropagation(); return conditionAttachment.handleDecoratorDragOver(event, node); } }, + handleNodeDragLeave: (event: DragEvent, node: any) => { - console.log('🔙 节点拖拽离开:', node.name, node.type); if (node.type === 'conditional-decorator') { conditionAttachment.handleDecoratorDragLeave(node); } }, - // Blackboard拖拽相关功能 isBlackboardDroppable, isBlackboardReference, handleBlackboardDrop, @@ -733,7 +707,6 @@ export function useBehaviorTreeEditor() { handleBlackboardDragLeave, clearBlackboardReference, - // Blackboard常驻侧边面板功能 blackboardCollapsed: computed({ get: () => blackboardSidebarState.collapsed, set: (value: boolean) => blackboardSidebarState.collapsed = value diff --git a/extensions/cocos/cocos-ecs/extensions/cocos-ecs-extension/source/panels/behavior-tree/composables/useBlackboard.ts b/extensions/cocos/cocos-ecs/extensions/cocos-ecs-extension/source/panels/behavior-tree/composables/useBlackboard.ts index 562f83c4..01d8a744 100644 --- a/extensions/cocos/cocos-ecs/extensions/cocos-ecs-extension/source/panels/behavior-tree/composables/useBlackboard.ts +++ b/extensions/cocos/cocos-ecs/extensions/cocos-ecs-extension/source/panels/behavior-tree/composables/useBlackboard.ts @@ -51,30 +51,6 @@ export function useBlackboard() { allowedValuesText: '' }); - const showAddVariableDialog = ref(false); - const editingVariable = ref(null); - const newVariable = reactive({ - name: '', - type: 'string' as any, - defaultValue: '' as any, - defaultValueText: '', - description: '', - group: '', - readonly: false, - min: undefined as number | undefined, - max: undefined as number | undefined, - optionsText: '' - }); - - const showImportExportDialog = ref(false); - const activeTab = ref('export'); - const exportData = computed(() => { - const data = Array.from(blackboardVariables.value.values()); - return JSON.stringify(data, null, 2); - }); - const importData = ref(''); - const clearBeforeImport = ref(false); - const blackboardCollapsed = ref(false); const blackboardTransparent = ref(true); @@ -108,18 +84,6 @@ export function useBlackboard() { return sortedGroups; }); - const groups = computed(() => { - const groupSet = new Set(); - blackboardVariables.value.forEach(variable => { - groupSet.add(variable.group || '未分组'); - }); - return Array.from(groupSet); - }); - - const isValidVariable = computed(() => { - return newVariable.name.trim().length > 0; - }); - const groupedBlackboardVariables = () => { return Object.entries(blackboardVariableGroups.value); }; @@ -240,31 +204,6 @@ export function useBlackboard() { } }; - const onTypeChange = () => { - switch (newVariable.type) { - case 'string': - newVariable.defaultValue = ''; - break; - case 'number': - newVariable.defaultValue = 0; - break; - case 'boolean': - newVariable.defaultValue = false; - break; - case 'vector2': - newVariable.defaultValue = { x: 0, y: 0 }; - break; - case 'vector3': - newVariable.defaultValue = { x: 0, y: 0, z: 0 }; - break; - case 'object': - case 'array': - newVariable.defaultValue = ''; - newVariable.defaultValueText = ''; - break; - } - }; - const saveBlackboardVariable = () => { if (!blackboardModalData.name.trim()) { alert('请输入变量名称'); @@ -273,7 +212,6 @@ export function useBlackboard() { let finalValue = blackboardModalData.defaultValue; - // 处理对象和数组类型的JSON格式 if (blackboardModalData.type === 'object' || blackboardModalData.type === 'array') { try { if (typeof blackboardModalData.defaultValue === 'string') { @@ -290,7 +228,6 @@ export function useBlackboard() { if (blackboardModalData.constraints.max !== undefined) constraints.max = blackboardModalData.constraints.max; if (blackboardModalData.constraints.step !== undefined) constraints.step = blackboardModalData.constraints.step; - // 处理字符串的可选值列表 if (blackboardModalData.useAllowedValues && blackboardModalData.allowedValuesText.trim()) { constraints.allowedValues = blackboardModalData.allowedValuesText .split('\n') @@ -317,7 +254,6 @@ export function useBlackboard() { showBlackboardModal.value = false; editingBlackboardVariable.value = null; - // 重置模态框数据 Object.assign(blackboardModalData, { name: '', type: 'string', @@ -421,10 +357,6 @@ export function useBlackboard() { event.dataTransfer.effectAllowed = 'copy'; }; - const removeBlackboardVariable = (variableName: string) => { - deleteBlackboardVariable(variableName); - }; - const editVariable = (variable: BlackboardVariable) => { editingBlackboardVariable.value = variable; @@ -447,71 +379,20 @@ export function useBlackboard() { showBlackboardModal.value = true; }; - const onBlackboardDragStart = (event: DragEvent, variable: BlackboardVariable) => { - onVariableDragStart(event, variable); - }; - - const closeAddVariableDialog = () => { - showAddVariableDialog.value = false; - editingVariable.value = null; - }; - - const saveVariable = () => { - saveBlackboardVariable(); - }; - - const closeImportExportDialog = () => { - showImportExportDialog.value = false; - }; - - const copyExportData = () => { - navigator.clipboard.writeText(exportData.value); - alert('已复制到剪贴板'); - }; - - const importVariables = () => { - try { - const data = JSON.parse(importData.value); - if (!Array.isArray(data)) { - throw new Error('格式错误:期望数组格式'); - } - - if (clearBeforeImport.value) { - blackboardVariables.value.clear(); - } - - let importCount = 0; - data.forEach((varData: any) => { - if (varData.name && varData.type) { - blackboardVariables.value.set(varData.name, varData); - importCount++; - } - }); - - alert(`成功导入 ${importCount} 个变量`); - showImportExportDialog.value = false; - importData.value = ''; - } catch (error) { - alert('导入失败:' + (error as Error).message); - } - }; - const addBlackboardVariable = () => { - Object.assign(newVariable, { + editingBlackboardVariable.value = null; + Object.assign(blackboardModalData, { name: '', type: 'string', defaultValue: '', - defaultValueText: '', description: '', group: '', - readonly: false, - min: undefined, - max: undefined, - optionsText: '' + readOnly: false, + constraints: {}, + useAllowedValues: false, + allowedValuesText: '' }); - - editingVariable.value = null; - showAddVariableDialog.value = true; + showBlackboardModal.value = true; }; return { @@ -522,17 +403,6 @@ export function useBlackboard() { blackboardModalData, expandedGroups, blackboardVariableGroups, - - showAddVariableDialog, - editingVariable, - newVariable, - groups, - showImportExportDialog, - activeTab, - exportData, - importData, - clearBeforeImport, - isValidVariable, blackboardCollapsed, blackboardTransparent, @@ -549,24 +419,15 @@ export function useBlackboard() { addBlackboardVariable, saveBlackboardVariable, deleteBlackboardVariable, - removeBlackboardVariable, + removeBlackboardVariable: deleteBlackboardVariable, updateBlackboardVariable, editVariable, selectVariable, clearBlackboard, - - closeAddVariableDialog, - saveVariable, - onTypeChange, - closeImportExportDialog, - copyExportData, - importVariables, - exportBlackboard, importBlackboard, - onBlackboardDragStart, - + onBlackboardDragStart: onVariableDragStart, editBlackboardVariable: editVariable, onBlackboardValueChange: (variable: BlackboardVariable) => { updateBlackboardVariable(variable.name, variable.value); diff --git a/extensions/cocos/cocos-ecs/extensions/cocos-ecs-extension/static/template/behavior-tree/BehaviorTreeEditor.html b/extensions/cocos/cocos-ecs/extensions/cocos-ecs-extension/static/template/behavior-tree/BehaviorTreeEditor.html index ba5b92c7..ec4383cf 100644 --- a/extensions/cocos/cocos-ecs/extensions/cocos-ecs-extension/static/template/behavior-tree/BehaviorTreeEditor.html +++ b/extensions/cocos/cocos-ecs/extensions/cocos-ecs-extension/static/template/behavior-tree/BehaviorTreeEditor.html @@ -21,7 +21,6 @@ -
@@ -348,7 +347,8 @@
- + +
- +
- +
{{ node.children.length }}
- +
- +
- +

⚙️ 属性面板

@@ -488,7 +488,6 @@ -
🔗 {{ prop.value }} @@ -513,7 +512,6 @@
-

🌲 树结构

@@ -528,13 +526,13 @@
- +
⚠️ {{ validationResult().message }}
- +