unity多个场景切换保存数据_unity 保存场景数据,读取场景

这段代码示例展示了如何在Unity中使用XML文件保存和读取多个场景的游戏对象数据。通过遍历所有启用的场景,获取每个场景中的GameObject,记录它们的位置、旋转和缩放信息,并将这些数据存储到XML元素中。最后,保存XML文件并刷新Project视图以查看更新。
摘要由CSDN通过智能技术生成

usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Xml;usingUnityEditor;usingUnityEditor.SceneManagement;usingUnityEngine;//

///保存所有的游戏场景,每个场景的数据都会保存到XML,网上都有,只是方便自己用.///

public classExportSceneInfoToXML : Editor {

[MenuItem("GameObject/ExportXML")]static voidExportXML()

{string filepath = Application.dataPath + @"/StreamingAssets/my.xml";if (!File.Exists(filepath))

{

File.Delete(filepath);

}

XmlDocument xmlDoc= newXmlDocument();

XmlElement root= xmlDoc.CreateElement("gameObjects");//遍历所有的游戏场景

foreach (UnityEditor.EditorBuildSettingsScene S inUnityEditor.EditorBuildSettings.scenes)

{//当场景启用

if(S.enabled)

{//得到场景的名称

string name =S.path;//打开这个场景

EditorApplication.OpenScene(name);

XmlElement scenes= xmlDoc.CreateE

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值