【发布时间】:2021-07-09 20:08:37
【问题描述】:
我必须从 XML 加载数据(自定义,但它基于 XML 文件格式 (URF-8))并使用它们在 Unity 中创建模型。我使用了 XmlSerializer 类、自定义创建并尝试了论坛中的所有 XML 帮助等。 我调试了一切(一步一步),一切正常,但在那之后我总是遇到容器问题。 (我有阅读错误) 请,如果您对此有任何经验,您能告诉我什么方法对此有用吗?太棒了
这是我对 XMLserializer 的尝试:(对 XML 标记的一些描述进行了注释(尝试了一切:D)
//load.cs - creating a container
using System;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;
using UnityEngine;
public class Load
{
//[XmlAttribute("block type")]
public float x_position;
public float y_position;
public float z_position;
}
//[XmlRoot("model version")]
public class Container
{
//[XmlArrayItem("block type")]
public List<Load> Load_container = new List<Load>();
}
//loadFile is main program.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
public class LoadFile: MonoBehaviour
{
public string path;
// Start is called before the first frame update
void Start()
{
var serializer = new XmlSerializer(typeof(Container));
var stream = new FileStream(path, FileMode.Open);
var container_load = serializer.Deserialize(stream) as Container;
stream.Close();
//Debug.Log();
}
// Update is called once per frame
void Update()
{
}
}
【问题讨论】: