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:
@@ -350,12 +350,20 @@ namespace Engine::Serialization {
|
||||
out << YAML::EndMap;
|
||||
}
|
||||
|
||||
// 脚本只存类名(注册表键);未注册名字加载后运行时警告跳过
|
||||
// 脚本:多脚本列表(每项 = 名字 + 独立启停位);未注册名字
|
||||
// 加载后运行时警告跳过
|
||||
if (const auto* sc = reg.try_get<ECS::ScriptComponent>(e)) {
|
||||
out << YAML::Key << "Script" << YAML::Value << YAML::BeginMap;
|
||||
out << YAML::Key << "ScriptName" << YAML::Value
|
||||
<< sc->scriptName;
|
||||
out << YAML::Key << "Active" << YAML::Value << sc->active;
|
||||
out << YAML::Key << "Items" << YAML::Value << YAML::BeginSeq;
|
||||
for (const auto& item : sc->items) {
|
||||
// flow map 单行一项,与场景格式定案一致
|
||||
out << YAML::BeginMap;
|
||||
out << YAML::Key << "Name" << YAML::Value << item.name;
|
||||
out << YAML::Key << "Active" << YAML::Value << item.active;
|
||||
out << YAML::EndMap;
|
||||
}
|
||||
out << YAML::EndSeq;
|
||||
out << YAML::EndMap;
|
||||
}
|
||||
|
||||
@@ -655,11 +663,25 @@ namespace Engine::Serialization {
|
||||
// 状态(速度/着地)由 PhysicsWorld 对账重建,不存
|
||||
}
|
||||
|
||||
// 脚本:只存类名;未注册名字由 ScriptRuntime 运行时警告跳过
|
||||
// 脚本:优先读多脚本 Items;无 Items 回退旧单脚本键(向前兼容)
|
||||
if (const YAML::Node n = comps["Script"]) {
|
||||
auto& sc = handle.AddComponent<ECS::ScriptComponent>();
|
||||
sc.scriptName = n["ScriptName"].as<std::string>("");
|
||||
sc.active = n["Active"].as<bool>(true);
|
||||
if (const YAML::Node items = n["Items"]) {
|
||||
for (const auto& it : items) {
|
||||
ECS::ScriptComponent::Item item;
|
||||
item.name = it["Name"].as<std::string>("");
|
||||
item.active = it["Active"].as<bool>(true);
|
||||
sc.items.push_back(std::move(item));
|
||||
}
|
||||
} else {
|
||||
// 旧格式:Script: {ScriptName: ..., Active: ...}
|
||||
ECS::ScriptComponent::Item item;
|
||||
item.name = n["ScriptName"].as<std::string>("");
|
||||
if (!item.name.empty()) {
|
||||
sc.items.push_back(std::move(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user