feat(editor): multi-script entities + asset browser panel

ScriptComponent now holds a list of {name, active} items (Unity
semantics: one entity, many scripts, each with its own enable bit;
component-level active stays as the master switch). ScriptRuntime
reconciles instances by name per entity -- rename/remove destroys
only the affected instances, untouched ones keep ticking. Scenes
persist Script.Items; old single-script key still loads.

AssetBrowserPanel (lightweight Unity Project window): fixed roots
(assets/scenes) as tabs, recursive directory tree, file list with
type filter (models/textures/scenes) and name substring filter,
double-click preloads models/HDRs into the asset caches (path-
deduped). Scene files point to the File menu for now; drag & drop
is a later iteration. Docked with Stats by default in fresh layouts.
This commit is contained in:
2026-10-04 00:43:06 +08:00
parent 74a2044441
commit ab7a43a686
9 changed files with 459 additions and 63 deletions
+13 -4
View File
@@ -282,12 +282,21 @@ namespace Engine::ECS {
// 实体原点 = 脚底(胶囊底端),符合角色 pivot 习惯
};
// 脚本组件:只存脚本类名(注册表键,POD 可序列化)。C++ 原生脚本经
// ENGINE_REGISTER_SCRIPT 自注册;将来 Lua/C# 脚本同键解析。
// 脚本组件:多脚本挂载(Unity 语义——一个 GameObject 挂 N 个
// MonoBehaviour,各自有 enabled)。每项 = 脚本类名(注册表键,
// 将来 Lua/C# 同键解析)+ 独立启停位;组件级 active 是总开关。
// 实例生命周期由 ScriptRuntime 对账管理(不进组件,保持可拷贝)
struct ScriptComponent {
bool active = true; // 禁用 = 实例保留但停 OnUpdate(Unity disable)
std::string scriptName;
// 单个脚本项
struct Item {
std::string name;
bool active = true; // 禁用 = 实例保留但停 OnUpdate
bool operator==(const Item&) const = default;
};
bool active = true; // 组件总开关(全部停 tick,实例保留)
std::vector<Item> items;
bool operator==(const ScriptComponent&) const = default;
};
@@ -1,8 +1,11 @@
//
// ScriptRuntime.h:脚本生命周期驱动。对账式管理(组件加/删/改名 ↔
// ScriptRuntime.h:脚本生命周期驱动。对账式管理(组件项加/删/改名 ↔
// 实例建/毁),照 PhysicsWorld.SyncScene 模式——每帧对账,编辑器操作
// 即时生效,场景加载/实体销毁自动消化。
//
// 多脚本:一个实体可挂任意多个脚本项(ScriptComponent::items),实例
// 按名字与 items 对账——重命名/删除走 OnDestroy 清理,未动的实例不重建。
//
#ifndef HELLOVULKAN_SCRIPT_RUNTIME_H
#define HELLOVULKAN_SCRIPT_RUNTIME_H
@@ -12,6 +15,7 @@
#include <Engine/Scripting/Script.h>
#include <unordered_map>
#include <vector>
namespace Engine {
@@ -37,8 +41,9 @@ namespace Engine {
void Sync();
ECS::Scene& m_Scene;
Application* m_App; // 注入脚本上下文
std::unordered_map<u32, ScriptInstance> m_Instances; // entityBits
Application* m_App; // 注入脚本上下文
// entityBits → 实例列表(成员按名字与 items 对齐,无序)
std::unordered_map<u32, std::vector<ScriptInstance>> m_Instances;
};
} // namespace Scripting