【问题标题】:Unity c# xmlDocument and Resources.Load/Unloadunity c# xmlDocument 和 Resources.Load/Unload
【发布时间】:2019-08-08 19:56:05
【问题描述】:

我与XmlDocument 合作。

TextAsset _textAsset = (TextAsset)Resources.Load(PathOfFile);
_xmlDoc = new XmlDocument();
_xmlDoc.LoadXml(_textAsset.text);

之后,我在_xmlDoc中进行了一些更改并保存到:

_xmlDoc.Save(PathOfFile);

但只有当我从资源管理器重新打开 XML 文件或隐藏显示 Unity 时,这些更改才会生效。

所以我认为问题是:文件在Resources.Load 之后仍然打开。

如何关闭它? (Resources.UnloadAsset(); 不起作用)

【问题讨论】:

    标签: c# xml unity3d resources save


    【解决方案1】:

    要立即查看任何编辑器脚本对Assets 所做的更改,您应该在编码方法的末尾调用AssetDatabase.Refresh();


    Afaik Resources 文件夹的内容是 ReadOnly 在构建中,所以你不能使用

    _xmlDoc.Save(PathOfFile);
    

    仅在编辑器中的构建中。您也许应该使用StreamingAssets 来访问它,使用Application.streamingAssetsPathApplication.persistentDataPath

    【讨论】:

    • 是的,我刚刚意识到它只适用于编辑器。构建后如何使用相同的东西?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-12
    • 2023-02-04
    • 1970-01-01
    相关资源
    最近更新 更多