我一直在寻找一段时间如何编写在服务器上注册的每个玩家的详细信息列表,这样当人们登录时,他们的详细信息将从xml文件中加载,并从他们注销的地方恢复.
我知道那里有很多教程,但我似乎无法做任何工作.我需要随机访问,并实时在硬盘上更新文件.当前代码(远离工作)显示了后面的格式,但我不理解xml的大多数概念,例如什么是属性/节点/元素?教程似乎想假设你知道..
XMLFile = XDocument.Load(@"C:/users.xml");
var users = XMLFile.Descendants( "Users" );
int count = 0;
foreach ( var user in users )
{
count++;
userName[count] = user.ToString();
XElement element = (XMLFile.FirstNode as XElement);
userPass[count] = element.Value;
XAttribute attribute = (XMLFile.NextNode as XAttribute);
userLocation[count] = attribute.Value;
attribute = (XAttribute)XMLFile.NextNode;
userRotation[count] = attribute.Value;
}
Run Code Online (Sandbox Code Playgroud)
这个想法是文件将被格式化为这样(作为xml ..)
Users
Aaron
password
vector3 of location
Quaternion of Rotation
SomeoneElse
hispassword
Vector3 of location
Quaternion of rotation
//and so on....
Run Code Online (Sandbox Code Playgroud)
这些值将在客户端登录并通过网络发送其他所有工作时读取.我只是无法获得任何读取/写入xml的方法,所以感谢您的帮助.