一共两个脚本
一个保存的,一个读取的,下面会附上代码,网上都有,这个只是方便自己用,
这是保存的脚本,放到Editor文件夹下即可
using System.Collections; using System.Collections.Generic; using System.IO; using System.Xml; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; // <summary> /// 保存所有的游戏场景,每个场景的数据都会保存到XML,网上都有,只是方便自己用. /// </summary> public class ExportSceneInfoToXML : Editor { [MenuItem("GameObject/ExportXML")] static void ExportXML() { string filepath = Application.dataPath + @"/StreamingAssets/my.xml"; if (!File.Exists(filepath)) { File.Delete(filepath); } XmlDocument xmlDoc = new XmlDocument(); XmlElement root = xmlDoc.CreateElement("gameObjects"); //遍历所有的游戏场景 foreach (UnityEditor.EditorBuildSettingsScene S in UnityEditor.EditorBuildSettings.scenes) { //当场景启用 if (S.enabled) { //得到场景的名称 string name = S.path; //打开这个场景 EditorApplication.OpenScene(name); XmlElement scenes = xmlDoc.CreateElement("scenes"); scenes.SetAttribute("name", name); foreach (GameObject obj in Object.FindObjectsOfType(typeof(GameObject))) { if (obj.transform.parent == null) { XmlElement gameObject = xmlDoc.CreateElement("gameObjects"); gameObject.SetAttribute("name", obj.name); gameObject.SetAttribute("asset", obj.name + ".prefab"); XmlElement transform = xmlDoc.CreateElement("transform"<