Last active: 2 years ago
Sericalize tree data struct to a array.
/**
* 将场景列表打平为单维数组
* @param scene 主场景
*/
export const serializeScene = <T extends SceneInfo | State<SceneInfo>>(
scene: T
) => {
let sceneList: T[] = [];
scene.children.forEach((s) => {
sceneList.push(s as T);
if (s.children.length)
sceneList = [...sceneList, ...serializeScene(s)] as T[];
});
return sceneList;
};